2. Design and implement EJB (Enterprise Java Beans) session bean business logic to calculate income tax and invoke the service using stub, i.e., client side proxy object.
Categories -> java and select Java Class Library and click on next
Provide name it-remote click on finish
Then screen window appears:
Create new Project:
In categories select Java EE and select Enterprise Application in Projects
Click on next
Unselect the Create web Application Module and click on finish
Then the following project will be created in the work space…
Right click on it-sb-eap2-ejb -> new Session Bean
Provide EJB Name:
Do the following:
EJB Name: ITService
Package: ejb
Session Type:
Select only: Stateless
Create Interface:
Select only: Remote in Project
Click on Finish
Then following screen appears:
Right click on “ITService” class and click Insert Code
Select Add Business Method
Provide:
Name: calculateTax
Return Type: double
Click on Add 3 times
Change the name, type of the parameters and mark all variables as final
Note: you may get error, if it happens click on Save button
Give the implementation for “calculateTax( )” method.
Add new method to get slabRates:
Write your logic to return tax percentage based on given input.
Finally the class “ITService” looks:
We are done with Server side.
Client Project:
Create new Project -> Java EE -> Enterprise Application Client
Click on Next
Click on Next
Click on Finish
Right click -> Insert Code
Select Call To Enterprise Bean
Select the Project
Click on OK
Create inner class in Main:
Create constructor TaxInformation class
Right-click -> insert code ( TaxInformation class)-> Constructor…
Select all the fields
Click on Generate.
Then inner class looks
Invoke the it calculateTax method by using itService (main method)
To display information:
We are done with client.
To Run the application:
Rght-click on “it-sb-eap2” and run
Application is deployed successful, now run the client class
Right-click on “it-sb-client” and run:
Then output on the console looks:
No comments:
Post a Comment