Browsing Header and Property Fields

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

You can browse the header and property fields of messages on a queue using the following QueueSession methods: public QueueBrowser createBrowser Queue queue throws JMSException Table 6–5 Message Property Conversion Chart Property Written As. . . boolean byte double float int long short String boolean YES No No No No No No YES byte No YES No No YES YES YES YES double No No YES No No No No YES float No No YES YES No No No YES int No No No No YES YES No YES long No No No No No YES No YES Object YES YES YES YES YES YES YES YES short No No No No YES YES YES YES String YES YES YES YES YES YES YES YES Note: Only queue message header and property fields can be browsed. You cannot browse topic message header and property fields. Managing Your Applications 6-27 public QueueBrowser createBrowser Queue queue, String messageSelector throws JMSException You must specify the queue that you wish to browse. You may also specify a message selector to filter messages that you are browsing. Message selectors are described in more detail in Section 6.9, Filtering Messages. Once you have defined a queue, you can access the queue name and message selector associated with a queue browser using the following QueueBrowser methods: public Queue getQueue throws JMSException public String getMessageSelector throws JMSException In addition, you can access an enumeration for browsing the messages using the following QueueBrowser method: public Enumeration getEnumeration throws JMSException The examples.jms.queue.QueueBrowser example, provided with WebLogic Server in the WL_HOME\samples\server\examples\src\examples\jms\queue directory, where WL_HOME is the top-level directory of your WebLogic Platform installation, shows how to access the header fields of received messages. For example, the following code line is an excerpt from the QueueBrowser example and creates the QueueBrowser object: qbrowser = qsession.createBrowserqueue; The following provides an excerpt from the displayQueue method defined in the QueueBrowser example. In this example, the QueueBrowser object is used to obtain an enumeration that is subsequently used to scan the queues messages. public void displayQueue throws JMSException { Enumeration e = qbrowser.getEnumeration; Message m = null; if e.hasMoreElements { System.out.printlnThere are no messages on this queue.; } else { System.out.printlnQueued JMS Messages: ; while e.hasMoreElements { m = Message e.nextElement; System.out.printlnMessage ID + m.getJMSMessageID + delivered + new Datem.getJMSTimestamp to + m.getJMSDestination; } } When a queue browser is no longer being used, you should close it to free up resources. For more information, see Section 5.6, Releasing Object Resources. For more information about the QueueBrowser class, see the javax.jms.QueueBrowser Javadoc at 6-28 Programming JMS for Oracle WebLogic Server http:java.sun.comjavaee5docsapijavaxjmsQueueBrowser.htm l .

6.9 Filtering Messages