LibraryToggle FramesPrintFeedback

Using the request context in a consumer endpoint, you can set a number of the JMS message header properties and the consumer endpoint's timeout value. These properties are valid for a single invocation. You must reset them each time you invoke an operation on the service proxy.

[Note]Note

You cannot set header properties in a service.

Table 20.4 lists the properties in the JMS header that can be set using the consumer endpoint's request context.


To set these properties do the following:

  1. Create an org.apache.cxf.transports.jms.context.JMSMessageHeadersType object.

  2. Populate the values you want to set using the appropriate setter methods described in Table 20.4.

  3. Set the values to the request context by calling the request context's put() method using org.apache.cxf.transports.jms.JMSConstants.JMS_CLIENT_REQUEST_HEADERS as the first argument, and the new JMSMessageHeadersType object as the second argument.

Example 20.15 shows code for setting some of the JMS properties using the request context.

Example 20.15. Setting JMS Properties using the Request Context

import org.apache.cxf.transports.jms.context.*;
 // Proxy greeter initialized previously
1InvocationHandler handler = Proxy.getInvocationHandler(greeter);


BindingProvider bp= null;
2if (handler instanceof BindingProvider)
{
3  bp = (BindingProvider)handler;
4  Map<String, Object> requestContext = bp.getRequestContext();
  
5  JMSMessageHeadersType requestHdr = new JMSMessageHeadersType();
6  requestHdr.setJMSCorrelationID("WithBob");
7  requestHdr.setJMSExpiration(3600000L);
  
  
8  JMSPropertyType prop = new JMSPropertyType;
9  prop.setName("MyProperty");
  prop.setValue("Bluebird");
10  requestHdr.getProperty().add(prop);

11  requestContext.put(JMSConstants.CLIENT_REQUEST_HEADERS, requestHdr);

12  requestContext.put(JMSConstants.CLIENT_RECEIVE_TIMEOUT, new Long(1000));
}

The code in Example 20.15 does the following:

1

Gets the InvocationHandler for the proxy whose JMS properties you want to change.

2

Checks to see if the InvocationHandler is a BindingProvider.

3

Casts the returned InvocationHandler object into a BindingProvider object to retrieve the request context.

4

Gets the request context.

5

Creates a JMSMessageHeadersType object to hold the new message header values.

6

Sets the Correlation ID.

7

Sets the Expiration property to 60 minutes.

8

Creates a new JMSPropertyType object.

9

Sets the values for the optional property.

10

Adds the optional property to the message header.

11

Sets the JMS message header values into the request context.

12

Sets the client receive timeout property to 1 second.

Comments powered by Disqus
loading table of contents...