Consumers and services use different context mechanisms to access the JMS message header properties. However, both mechanisms return the header properties as a org.apache.cxf.transports.jms.context.JMSMessageHeadersType
object.
To get the JMS message header properties from the WebServiceContext
object, do the following:
Obtain the context as described in Obtaining a context.
Get the message headers from the message context using the message context's get()
method with the parameter org.apache.cxf.transports.jms.JMSConstants.JMS_SERVER_HEADERS
.
Example 20.12 shows code for getting the JMS message headers from a service's message context:
Example 20.12. Getting JMS Message Headers in a Service Implementation
import org.apache.cxf.transport.jms.JMSConstants; import org.apache.cxf.transports.jms.context.JMSMessageHeadersType; @WebService(serviceName = "HelloWorldService", portName = "HelloWorldPort", endpointInterface = "org.apache.cxf.hello_world_jms.HelloWorldPortType", targetNamespace = "http://cxf.apache.org/hello_world_jms") public class GreeterImplTwoWayJMS implements HelloWorldPortType { @Resource protected WebServiceContext wsContext; ... @WebMethod public String greetMe(String me) { MessageContext mc = wsContext.getMessageContext(); JMSMessageHeadersType headers = (JMSMessageHeadersType) mc.get(JMSConstants.JMS_SERVER_HEADERS); ... } ... }
Once a message is successfully retrieved from the JMS transport you can inspect the JMS header properties using the consumer's response context. In addition, you can see how long the client waits for a response before timing out.
You can To get the JMS message headers from a consumer's response context do the following:
Get the response context as described in Obtaining a context.
Get the JMS message header properties from the response context using the context's get()
method with org.apache.cxf.transports.jms.JMSConstants.JMS_CLIENT_RESPONSE_HEADERS
as the parameter.
Example 20.13 shows code for getting the JMS message header properties from a consumer's response context.
Example 20.13. Getting the JMS Headers from a Consumer Response Header
import org.apache.cxf.transports.jms.context.*; // Proxy greeter initialized previouslyBindingProvider bp = (BindingProvider)greeter;
Map<String, Object> responseContext = bp.getResponseContext();
JMSMessageHeadersType responseHdr = (JMSMessageHeadersType) responseContext.get(JMSConstants.JMS_CLIENT_REQUEST_HEADERS); ... }
The code in Example 20.13 does the following: