WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

Package examples.webservices.complex.statelessSession

This example shows how to create a WebLogic Web service based on a stateless session EJB.

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.
 

Package examples.webservices.complex.statelessSession Description

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:

After 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.

  1. Prerequisites
  2. Build the Example
  3. Run the Example
  4. Check the Output

 

Prerequisites

Before you run this example, you need:

 

Build the Example

To build the example, follow these steps:
  1. Set up your development shell as described in Quick Start.

  2. Change to the SAMPLES_HOME\server\src\examples\webservices\complex\statelessSession directory, where SAMPLES_HOME refers to the examples WebLogic Server domain directory.

  3. Assemble and compile the example by executing the Java ant utility at the command line:
    prompt> ant

    The ant utility uses the build.xml build script to perform the following tasks:


 

Run the Example

  1. Start the examples WebLogic Server.

  2. In your development shell, run the Client Java application using the following command:
    prompt> ant run 
  3. After building and running the example, you can view the Web Service Home Page using the following URL:

    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.

 

Check the Output

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

 

See Also

Read more about:


Documentation is available at
http://e-docs.bea.com/wls/docs70

Copyright © 2002 BEA Systems, Inc. All Rights Reserved.