This example shows how to expose an Enterprise Java Bean following the EJB 2.1 specification as a Web Service. This is a simple "Hello" service that takes a string parameter and returns a string result. Note the usage of the wsa.jar to assemble the EJB 2.1 Web Service .
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 assemble an EJB 2.1 Web Service application by generating the necessary wsdl and the mapping files and packaging it all in the application. The assembled application is placed in
/dist/helloService-ejb.ear Examine the helloService-ejb.ear in the dist directory. It should contain a JAR file named helloService-ejb.jar. This JAR file contains all the service artifacts, the EJB implementation classes, as well as the wsdl, the mapping file, and the webservice deployment descriptor file webservices.xml.
Step 2 - Deploy the Web Service
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 in build/client.
Step 4 - Run the Client
You are now ready to run the client for the webservice.
Examine the file HelloClient.java in src/client/oracle/demo/ejb/. To run the client, type:ant run-demo. You should see output such as the following.
[java] HELLO!! You just said: Hello Ejb web Service!