package examples.jms.messageformat; import java.io.IOException; import java.io.StringReader; import java.util.Hashtable; import javax.jms.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import weblogic.jms.extensions.WLQueueSession; import weblogic.jms.extensions.XMLMessage; /** * This class shows how to establish a connection to and receive messages from * a JMS queue. *
Run this class after you have run the ClientSend class to send XML
* data to a JMS queue. After ClientSend has sent its message, the Message-
* driven EJB
* Use this command:
* java examples.jms.messageformat.ClientReceive t3://localhost:7001
*/
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println("Usage: java examples.jms.messageformat.ClientReceive WebLogicURL");
return;
}
ClientReceive receiver = new ClientReceive();
receiver.receive(args[0]);
}
}
MessageTraderBean
retrieves the XML data from the
* queue, parses it, then sends the output to another JMS queue. This class,
* ClientReceive, gets the final message from this JMS queue.
*
* @author Copyright (c) 2005 by BEA Systems, Inc. All Rights Reserved.
*/
public class ClientReceive {
public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
public final static String JMS_FACTORY="weblogic.examples.jms.messageformat.QueueConnectionFactory";
public final static String QUEUE="weblogic.examples.jms.messageformat.exampleQueueReceive";
private static String xmlMessage = null;
public String getXmlMessage() { return xmlMessage; }
/**
* Establishes a connection to the JMS queue and receives the
* trade result in the form of XML data.
*
* @exception NamingException if a JNDI naming exception occurred
* @exception JMSException if a JMS exception occurred
* @exception IOException if an IO naming exception occurred
* @exception ParserConfigurationException if a parser configuration exception occurred
* @exception SAXException if a SAX exception occurred
*/
public void receive(String url)
throws NamingException, JMSException, IOException,
ParserConfigurationException, SAXException, Exception
{
// Look up the Queue and the QueueConnection Factory
// in a JNDI naming and directory service, or create
// them directly.
Hashtable