WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

Package examples.webservices.basic.statelessSession

This example shows how to create a WebLogic Web service based on a stateless session EJB called HelloWorld that uses only built-in data types as its input parameters and return value.

See:
          Description

Interface Summary
HelloWorld The methods in this interface are the public face of HelloWorld.
HelloWorldHome This interface is the Home interface of the HelloWorld stateless session EJB.
 

Class Summary
Client This class illustrates how to use the JAX-RPC API to statically invoke the HelloWorldEJB WebLogic Web service.
HelloWorldBean HelloWorldBean is a stateless session EJB.
 

Package examples.webservices.basic.statelessSession Description

This example shows how to create a WebLogic Web service based on a stateless session EJB called HelloWorld that uses only built-in data types as its input parameters and return value.

The HelloWorld EJB defines a single method, sayHello(), that takes as input an int and a String parameter and returns a String message built from the two inputted parameters.

When this EJB is converted into a Web service, the sayHello method becomes the public operation defined in the WSDL of the Web service.

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 sayHello operation. It uses JAX-RPC style APIs to invoke the Web service.

Additional Resources for examples.webservices.basic.statelessSession
ejb-jar.xml The J2EE EJB deployment descriptor file that describes the HelloWorld stateless session EJB.
build.xml The Java Ant build script that creates an EJB JAR file that contains the HelloWorld 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\basic\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

 

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/basic_statelessSession/HelloWorldEJB

    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 executes successfully, you will see the following message in the command shell from which you started WebLogic Server:
setSessionContext called
ejbCreate called
sayHello in the HelloWorld EJB has been invoked with arguments A and 4
And the following output in your client window:
Buildfile: build.xml

run:
     [java] The client passed the Values 4 and A to the webservice, and got back
 this result:
     [java] This message brought to you by the letter A and the number 4

BUILD SUCCESSFUL

 

See Also

Read more about:


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

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