} }
Files Prepare Run Troubleshooting Related Topics
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.
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.
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));
}
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.
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. |
Before working with this example:
No special configuration is required for this example
To run the example, follow these steps:
prompt> ant run
http://host:port/jws_basic_ejbClient/SimpleBean?WSDL
where
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
(Internet connection required.)