} }

 Files   Prepare   Run   Troubleshooting   Related Topics 

 

About the Example

This example shows how to invoke the operations of a WebLogic Web Service from within a stateless session EJB. The example also shows the standard way to invoke the EJB (which in turn invokes the Web Service) from a standalone Java application.

 

Description of the Web Service

As described in the Web Service example Creating a Web Service Using JWS Metadata Annotations (listed under the Oracle WebLogic Server Examples > Examples > API> Web Services node in the Samples Viewer), the Web Service in this example also uses JWS annotations to specify the shape and behavior of the Web Service. See the documentation for the simple Web Service example for a full explanation of the basic JWS annotations (@WebService, @WebMethod, @SoapBinding, and @WLHttpTransport).

The generated Web Service in this example, called SimpleService, has two operations:

The SimpleBean.java Java source file (also called JWS file) forms the basis of the Web Service. The file uses both standard (defined by JSR-181) and WebLogic-specific JWS annotations to define the shape and behavior of the Web Service. See the Creating a Web Service Using JWS Metadata Annotations example for an explanation of the basic JWS annotations, such as @WebService, @WebMethod, and so on. Also see this example for an explanation of using the jwsc WebLogic Web Services Ant task to compile the JWS file into a deployable Web Service.

 

Description of the EJB That Invokes the Web Service

The WSEJBClientBean stateless session EJB is implemented with the WSEJBClientBean.java file, which uses the following EJBGen annotations to specify the shape and behavior of the EJB:

The EJB defines the following two remote methods:

Before the EJB can invoke the Web Service operations, it must first use the clientgen-generated JAX-RPC stubs to instantiate Service and PortType objects based on the Web Service it is invoking, in this case the SimpleService Web Service. It does this by first importing the stubs generated by clientgen:

import examples.webservices.jws_basic.ejbClient.client.MyPortType;

import examples.webservices.jws_basic.ejbClient.client.SimpleService;
import examples.webservices.jws_basic.ejbClient.client.SimpleService_Impl;

The names of the Service and PortType stubs are based on the @WebService JWS annotation in the JWS file that implements the Web Service (SimpleBean.java):

@WebService(name="myPortType",

serviceName="SimpleService",
targetNamespace="http://example.org")

Then, in the ejbCreate method, the EJB uses the standard JAX-RPC procedures for getting a Service and PortType stub based on the WSDL of the deployed Web Service:

      SimpleService service = new SimpleService_Impl(URL + "?WSDL");

port = service.getHelloPort();

In the preceding code, port is of data type MyPortType, and URL is the URL of the deployed SimpleService Web Service.

The business methods of the EJB can then use the port variable to invoke the operations of the Web Service. For example:

  public String echoString(String echoStr) throws RemoteException {

return (port.echoString(echoStr));
}

 

Description of the Client Application that Invokes the EJB

The Client application is a standalone Java client application that invokes the remote methods of the WSEJBClientBean stateless session EJB. See the examples listed under the Oracle WebLogic Server Examples > Examples > API> EJB node in the Samples Viewer for basic information about EJBs and invoking them from a client application.


 

Files Used in the Example

Directory Location:

MW_HOME/wlserver_10.3/samples/server/examples/webservices/jws_basic/ejbClient

(where MW_HOME is the directory containing your Oracle WebLogic Server installation)

File

Click source files to view code.

Description

SimpleBean.java Java source file that contains the JWS metadata annotations (both standard and WebLogic-specific) that define the JWS-implemented Web Service. The JWS file includes two methods that implement the Web Service operations: echoString and echoInt (which is publicly called myoperation.).
WSEJBClientBean.java Java source file that implements the stateless session EJB. The EJB contains two business methods, echoString and echoNumber,which in turn invoke the echoString and myoperation operations of the Web Service, respectively.
Client.java Standalone client application that invokes the deployed stateless session EJB, which in turn invokes the operations of the Web Service.
application.xml The Java EE standard enterprise application deployment descriptor.
build.xml Ant build file that contains targets for building and running the example. In particular, it has targets for building and deploying the Web Service. This build file then calls the build-ejbClient.xml file, which builds and deploys the stateless session EJB.
build-ejbClient.xml Ant build file that contains targets for building and running the example. In particular, it builds and deploys the stateless session EJB.

 

Prepare the Example

 

Prerequisites

Before working with this example:

  1. Install Oracle WebLogic Server, including the examples.
  2. Start the Examples server.
  3. Set up your environment.

 

Configure Oracle WebLogic Server

  No special configuration is required for this example

 

Build and Deploy the Example

  1. Execute the following command:

    prompt> ant build

    This command compiles and stages the example. The build target includes a call to the build.ejbClientBean.xml Ant build file which builds the stateless session EJB.
  2. Execute the following command:

    prompt> ant deploy deploy.ejbClientBean

    The deploy target deploys the Web Service and the deploy.ejbClientBean deploys the stateless session EJB which acts as a client to the Web Service by invoking two of its operations. Both components are deployed to the wl_server domain of your Oracle WebLogic Server installation.

 

Run the Example

To run the example, follow these steps:

  1. Complete the steps in the "Prepare the Example" section.
  2. In your development shell, run the Client Java application by using the following command from the main example directory (SAMPLES_HOME\server\examples\src\examples\webservices\jws_basic\ejbClient):

    prompt> ant run

  3. After building and running the example, you can view the WSDL of the Web Service by browsing to the following URL in your Web browser:

    http://host:port/jws_basic_ejbClient/SimpleBean?WSDL

    where

 

Check the Output

If your example runs successfully, you will get the following message in the command shell from which you ran the client application:

run:

[java] Beginning ejbClient.Client...

[java] Creating a WSEJBClient
[java] The echoed string is: Hello There
[java] The echoed number is: 28
[java] Removing the WSEJBClient

[java] End ejbClient.Client...

BUILD SUCCESSFUL


 

Troubleshooting


 

Related Topics

(Internet connection required.)