6-24 Programming JMS for Oracle WebLogic Server
The examples.jms.sender.SenderServlet example, provided with WebLogic Server in the WL_
HOME \samples\server\examples\src\examples\jms\sender directory,
where WL_HOME is the top-level directory of your WebLogic Platform installation, shows how to set header fields in messages that you send and how to display message
header fields after they are sent.
For example, the following code, which appears after the send method, displays the message ID that was assigned to the message by WebLogic JMS:
System.out.printlnSent message + msg.getJMSMessageID + to +
msg.getJMSDestination;
6.8.2 Setting Message Property Fields
To set a property field, call the appropriate set method and specify the property name and value. To read a property field, call the appropriate get method and specify the
property name.
The sending application can set properties in the message, and the receiving application can subsequently view them. The receiving application cannot change the
properties without first clearing them using the following clearProperties method:
public void clearProperties throws JMSException
This method does not clear the message header fields or body. JMSReplyTo
public void setJMSReplyTo Destination replyTo
throws JMSException public Destination getJMSReplyTo
throws JMSException JMSTimeStamp1
public void setJMSTimeStamp long timestamp
throws JMSException public long getJMSTimeStamp
throws JMSException JMSType
public void setJMSType String type
throws JMSException public String getJMSType
throws JMSException
1
The corresponding set method has no impact on the message header field when the send method is executed. If set, this header field value will be overridden during the send operation.
Note: The JMSX property name prefix is reserved for JMS. The
connection metadata contains a list of JMSX properties, which can be accessed as an enumerated list using the
getJMSXPropertyNames method. For more information, see Section 6.3.2, Accessing Connection Metadata.
The JMS_ property name prefix is reserved for provider-specific properties; it is not intended for use with standard JMS messaging.
Table 6–3 Cont. JMS Header Field Methods
Header Field Set Method
Get Method
Managing Your Applications 6-25
The property field can be set to any of the following types: boolean, byte, double, float, int, long, short, or string. The following table lists the Message class set and get
methods for each of the supported data types.
In addition to the set and get methods described in the previous table, you can use the setObjectProperty and getObjectProperty methods to use the
objectified primitive values of the property type. When the objectified value is used, the property type can be determined at execution time rather than during the
compilation. The valid object types are boolean, byte, double, float, int, long, short, and string.
You can access all property field names using the following Message method: public Enumeration getPropertyNames
throws JMSException This method returns all property field names as an enumeration. You can then retrieve
the value of each property field by passing the property field name to the appropriate get method, as described in the previous table, based on the property field data type.
Table 6–4 Message Property Set and Get Methods for Data Types
Data Type Set Method
Get Method
boolean public void setBooleanProperty
String name, boolean value
throws JMSException public boolean getBooleanProperty
String name throws JMSException
byte public void setByteProperty
String name, byte value
throws JMSException public byte getByteProperty
String name throws JMSException
double public void setDoubleProperty
String name, double value
throws JMSException public double getDoubleProperty
String name throws JMSException
float public void setFloatProperty
String name, float value
throws JMSException public float getFloatProperty
String name throws JMSException
int public void setIntProperty
String name, int value
throws JMSException public int getIntProperty
String name throws JMSException
long public void setLongProperty
String name, long value throws JMSException
public long getLongProperty String name
throws JMSException short
public void setShortProperty String name,
short value throws JMSException
public short getShortProperty String name
throws JMSException
String public void setStringProperty
String name, String value
throws JMSException public String getStringProperty
String name throws JMSException
6-26 Programming JMS for Oracle WebLogic Server
Table 6–5 contains a conversion chart for message properties. It allows you to identify
the type that can be read based on the type that has been written. For each property type listed in the left-most column in which a message has been written, a YES in one
of the remaining columns indicates that the message can be read as the type listed at the top of that column.
You can test whether or not a property value has been set using the following Message method:
public boolean propertyExists String name
throws JMSException
You specify a property name and the method returns a boolean value indicating whether or not the property exists.
For example, the following code sets two String properties and an int property: msg.setStringPropertyUser, user;
msg.setStringPropertyCategory, category; msg.setIntPropertyRating, rating;
For more information about message property fields, see Section 2.4.6.2, Message
Property Fields, or the javax.jms.Message Javadoc at
http:java.sun.comjavaee5docsapijavaxjmsMessage.html .
6.8.3 Browsing Header and Property Fields