3-16 Programming Advanced Features of JAX-WS Web Services for Oracle WebLogic Server
parameter when creating the Web service proxy or dispatch. You specify the name of the asynchronous handler that will be invoked when a response message is received.
The following example shows how to develop an asynchronous handler interface. The example demonstrates how to initialize the AsyncClientHandlerFeature to
connect the asynchronous handler implementation to the port used to make invocations on the backend service. This example is excerpted from
Example 2–2, Asynchronous Web Service Client Best Practices Example
.
Example 3–2 Example of Developing the Asynchronous Handler Interface
import weblogic.jws.jaxws.client.async.AsyncClientHandlerFeature; ...
BackendServiceAsyncHandler handler = new BackendServiceAsyncHandler { public void onDoSomethingResponseResponseDoSomethingResponse res {
... Handle Response ... try {
DoSomethingResponse response = res.get; _lastResponse = response.getReturn;
System.out.printlnGot async response: + _lastResponse; } catch Exception e {
_lastResponse = e.toString; e.printStackTrace;
} }
}; AsyncClientHandlerFeature handlerFeature = new AsyncClientHandlerFeaturehandler;
features.addhandlerFeature; _features = features.toArraynew WebServiceFeature[features.size];
BackendService anotherPort = _service.getBackendServicePort_features; ...
Make the invocation. Our asynchronous handler implementation set into the AsyncClientHandlerFeature above receives the response.
String request = Dance and sing; System.out.printlnInvoking DoSomething asynchronously with request: + request;
anotherPort.doSomethingAsyncrequest;
3.5.3 Propagating User-defined Request Context to the Response
The weblogic.wsee.jaxws.JAXWSProperties API defines the following properties that enables users to propagate user-defined request context information to
the response message, without relying on the asynchronous handler instance state.
The asynchronous handler instance may be created at any time; for example, if the client’s server goes down and is restarted. Therefore, storing request context in the
asynchronous handler interface will not be useful.
The JAXWSProperties properties are defined in the following table.
Table 3–8 Properties Supported by the JAXWSProperties API
This property . . . Specifies . . .
MESSAGE_ID Message ID for the request. The client can set this property on the request context
to override the auto-generation of the per-request Message ID header.
Invoking Web Services Asynchronously 3-17
In addition, Web service clients can persist context properties, as long as they are Serializable, for the request message. Context properties can include those required by
the client or the communication channels. Message properties can be stored as part of the weblogic.wsee.jaxws.JAXWSProperties.PERSISTENT_CONTEXT Map
property and retrieved after the response message is returned. For complete details, see
Section 3.8, Propagating Request Context to the Response .
3.6 Using Asynchronous Web Service Clients From Behind a Firewall MakeConnection
Web Services MakeConnection is a client polling mechanism that provides an alternative to asynchronous client transport, typically to provide support for clients
that are behind a firewall. WebLogic Server supports WS-Make Connection version 1.1, as described in the MakeConnection specification at:
http:docs.oasis-open.orgws-rxwsmc200702 , and is backwards
compatible with version 1.0. Specifically, MakeConnection:
■
Enables the decoupling of the response message from the initiating transport request used to send the request message similar to asynchronous client
transport.
■
Supports Web service clients that are non-addressable and unable to accept an incoming connection for example, clients behind a firewall.
■
Enables a Web service client to act as an MC-Initiator and the Web service to act as an MC-Receiver, as defined by the WS-MakeConnection specification.
The following figure, borrowed from the Web Services MakeConnection specification, shows a typical MakeConnection message flow.
PERSISTENT_CONTEXT Context properties required by the client or the communication channels. Web
service clients can persist context properties, as long as they are Serializable, for the request message. These properties will be available in the response context map
available from the Response object when the asynchronous handler is invoked. For more information, see
Section 3.8, Propagating Request Context to the Response
. RELATES_TO
Message ID to which the response correlates. REQUEST_TIMEOUT
For synchronous operations using asynchronous client transport, maximum amount of time to block and wait for a response. This property default to 0
indicating no timeout.
Table 3–8 Cont. Properties Supported by the JAXWSProperties API
This property . . . Specifies . . .