openjms Tomcat5

From: ErCipolla_at_yahoo.it (ErCipolla77_at_yahoo.it)
Date: 09/29/04


Date: 29 Sep 2004 10:50:38 -0700

I try to create a jms queue session in a HttpServlet.
And I receive this exception:

javax.jms.JMSException: Failed to createSession
java.rmi.ServerException: RemoteException occured in server thread;
nested exception is: java.rmi.UnmarshalException: error unmarshaling
arguments; nested exception is: java.net.MalformedURLException: no
protocol: Software

The same code works well in a normal java aplication, but not in a
servlet running in Tomcat 5.0.19.

import java.util.HashMap;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;

import org.apache.log4j.Logger;

/**
 *
 */
public class Sender {
        
        private Context context = null;
        private QueueConnection connection = null;
        private QueueSession session = null;
        private QueueSender sender = null;
        private String queueName = null;
        private String broker = "JmsQueueConnectionFactory";
        private Queue queue = null;
        private HashMap messageMap = null;
        private long timeToLive = 500;
        private Logger logger = Logger.getLogger(Sender.class.getName());
        /**
         *
         * @param context
         * @param queueName
         */
        public Sender(Context context, String queueName) {
                try {
                        logger.info("Sender.Sender(): Sender created!");
                        this.queueName = queueName;
                        this.context = context;
                        initialize();
                }
                catch (Exception e) {
                        logger.fatal("Sender.Sender()" + e.toString());
                }
        }
        /**
         * Called to initialize the jms sender.
         * @throws JFOSException
         */
        private void initialize() throws JFOSException {
                  try {
                      logger.info("Sender.initialize(): Initialize sender for queue
" + queueName + " !");
                          //lookup the connection factory from the context
                          QueueConnectionFactory factory = (QueueConnectionFactory)
                                context.lookup(broker);
                          connection = factory.createQueueConnection();
                          
                          //connection.setExceptionListener( new MyExceptionListener() );
                          
                          connection.start();
        
                          try {
                              session = connection.createQueueSession(
                                      false, Session.AUTO_ACKNOWLEDGE);
                            
                          }
                          catch (JMSException jmse){
                              logger.fatal("Sender.initalize()" + jmse.toString());
                              session = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
                          }
                          //connection.start();
                          queue = (Queue) context.lookup(queueName);
                          sender = session.createSender(queue);
                          logger.info("Sender.initialize(): ready, on queue " + queueName +
" !");
                  }
                  catch (JMSException jmse) {
                      logger.fatal("JMSExecption");
                      logger.fatal("Sender.initalize()" + jmse.toString());
                      JFOSException jfosException = new JFOSException( 1,
"Sender.initailize()", jmse.toString(), jmse.getMessage() );
                          throw jfosException;
                  }
                  catch ( Exception e) {
                          logger.fatal("Sender.initalize()" + e.toString());
                          JFOSException jfosException = new JFOSException( 1,
"Sender.initailize()", e.toString(), e.getMessage() );
                          throw jfosException;
                  }
        }
        /**
         * Called to create and send a JMS TextMessage to the destination.
         * @param content
         * @throws JFOSException
         */
        public void sendMessage(String content) throws JFOSException {
            TextMessage message = null;
                try {
                        message = session.createTextMessage();
                        if ( message != null ) {
                            message.setJMSExpiration(timeToLive);
                                message.setText(content);
                                sender.send(message);
                                logger.debug("Sender.sendMessage(): Message sended!");
                        }
                        else
                            logger.error("Sender.sendMessage(): Message not created!");
                }
                catch (Exception e) {
                    logger.fatal("Sender.sendMessage()" + e.toString());
            JFOSException jfosException = new JFOSException( 1,
"Sender.sendMessage()", e.toString(), e.getMessage() );
            throw jfosException;
                }
        }
        /**
         * Called to send a JMS TextMessage to the destination.
         * @param message
         * @throws JFOSException
         */
        public void sendMessage(Message message) throws JFOSException {
            try {
                TextMessage tmsg = null;
                if ( message instanceof TextMessage ) {
                    tmsg = (TextMessage) message;
                    sender.send(message);
                }
            }
            catch (JMSException e) {
                logger.fatal("Sender.sendMessage()" + e.toString());
            JFOSException jfosException = new JFOSException( 1,
"Sender.sendMessage()", e.toString(), e.getMessage() );
            throw jfosException;
            }
        }
        /**
         * Called to close all connection and references.
         */
        public void close() {
                logger.info("Sender.close() : Cose Session and connection");
        try {
          if ( session != null ) {
            session.close();
          }
          if ( connection != null ) {
            connection.close();
          }
        }
        catch ( Exception e ) {
                logger.fatal("Sender.close()");
                          logger.fatal(e.toString());
        }
        finally {
          session = null;
          connection = null;
          logger = null;
        }
        }
    /**
     * Listen to JFOSException
     * @author master
     * Sep 1, 2004
     * Browser.java
     */
    private class MyExceptionListener implements
javax.jms.ExceptionListener {
        public void onException( javax.jms.JMSException e ) {
          System.out.println(e.getMessage());
          int cnt = 0;
          while( true ) {
            try {
              close();
              initialize();
              break;
            }
            catch ( JFOSException e1 ) {
                    logger.fatal("Error :
MyExceptionListener.onException()");
                              logger.fatal(e1.toString());
                          try {
                                  Thread.sleep( 10000 );
                          }
                          catch ( Exception e2 ) {}
            }
          }
        }
    }
}

Thanks for help!
by
robert



Relevant Pages

  • Re: Exception Handling - help!
    ... | to also be in Partition I.12.4.2.5, the overview of Exception Handling. ... | filter block - is this true only for inline code, ... | (which it was not when the exception was thrown). ... | nested exception the new exception would have to walk the stack anyway ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Exception Handling - help!
    ... George did a fine job of demonstrating this aspect of exception ... to also be in Partition I.12.4.2.5, the overview of Exception Handling. ... filter block - is this true only for inline code, ... nested exception the new exception would have to walk the stack anyway from ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Exception Handling - help!
    ... filter, the filter is indeed considered to have returned ... finally/fault will continue executing after the nested exception is caught. ... | when the 2nd exception reaches in the filter of the original exception, ...
    (microsoft.public.dotnet.framework.clr)
  • Re: ClassNotFoundException on Core Java 2 RMI example
    ... javax.naming.CommunicationException [Root exception is ... RemoteException occurred in server thread; ... nested exception is: ...
    (comp.lang.java.programmer)
  • wsadapter error in universal test client
    ... Hi I get an exception when I call the create method of ClubLocalHome ... nested exception is: javax.ejb.EJBException: nested exception is: ... Error connecting to adapter ...
    (comp.lang.java.programmer)