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 |
---|---|
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.
Table 20.4. Settable JMS Header Properties
Property Name | Property Type | Setter Method |
---|---|---|
Correlation ID | string |
setJMSCorralationID()
|
Delivery Mode | int |
setJMSDeliveryMode()
|
Priority | int |
setJMSPriority()
|
Time To Live | long |
setTimeToLive()
|
To set these properties do the following:
Create an org.apache.cxf.transports.jms.context.JMSMessageHeadersType
object.
Populate the values you want to set using the appropriate setter methods described in Table 20.4.
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:
Create a JMSPropertyType
object.
Set the property's name field using setName()
.
Set the property's value field using setValue()
.
Add the property to the JMS message header using
JMSMessageHeadersType.getProperty().add(JMSPropertyType)
.
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 previouslyInvocationHandler handler = Proxy.getInvocationHandler(greeter); BindingProvider bp= null;
if (handler instanceof BindingProvider) {
bp = (BindingProvider)handler;
Map<String, Object> requestContext = bp.getRequestContext();
JMSMessageHeadersType requestHdr = new JMSMessageHeadersType();
requestHdr.setJMSCorrelationID("WithBob");
requestHdr.setJMSExpiration(3600000L);
JMSPropertyType prop = new JMSPropertyType;
prop.setName("MyProperty"); prop.setValue("Bluebird");
requestHdr.getProperty().add(prop);
requestContext.put(JMSConstants.CLIENT_REQUEST_HEADERS, requestHdr);
requestContext.put(JMSConstants.CLIENT_RECEIVE_TIMEOUT, new Long(1000)); }
The code in Example 20.15 does the following:
Gets the | |
Checks to see if the | |
Casts the returned | |
Gets the request context. | |
Creates a | |
Sets the Correlation ID. | |
Sets the Expiration property to 60 minutes. | |
Creates a new | |
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. |