LibraryLink ToToggle FramesPrintFeedback

Setting JMS Properties

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.


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.

You can also set optional properties to the JMS header. Optional JMS header properties are stored in the JMSMessageHeadersType object that is used to set the other JMS header properties. They are stored as a List object containing org.apache.cxf.transports.jms.context.JMSPropertyType objects. To add optional properties to the JMS header do the following:

  1. Create a JMSPropertyType object.

  2. Set the property's name field using setName().

  3. Set the property's value field using setValue().

  4. Add the property to the JMS message header using JMSMessageHeadersType.getProperty().add(JMSPropertyType).

  5. Repeat the procedure until all of the properties have been added to the message header.

In addition to the JMS header properties, you can set the amount of time a consumer endpoint waits for a response before timing out. You set the value by calling the request context's put() method with org.apache.cxf.transports.jms.JMSConstants.JMS_CLIENT_RECEIVE_TIMEOUT as the first argument and a long representing the amount of time in milliseconds that you want the consumer to wait 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");
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:


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


Checks to see if the InvocationHandler is a BindingProvider.


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


Gets the request context.


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


Sets the Correlation ID.


Sets the Expiration property to 60 minutes.


Creates a new JMSPropertyType object.


Sets the values for the optional property.


Adds the optional property to the message header.


Sets the JMS message header values into the request context.


Sets the client receive timeout property to 1 second.