This example shows how to expose an Enterprise Java Bean per EJB 2.0 as a Web Service. This is a simple "Calculator" service with two operations add() and sub() for performing addition and subtraction respectively. Both operations take an input parameter of type int. Note the usage of the Web Services Assembler wsa.jar to assemble this Web Service based on the EJB 2.0 Enterprise Java Bean.
After completing this demo you should be able to:
Ensure that you have installed the required software and set up your environment. You must have OC4J running. If it is not running on localhost, port 8888, you'll have to modify the ANT script (build.xml) to use the correct host and port to your server.
Once you have the server configured and running, just type ant from the
Step 1 - Assemble the application:
To assemble the webservice application, type: ant gen-service. This will take the ejb at etc/calc.jar and expose it as Web Service, by generating the necessary wsdl and the mapping files and packaging it all in the application. The assembled application is placed in
dist/calc.ear Examine the calc.ear in the /dist. It should contain the input EJB JAR file and an extra WAR file. This WAR file contains all the service artifacts, ejb implementation classes, as well as the wsdl, the mapping file and the Web Service deployment descriptor file webservices.xml.
Step 2 - Deploy
The service is now ready to be deployed. To deploy this ear to a running instance of oc4j, type: ant deploy-demo.
Step 3 - Generate the stubs (client artifacts)
In this step you will generate the stubs for the service. A client application uses a stub to invoke operations on a remote service.
To generate the stubs type: ant gen-stubs. The source for the stubs will be placed into build/client.
Step 4 - Run the Client
You are now ready to run the client for the webservice. Examine the file EJB20Client.java in src/client/oracle/demo/ejb20/ . To run the client type:ant run-demo. You should see the output like.
[java] 18