IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Enterprise Service Bus programming > JMS binding

Access the JMS header

You can access the JMS header using Java, or the mediation flow component.


Use Java to access the JMS header

The SCA module can access the JMS message header and JMS message properties. An example where this can be used is to determine the format of the message body. A custom data handler determines the message format by accessing the JMS header. The custom data handler decides how the message body is handled.

For example, if you access the JMSType field in the JMS header, a data handler can determine how the message body is formatted. As a result, you can use a single data handler for multiple JMS message formats. This removes the need for multiple exports, imports and JMS destinations.

To access the JMS header in a data handler, you must enable protocol header propagation on the binding. The header structure is copied to the context service.

You can use the following code to access the JMS header in the context service:

 HeadersType headers = ContextService.INSTANCE.getHeaders();
 JMSHeaderType jmsHeader = headers.getJMSHeader();
 String jmsType = jmsHeader.getJMSType();
 
 if (jmsType.equals("Company1Quote")) {
 	/* parse XML using Company1 schema to create business object*/
 } else if (jmsType.equals("Company2Quote")) {
 	/* parse XML using Company2 schema to create business object*/
 } else if (jmsType.equals("Company3Quote")) {
 	/* parse XML using Company3 schema to create business object*/
 } else {
 	/* parse XML using standard schema to create business object*/
 }
The JMS message properties are stored in the header properties section of the context service. You can access them using the following code:
 HeadersType headers = ContextService.INSTANCE.getHeaders();
 List<PropertyType> properties = headers.getProperties();

 for (PropertyType property : properties) {  	
	String propName = property.getName();  	
	String propValue = property.getValue();  	
	/* Check for required JMS property */  
 }  


Use a mediation flow component to access the JMS header

When you enable context propagation on the JMS import or export binding, the JMS header is made available in the SMO, within a mediation flow component. You can then read or update the header using mediation primitives.

For example the Message Element Setter mediation primitive or JMS Header Setter mediation primitive. The structure of the JMS header in the SMO is shown in Figure 1. You can store JMS properties in the properties section of the HeaderType structure, as a list which you can read and modify. You can also statically set properties in the JMS binding. If you statically set a property, it overrides settings that are set dynamically and that have the same name.

Figure 1. The structure of the JMS header in the SMO

JMS binding