This chapter describes how to use JMS transport as the connection protocol with WebLogic Java API for XML-based RPC (JAX-RPC) web service using asynchronous request-response.
This chapter includes the following sections:
Configuring the Host WebLogic Server Instance for the JMS Transport Web Service
Using the <WLJmsTransport> Child Element of the jwsc Ant Task
Typically, client applications use HTTP/S as the connection protocol when invoking a WebLogic web service. You can, however, configure a WebLogic web service so that client applications use JMS as the transport instead.
Using JMS transport offers the following benefits: reliability, scalability, and quality of service. As with web service reliable messaging, if WebLogic Server goes down while the method invocation is still in the queue, it will be dealt with as soon as WebLogic Server is restarted. When a client invokes a web service, the client does not wait for a response from the invoke, and the execution of the client can continue. Using JMS transport does require slightly more overhead and programming complexity than HTTP/S.
You configure transports using either JWS annotations or child elements of the jwsc
Ant task, as described in later sections. When a WebLogic web service is configured to use JMS as the connection transport, the endpoint address specified for the corresponding port in the generated WSDL of the web service uses jms://
in its URL rather than http://
. An example of a JMS endpoint address is as follows:
jms://myHost:7001/transports/JMSTransport?URI=JMSTransportQueue
The URI=JMSTransportQueue
section of the URL specifies the JMS queue that has been configured for the JMS transport feature. Although you cannot invoke the web service using HTTP, you can view its WSDL using HTTP, which is how the clientgen
is still able to generate JAX-RPC stubs for the web service.
For each transport that you specify, WebLogic Server generates an additional port in the WSDL. For this reason, if you want to give client applications a choice of transports they can use when they invoke the web service (JMS, HTTP, or HTTPS), you should explicitly add the transports using the appropriate JWS annotations or child elements of jwsc
.
Note:
Using JMS transport is an added-value WebLogic feature; non-WebLogic client applications, such as a .NET client, may not be able to invoke the web service using the JMS port.To use JMS transport when starting from Java, you must perform at least one of the following tasks:
Add the @WLJmsTransport
annotation to your JWS file.
Add a <WLJmsTransport>
child element to the jwsc
Ant task. This setting overrides the transports defined in the JWS file.
Note:
Because you might not know at the time that you are coding the JWS file which transport best suits your needs, it is often better to specify the transport at build-time using the<WLJmsTransport>
child element.The following procedure describes the complete set of steps required so that your web service can be invoked using the JMS transport when starting from Java.
Note:
It is assumed that you have created a basic JWS file that implements a web service and that you want to configure the web service to be invoked using JMS. It is also assumed that you have set up an Ant-based development environment and that you have a workingbuild.xml
file that includes targets for running the jwsc
Ant task and deploying the service.Table 13-1 Steps to Use JMS Transport Starting From Java
# |
Step | Description |
---|---|---|
1 |
Configure the WebLogic Server domain for the required JMS components. |
See Configuring the Host WebLogic Server Instance for the JMS Transport Web Service. |
2 |
Add the |
This step is optional. If you do not add the |
3 |
Add a |
Use the See Using the <WLJmsTransport> Child Element of the jwsc Ant Task for details. |
4 |
Build your web service by running the target in the |
For example, if the target that calls the prompt> ant build-service |
5 |
Deploy your web service to WebLogic Server. |
See Invoking a WebLogic Web Service Using JMS Transport for information about updating your client application to invoke the web service using JMS transport.
To use JMS transport when starting from WSDL, you must perform at least one of the following tasks:
Update the WSDL to use JMS transport before running the wsdlc
Ant task.
Update the stubbed-out JWS implementation file generated by the wsdlc
Ant task to add the @WLJmsTransport
annotation.
Add a <WLJmsTransport>
child element to the jwsc
Ant task used to build the JWS implementation file. This setting overrides the transports defined in the JWS file.
Note:
Because you might not know at the time that you are coding the JWS file which transport best suits your needs, it is often better to specify the transport at build-time using the<WLJmsTransport>
child element.The following procedure describes the complete set of steps required so that your web service can be invoked using the JMS transport when starting from WSDL.
Note:
It is assumed in this procedure that you have an existing WSDL file.Table 13-2 Steps to Use JMS Transport Starting From WSDL
# |
Step | Description |
---|---|---|
1 |
Configure the WebLogic Server domain for the required JMS components. |
See Configuring the Host WebLogic Server Instance for the JMS Transport Web Service. |
2 |
Update the WSDL to use JMS transport. (Optional) |
This step is optional. If you do not update the WSDL to use JMS transport, then you must do at least one of the following:
|
3 |
Run the |
For example, if the target that calls the prompt> ant generate-from-wsdl |
4 |
Update the stubbed-out JWS file. |
The If you updated the WSDL to use the JMS transport in Step 2, the JWS file includes the
|
5 |
Add a |
Use the See Using the <WLJmsTransport> Child Element of the jwsc Ant Task for details. |
6 |
Run the |
Specify the artifacts generated by the |
7 |
Deploy the web service to WebLogic Server. |
See Invoking a WebLogic Web Service Using JMS Transport for information about updating your client application to invoke the web service using JMS transport.
Configuring the WebLogic Server instance on which the JMS transport web service is deployed involves configuring JMS resources, such as JMS servers and modules, that are used internally by the web services runtime.
You can configure these resources manually or you can use the Configuration Wizard to extend the WebLogic Server domain using a web services-specific extension template. Using the Configuration Wizard greatly simplifies the required configuration steps; for details, see "Configuring Your Domain For Web Services Features".
Notes:
Alternatively, you can use WLST to configure the resources. For information about using WLST to extend the domain, see "Configuring Existing Domains" in Understanding the WebLogic Scripting Tool.A domain that does not contain Web Services resources will still boot and operate correctly for non-web services scenarios, and any Web Services scenario that does not involve asynchronous request and response. You will, however, see INFO messages in the server log indicating that asynchronous resources have not been configured and that the asynchronous response service for web services has not been completely deployed.
If you prefer to configure the resources manually, perform the following steps.
Table 13-3 Steps to Configure Host WebLogic Server Instance Manually for the JMS Transport Web Service
# |
Step | Description |
---|---|---|
1 |
Invoke the WebLogic Server Administration Console for the domain that contains the host WebLogic Server instance. |
To invoke the WebLogic Server Administration Console in your browser, enter the following URL: http://host:port/console where
See "Invoking the Administration Console" in Understanding WebLogic Web Services for Oracle WebLogic Server. |
3 |
Create a JMS Server. |
Create a JMS Server. If a JMS server already exists, you can use it if you do not want to create a new one. See "Create JMS servers" in Oracle WebLogic Server Administration Console Online Help. |
4 |
Create JMS module and define queue. |
Create a JMS module, and then define a JMS queue in the module. If a JMS module already exists, you can use it if you do not want to create a new one. Target the JMS queue to the JMS server you created in the preceding step. Be sure you specify that this JMS queue is local, typically by setting the local JNDI name. See "Create JMS system modules" and "Create queues in a system module" in Oracle WebLogic Server Administration Console Online Help. If you want the JMS transport web service to use the default web services queue, set the JNDI name of the JMS queue to Clustering Considerations: If you are using the web service JMS transport feature in a cluster, you must:
|
If you know at the time that you program the JWS file that you want client applications to use JMS transport (instead of HTTP/S) to invoke the web service, you can use the @WLJmsTransport
to specify the details of the invocation. Later, at build-time, you can override the invocation defined in the JWS file and add additional JMS transport specifications, by specifying the <WLJmsTransport>
child element of the jwsc
Ant task, as described in Using the <WLJmsTransport> Child Element of the jwsc Ant Task.
Follow these guidelines when using the @WLJmsTranport
annotation:
You can include only one @WLJmsTransport
annotation in a JWS file.
Use the queue
attribute to specify the JNDI name of the JMS queue you configured earlier in the section. If you want to use the default web services queue (weblogic.wsee.DefaultQueue
) then you do not have to specify the queue
attribute.
Use the connectionFactory
attribute to specify the JNDI name of the connection factory. The default value of this attribute is the default JMS connection factory for your WebLogic Server instance.
The following example shows a simple JWS file that uses the @WLJmsTransport
annotation, with the relevant code in bold:
package examples.webservices.jmstransport; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import weblogic.jws.WLJmsTransport; @WebService(name="JMSTransportPortType", serviceName="JMSTransportService", targetNamespace="http://example.org") @SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle=SOAPBinding.ParameterStyle.WRAPPED) // WebLogic-specific JWS annotation that specifies the context path and // service URI used to build the URI of the Web Service is // "transports/JMSTransport" @WLJmsTransport(contextPath="transports", serviceUri="JMSTransport", queue="JMSTransportQueue", portName="JMSTransportServicePort", connectionFactory="JMSTransportConnectionFactory") /** * This JWS file forms the basis of simple Java-class implemented WebLogic * Web Service with a single operation: sayHello */ public class JMSTransportImpl { @WebMethod() public String sayHello(String message) { System.out.println("sayHello:" + message); return "Here is the message: '" + message + "'"; } }
You can also specify the JMS transport at build-time by using the <WLJmsTransport>
child element of the <jws>
element of the jwsc
Ant task. Reasons for specifying the transport at build-time include:
You need to override the attribute values specified in the JWS file.
The JWS file specifies a different transport, and at build-time you decide that JMS should be the transport.
The JWS file does not include a @WLXXXTransport
annotation; thus by default the HTTP transport is used, but at build-time you decide you want to clients to use the JMS transport to invoke the web service.
If you specify a transport to the jwsc
Ant task, it takes precedence over any transport annotation in the JWS file.
The following example shows how to specify a transport to the jwsc
Ant task:
<target name="build-service"> <jwsc srcdir="src" destdir="${ear-dir}"> <jws file="examples/webservices/jmstransport/JMSTransportImpl.java"> <WLJmsTransport contextPath="transports" serviceUri="JMSTransport" portName="JMSTransportServicePort" queue="JMSTransportQueue" connectionFactory="JMSTransportConnectionFactory"/> </jws> </jwsc> </target>
The preceding example shows how to specify the same values for the URL and JMS queue as were specified in the JWS file shown in Using the @WLJmsTransport JWS Annotation.
For more information about using the jwsc
Ant task, see "jwsc" in WebLogic Web Services Reference for Oracle WebLogic Server.
To update the WSDL to use JMS transport, you need to add <wsdl:binding>
and <wsdl:service>
definitions that define JMS transport information. You can add the definitions in one of the following ways:
Edit the existing HTTP <wsdl:binding>
and <wsdl:service>
definitions.
To specify multiple transport options in the WSDL, copy the existing HTTP <wsdl:binding>
and <wsdl:service>
definitions and edit them to use JMS transport.
In either case, you must modify the <wsdl:binding>
and <wsdl:service>
definitions to use JMS transport as follows:
Set the transport
attribute of the <soapwsdl:binding>
child element of the <wsdl:binding>
element to http://www.openuri.org/2002/04/soap/jms/
. For example:
<binding name="JmsTransportServiceSoapBindingjms" type="tns:JmsTransportPortType">
<soap:binding style="document" transport="http://www.openuri.org/2002/04/soap/jms/"/>
Specify a JMS-style endpoint URL for the location
attribute of the <soapwsdl:address>
child element of the <wsdl:service>
. For example:
<s0:service name="JmsTransportService">
<s0:port binding="s1:JmsTransportServiceSoapBindingjms" name="JmsTransportServicePort">
<s2:address location="jms://localhost:7001/transports/JmsTransport?URI=JMSTransportQueue"/>
</s0:port>
</s0:service>
You write a client application to invoke a web service using JMS transport in the same way as you write one using the HTTP transport; the only difference is that you must ensure that the JMS queue (specified by the @WLJmsTransport
annotation or <WLJmsTransport>
child element of the jwsc
Ant task) and other JMS objects have been created. See Using JMS Transport Starting From Java: Main Steps or Using JMS Transport Starting From WSDL: Main Steps for more information.
Although you cannot invoke a JMS-transport-configured web service using HTTP, you can view its WSDL using HTTP, which is how the clientgen
Ant task is still able to create the JAX-RPC stubs for the web service. For example, the URL for the WSDL of the web service shown in this section would be:
http://host:port/transports/JMSTransport?WSDL
However, because the endpoint address in the WSDL of the deployed web service uses jms://
instead of http://
, and the address includes the qualifier ?URI=
JMS_QUEUE, the clientgen
Ant task automatically creates the stubs needed to use the JMS transport when invoking the web service, and your client application need not do anything different than normal. An example of a JMS endpoint address is as follows:
jms://host:port/transports/JMSTransport?URI=JMSTransportQueue
Note:
If you have specified that the web service you invoke using JMS transport also runs within the context of a transaction (in other words, the JWS file includes the@weblogic.jws.Transactional
annotation), you must use asynchronous request-response when invoking the service. If you do not, a deadlock will occur and the invocation will fail.For general information about invoking a web service, see "Developing JAX-RPC Web Service Clients".
When you write a client application that uses the clientgen
-generated JAX-RPC stubs to invoke a web service, the default service address URL of the web service is the one specified in the <address>
element of the WSDL file argument of the Service
constructor.
Sometimes, however, you might need to override this address, in particular when invoking a WebLogic web service that is deployed to a cluster and you want to specify the cluster address or a list of addresses of the managed servers in the cluster. You might also want to use the t3
protocol to invoke the web service. To override this service endpoint URL when using JMS transport, use the weblogic.wsee.jaxrpc.WLStub.JMS_TRANSPORT_JNDI_URL
stub property as shown in the following example:
package examples.webservices.jmstransport.client; import weblogic.wsee.jaxrpc.WLStub; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import javax.xml.rpc.Stub; /** * This is a simple standalone client application that invokes the * the <code>sayHello</code> operation of the JMSTransport web service. */ public class Main { public static void main(String[] args) throws ServiceException, RemoteException{ JMSTransportService service = new JMSTransportService_Impl(args[0] + "?WSDL" ); JMSTransportPortType port = service.getJMSTransportServicePort(); Stub stub = (Stub) port; stub._setProperty(WLStub.JMS_TRANSPORT_JNDI_URL, "t3://shackell01.amer.com:7001"); try { String result = null; result = port.sayHello("Hi there! "); System.out.println( "Got JMS result: " + result ); } catch (RemoteException e) { throw e; } } }
When you use JMS transport, the web services runtime uses, by default, the javax.jms.TextMessage
object to send the message. This is usually adequate for most client applications, but sometimes you might need to send binary data rather than ordinary text; in this case you must request that the web services runtime use javax.jms.BytesMessage
instead. To do this, use the WLStub.JMS_TRANSPORT_MESSAGE_TYPE
stub property in your client application and set it to the value WLStub.JMS_BYTESMESSAGE
, as shown in the following example:
stub._setProperty(WLStub.JMS_TRANSPORT_MESSAGE_TYPE, WLStub.JMS_BYTESMESSAGE);
The web services runtime sends back the response using the same message data type as the request.
See Overriding the Default Service Address URL for a full example of a client application in which you can set this property.
As described in Invoking a WebLogic Web Service Using JMS Transport, the WSDL of the deployed web service is, by default, still accessible using HTTP. If you want to disable access to the WSDL file, in particular if your web service can be accessed outside of a firewall, then you can do one of the following:
Use the weblogic.jws.WSDL
annotation in your JWS file to programmatically disable access. For details, see "weblogic.jws.WSDL" in WebLogic Web Services Reference for Oracle WebLogic Server.
Use the WebLogic Server Administration Console to disable access to the WSDL file after the web service has been deployed. In this case, the configuration information will be stored in the deployment plan rather than through the annotation.
To use the WebLogic Server Administration Console to perform this task, go to the Configuration -> General page of the deployed web service and uncheck the View Dynamic WSDL Enabled check box. After saving the configuration to the deployment plan, you must redeploy (update) the web service, or Enterprise Application which contains it, for the change to take effect.