This content has been marked as final.
Show 2 replies
-
1. Re: Message Listener Dies
joelvogt Sep 9, 2002 8:33 PM (in response to eusebio)well that depends on what your constructor and class does. If you can post some example code that would help
-
2. Re: Message Listener Dies
eusebio Sep 10, 2002 7:17 AM (in response to eusebio)Hi
It's fairly simple - I haven't changed a huge amount from the example code I found on the JBoss site.
The application dies immediately after the call to this.recon.setRecon in the constructor (see below).package com.pindartech.yponyell.request; import com.pindartech.yponyell.db.*; import com.pindartech.yponyell.xml.*; import com.pindartech.yponyell.jms.*; import com.pindartech.yponyell.utils.YPError; import org.apache.log4j.Logger; import java.io.*; import javax.jms.*; import javax.naming.*; import java.util.Properties; /** *@author Dean Friday *@created 08 August 2002 *@version $Revision: 1.2 $ * * Handles JMS message requests for advert images. */ public class RequestHandler implements MessageListener, ExceptionListener { /** * Logger for logging output */ Logger logger; /** * Factory classes used for creating the filehandling and JMS objects */ JMSFactory jmsFactory; FileMessageFactory fileMessageFactory; xmlReader xmlr; Request req; Properties xmlProps; YPError ypError; Reconciliator recon; String xmlHeaderParams[] = null; String SAPOrderID = null; String requestType = null; String inputXML = null; private String bookCode; final static String configXML = "/data/home/yponyell/config/xml/config.xml"; public RequestHandler() throws JMSException, NamingException { this.logger = Logger.getLogger(RequestHandler.class); this.xmlr = new xmlReader(); this.xmlProps = this.xmlr.loadXMLConfig(configXML); this.jmsFactory = new JMSFactory(xmlProps.getProperty("JNDI_CONNECTION")); this.jmsFactory.setMessageListener(xmlProps.getProperty("JMS_REQUEST_QUEUE"), this); this.jmsFactory.setExceptionListener(this); this.jmsFactory.startConnection(); this.logger.debug("Finished constructing JMSFactory..."); this.fileMessageFactory = new FileMessageFactory(this.jmsFactory, this.xmlProps.getProperty("XML_IN"), this.xmlProps.getProperty("TEMP_XML_FILE"), this.xmlProps.getProperty("GIF_MAP_NAME"), this.xmlProps.getProperty("XML_MAP_NAME"), this.xmlProps.getProperty("GIF_BUFFER_SIZE")); this.req = new Request(this.xmlProps); this.logger.debug("Finished constructing Request..."); this.recon = new Reconciliator(); this.recon.setRecon(this.xmlProps.getProperty("RECON_DRIVER"), this.xmlProps.getProperty("RECON_PASS"), this.xmlProps.getProperty("RECON_USER"), this.xmlProps.getProperty("RECON_URL")); this.logger.debug("Finished constructing RequestHandler..."); } /** * Implementation of the MessageListener interface, JMS messages are * received through this method. * *@param m Next message on JMS queue */ public void onMessage(Message m) { this.ypError = null; try { this.logger.debug("Getting XML String from new message..."); this.inputXML = this.fileMessageFactory.extractXML((TextMessage) m); this.logger.debug("Got XML String, checkNGet next..." + this.inputXML); if(! this.xmlr.checkNGet(this.xmlProps.getProperty("TEMP_XML_FILE"))){ ypError = this.xmlr.getErrObj(); } else { this.logger.debug("checkNGet done..."); this.SAPOrderID = this.xmlr.getSAPOrderID(); this.requestType = this.xmlr.getRequestType(); this.logger.debug("SAPOrderID got..."); if( !this.req.checkBookAndSize(this.SAPOrderID) ) { this.logger.debug("Book / size invalid..."); this.ypError = this.req.getErrObj(); } else if( !this.req.updateRequestStatus(this.SAPOrderID, this.requestType) ) { this.logger.debug("Request status problem..."); this.ypError = this.req.getErrObj(); } } this.bookCode = this.req.getBookCode(); if(this.ypError != null){ this.ypError.setConfigProperties(this.xmlProps); this.ypError.setSAPOrderNumber(this.xmlr.getSAPOrderNumber()); this.ypError.setSAPOrderLine(this.xmlr.getSAPOrderLine()); this.logger.debug("xmlHeaderParams..." + this.xmlr.getSAPOrderNumber() + "..." + this.xmlr.getSAPOrderLine()); this.ypError.resolveError(); this.recon.reconError((this.xmlr.getSAPOrderNumber() + this.xmlr.getSAPOrderLine()), this.bookCode, this.ypError.getErrorCode()); } else { this.recon.reconAdvert(this.SAPOrderID, this.bookCode, this.requestType); } m.acknowledge(); this.logger.debug("Message acknowledged..."); } catch (Exception ex) { System.err.println("Could not get message: " + ex); ex.printStackTrace(); } } /** * Called by the client runtime when the connection to the server is broken * NB. This feature does not work with JBossMQ V2.4.3 * *@param e JMSException */ public void onException(JMSException e) { System.out.println("Connection lost!"); System.out.println("Exception: " + e.getMessage()); } /** * Closes session and connection. * *@exception JMSException Description of the Exception */ public void close() throws JMSException { this.jmsFactory.cleanup(); } /** * Main procedure for RequestHandler. * *@param args The command line arguments */ public static void main(String[] args) { try { RequestHandler receiver = new RequestHandler(); } catch (Exception ex) { System.err.println("An exception occured while in main RequestHandler: " + ex); ex.printStackTrace(); } } } // RequestHandler [end code] Thanks