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.

[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.

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");
  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.