ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

XML Messaging Using JBoss
Pages: 1, 2, 3, 4

Using Castor in JBoss

Castor is one of the data-binding frameworks for Java. At the time of this writing, there is no JMX implementation for Castor (yet).

In order to use it, we just follow the instructions from the Castor home page:

  • Create the mapping file.
  • Generate or create the Java bean.
  • Load the mapping file.
  • Create a reader to the file to unmarshal from the XML message.
  • Create a new unmarshaller.
  • Unmarshal the object.

Note: Although JBoss 4.0.0 provides a Castor .jar file (castor-0.9.5-xml.jar), you need the complete .jar (castor- This is needed to handle a date field.

Design Pattern for the Producer

The figure below depicts the design pattern for the producer:

Figure 2. Design pattern for the producer

Based on the following cron expression for Oracle:

<attribute name="OracleCron">
  <![CDATA[0 * 08-18 * * ?]]>

QuartzService schedules HibernateService to retrieve data from IProducerContact using the HSQL SELECT statement:

<attribute name="OracleQuery">
  <![CDATA[FROM IContact as contact 
   WHERE contact.sendStatus <> 'S']]>

Note: IContact here is the name of the persistence class, and not the name of the interface table.

HibernateService, armed with the mapping files, unmarshalls the data retrieved to construct the Java objects. These objects are passed on to the Databinder.toGenericXML() or Databinder.toXML() methods to generate XML output.

The XML output is then transformed by XSLT. This new XML format is sent to the JMS provider, such as JBossMQ or WebSphere MQ.

To help you understand the provided code, Figure 3 shows the class diagram:

Figure 3. XMLProducer's class diagram

Figure 4 is the sequence diagram:

Figure 4. XMLProducer's sequence diagram

Design Pattern for the Consumer

Figure 5 depicts the design pattern for the consumer:

Figure 5
Figure 5. Design Pattern for the consumer

The consumer has two components, XMLConsumer.jar and XMLConsumerService.sar. The first one is the MDB component, and the second one is the business process. There are two types of incoming messages: Contact messages and Ccy messages. These will be consumed by ContactMDB or CcyMDB, respectively. There's one MDB for one type of message. This allows a concurrency process. Each MDB will then delegate the process to an MBean, called XMLConsumerService.

When an XML message is consumed, Castor marshals that message to a Java object. Then Hibernate will take over this Java object to store the data into the interface tables IConsumerContact and IConsumerCcy.

Once the data in those interface tables, it's up to AppTarget to put the data into the master database.

To help you understand the provided code, Figure 6 shows a class diagram:

Figure 6. XMLConsumer's class diagram

and Figure 7 shows a sequence diagram:

Figure 7. XMLConsumer's sequence diagram

Pages: 1, 2, 3, 4

Next Pagearrow