Contents

The XMLInteroperability Toolkit, which is a part of FioranoMQ, allows the interoperability of FioranoMQ across JMS Vendors. The Toolkit provides APIs with tools required to convert a JMS Message to an XML document and to recreate a Message from an XML document. The toolkit currently supports XML conversions for TextMessage and MapMessage. The toolkit is generic and supports XML Parser plug-ins at runtime. This toolkit can be used to communicate across different JMS Vendors. The DTD (Document Type Definition) of the Messages is public and can be used by any non-Fiorano JMS vendor to communicate with FioranoMQ.

The contents of this chapter are organized as listed below:

  • JMS Message to XML.
  • XML to JMS Message.
  • Using XMLAdapter Toolkit of FioranoMQ with other JMS Vendors.

31.5.1 JMS Message to XML

A JMS TextMessage or MapMessage can be converted to XML. To convert a message to XML, an appropriate XMLAdapter has to be created. If the Message to be converted is a MapMessage, then an instance of XMLMapMessage-Adapter is created. To illustrate, pick a TextMessage and convert it to an XML Document. Create an instance of the XMLTextMessageAdapter:

XMLTextMessageAdapter adapter = new XMLTextMessageAdapter();

To represent this message as an XML, invoke the following method on the adapter:

StringBuffer xmlData = adapter.createXML (txtMsg, false);

This call results in the conversion of the Message into an XMLDocument based on the DTD for text messages.

The code snippet used is:

 

31.5.2 XML to JMS Message

An XML Document representing a JMSMessage can be reconverted back to a JMSMessage. For example, consider an XML Document representing a TextMessage. Create an instance of the XMLTextMessageAdapter:

XMLTextMessageAdapter adapter
= new XMLTextMessageAdapter ();

Associate the XML Parser to the adapter. By default IBM's XML Parser is used. Specify the name of the main class of the parser, represented as an argument to this method. The Toolkit uses Java's reflection methods to create an instance of the parser

adapter.setXMLParser

("org.apache.xerces.parsers.SAXParser");

Reconvert the XML to a message:

adapter.createMessage( textmsg, "specify the URI of the XML Document")

The code snippet used is:

31.5.3 Using XMLAdapter Toolkit of FioranoMQ with other JMS Vendors

By default, the XML Interoperability toolkit is configured to work with FioranoMQ. This is possible because the toolkit allows a provider specific adapter to be set to the XMLAdapter. Any other JMS Vendor can use this toolkit to expose JMS messages by implementing the IProviderSpecificMessageAdapter interface and plugging it to the XMLAdapter. (More samples can be found in the \fmq\samples\XMLToolkit folder of the FMQ installation directory.)

class XMLTextMessageAdapter Declaration

public XMLTextMessageAdapter()

Purpose
The XMLTextMessageAdapter provides a compete set of methods to convert a Text-Message to its corresponding XML document and vice versa.

Method Summary

public XMLTextMessageAdapter()

Constructor: Creates an XMLTextMessageAdapter.

public void setXMLParser (String xmlParser)
throws JMSException.

Sets the fully qualified name of the XML Parser, to be used to parse the JMS message.

public void setProviderSpecificAdapter
(IProviderSpecificMessageAdapter adapter)
throws JMSException.

Sets a provider specific adapter. By default the XML toolkit works with the adapter of FioranoMQ. Any other JMS Implementation can interoperate by setting and implementing the appropriate adapters.

public void createMessage
(TextMessage msg, String uri)
throws JMSException

public void createMessage
(TextMessage msg, InputSource source)
throws JMSException

Converts the XML Message, identified by the InputSource, or a String representation, into a JMS text message.

public StringBuffer getMessageBody
(TextMessage msg)
throws JMSException

Returns the header as an XML document from the JMS message.

public String getMessageBodyDTD()

Returns the DTD for the message body.

Adaptavist ThemeBuilder EngineAtlassian Confluence