|
WebLogic Server 7.0 Code Examples, BEA Systems, Inc. | |||||
See:
Description
| Interface Summary | |
| Trader | The methods in this interface are the public face of TraderBean. |
| TraderHome | This interface is the home interface for the TraderBean.java, which in WebLogic is implemented by the code-generated container class TraderBeanC. |
| Class Summary | |
| Client | This class illustrates how to use the JAX-RPC API to invoke the TraderService Web service to perform the following tasks: Buy 100 shares of some stocks Sell 100 shares of some stocks The TraderService Web service is implemented using the Trader stateless session EJB. |
| TraderBean | TraderBean is a stateless Session Bean. |
| TradeResult | This class reflects the results of a buy/sell transaction. |
This example shows how to create a WebLogic Web service based on a stateless
session EJB. The example uses the Trader EJB, one of the EJB 2.0 examples
located in the examples/complex/statelessSession directory.
The Trader EJB defines two methods, buy() and sell(),
that take as input a String stock symbol and an int
number of shares to buy or sell. Both methods return a user-defined data
type called TraderResult.
When this EJB is converted into a Web service, the two methods become public
operations defined in the WSDL of the Web service. The Client.java
application uses JAX-RPC style client APIs to create SOAP messages that invoke
the operations.
The build.xml file compiles, assembles, packages, deploys,
and runs the example. The file calls the servicegen Ant task that
automatically generates the following components:
TraderResult
data between its XML and Java representations
TraderResult Java object
web-services.xml,
that describes how to deploy the Web service on WebLogic Server
servicegen generates all these components, it packages them,
along with the EJB JAR file, into an EAR file that can be deployed on WebLogic
Server.
The build.xml file then calls the clientgen Ant task
that creates another client JAR file used by a client application to invoke the
Web service. This client JAR file is created locally rather than the one that's
created as part of the servicegen Ant task that ends up on WebLogic
Server. Typically users that need the client JAR file either use the
clientgen Ant task or download it from the Web services Home Page.
Client.java is a static client application that directly uses the
Web service interfaces to invoke the buy and sell methods. It uses JAX-RPC style
APIs to invoke the Web service.
| Additional Resources for examples.webservices.ejb.statelessSession | |
| ejb-jar.xml | The J2EE EJB deployment descriptor file that describes the TraderService stateless session EJB. |
| weblogic-ejb-jar.xml | The WebLogic-specific EJB deployment descriptor file for the TraderService stateless session EJB. |
| build.xml | The Java Ant build script that creates an EJB JAR file that contains the TraderService EJB, creates the Web service EAR file using the servicegen Ant task, creates the client JAR file using the clientgen Ant task, compiles the client application, deploys the EAR file, and runs the application. |
The following sections describe how to build and run the example.
Before you run this example, you need:
prompt> ant
The ant utility uses the build.xml build script to perform
the following tasks:
*.java files
servicegen Ant task which automatically generates
serializer and deserializer classes for the TradeResult user-defined
data type, generates a downloadable client JAR file, creates the
web-services.xml file, and packages all these components into a
deployable EAR file.
clientgen Ant task to create a local client JAR file
that contains all the needed classes and interfaces to invoke the Web service
Client.java client application
prompt> ant run
http://localhost:port/webservice/TraderService
where
From the Web Service Home Page you can view the generated WSDL, and test the Web service to make sure it's working correctly.
If the example runs successfully, you should see the following output in
both the window from which you ran the client application and the WebLogic Server
console window:
[java] Buying 100 shares of BEAS.
[java] Result traded 100 shares of BEAS
[java] Buying 200 shares of MSFT.
[java] Result traded 200 shares of MSFT
[java] Buying 300 shares of AMZN.
[java] Result traded 300 shares of AMZN
[java] Buying 400 shares of HWP.
[java] Result traded 400 shares of HWP
[java] Selling 100 shares of BEAS.
[java] Result traded 100 shares of BEAS
[java] Selling 200 shares of MSFT.
[java] Result traded 200 shares of MSFT
[java] Selling 300 shares of AMZN.
[java] Result traded 300 shares of AMZN
[java] Selling 400 shares of HWP.
[java] Result traded 400 shares of HWP
|
Documentation is available at http://e-docs.bea.com/wls/docs70 |
|||||