# Specifying Message Headers and Properties

The JMS control includes properties for setting and retrieving headers and properties on a JMS message.

Note: In the previous version of WebLogic Workshop, you could use XML maps to translate between the JMS control's method and callback parameters and the JMS message headers and message properties. XML maps are no longer supported as a means of specifying JMS headers and properties. Instead, WebLogic Workshop provides new annotations for working with message headers and properties. If you upgrade an existing JMS control from a CTRL file to a JCX file, you'll need to update the control to use the new annotations.

## Accessing Message Headers

A JMS message includes a number of header fields that contain information used to identify and route messages. You can retrieve the message headers for a incoming message received using the JMS control by using the @jc:jms-headers annotation. The @jc-jms-headers annotation has attributes that correspond to standard JMS headers. The supported headers for an incoming message are:

- JMSCorrelationID
- JMSDeliveryMode
- JMSExpiration
- JMSMessageID
- JMSPriority
- JMSRedelivered
- JMSTimestamp
- JMSType

For more information on these headers, see the Sun JMS specification.

You can specify whichever headers you are interested in as attributes on the @jc:jms-headers annotation, but each attribute value that you specify must map to a parameter of the same name in the callback signature for the JMS control. This way, WebLogic Workshop knows to retrieve the header value and pass it in to your code via the callback.

Only two of these headers can be set on an outgoing message: the JMSCorrelationID header and the JMSType header. The JMSCorrelationID header must be set to the conversation ID of the service that is listening. The JMSType header can be set to an arbitrary value to distinguish the type of message the sender is sending.

To see an example that retreives JMS headers, take a look at the source code for the sample JMS control file AccountSubscribeJMSControl.jcx. This sample is available in the SamplesApp application, in the jms folder of the WebServices project.

## Accessing Message Properties

A JMS message can also include properties that you or the message sender can add to send additional information about the message. You can think of them as optional, custom headers. Properties can be of type boolean, byte, short, int, long, float, double, or string. They can be set when a message is sent, or they can be read by the consumer of a message upon receipt. You can add as many properties to the message as you need to.

You can set and retrieve the properties of messages sent and received using the JMS control by using the @jc:jms-property annotation. This annotation lets you specify properties as name/value pairs: the key attribute is the property identifier, and the value attribute is the property value.

You can also set properties from your code using the setProperties() method on the JMS control interface. You can return property values using the getProperties() method.

If the JMS control is receiving an incoming message, the JMS control extracts the incoming property values specified by the @jc:jms-property annotation and passes them to the control's callback. The property values must therefore map to the callback's parameters.

If the JMS control is sending a message, the JMS control adds the properties specified by the @jc:jms-property annotation to the outgoing message. You can optionally specify that a parameter passed to the method that sends the message should be substituted as a property value on the message.

Note that the properties specified on the outgoing message must match those on the incoming message in name and type. There is no implicit type conversion for properties on a JMS message.

## Related Topics

JMS Control

Overview: Messaging Systems and JMS

Specifying the Message Body

SimpleJMS.jws Sample

CustomJMSClient.jws Sample

@jc:jms Annotation

@jc:jms-headers Annotation

@jc:jms-property Annotation