activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From EddieK <Edward.K...@aspect.com>
Subject "Transport not scheme specified" exception trying to initialize JMS
Date Wed, 18 Jun 2008 23:26:24 GMT

I am migrating an application away from JBoss JMS to ActiveMQ, but I am not
having much luck.  The application, migrated away from JBoss, will run under
Tomcat 6 as a webapp.  I have everything functioning except JMS.

So far I have done the following:

Copy the Web App whole from where it lived under JBoss's embedded Tomcat and
move it under a standalone Tomcat webapp directory.  (Plus make necessary
changes for things to work, add JAR files previously pulled from JBoss but
obviously not including JBoss JMS JAR files.)

Copy activemq-all-5.1.0.jar plus geronimo-jms_1.1_spec-1.1.1.jar plus
geronimo-jta_1.0.1B_spec-1.0.1.jar plus
geronimo-j2ee-management_1.0_spec-1.0.jar plus commons logging into my web
applications WEB-INF/lib directory.

Create the following jndi.properties in my web apps WEB-INF/classes
directory:

  java.naming.factory.initial =
org.apache.activemq.jndi.ActiveMQInitialContextFactory
  java.naming.provider.url = vm://localhost
  queue.MyRequest = Test.MyRequest
  topic.MyMessage = Test.MyMessage

And I know this jndi.properties file is being found and parsed because if I
deliberately misname the queue or topic, I get a different and earlier
exception.

My goal is to run the JMS broker within my webapp, thus avoiding an
unnecessary extra process and service to manage.  I am obviously missing
something, but so far in my searching I cannot find what else I need to
configure to get this to work.  The application in question does not use
Spring or XBeans, so I would prefer to avoid these configuration methods. 
Unfortunately, most examples either use the standalone broker or Spring or
XBeans.

I try to initialize JMS with the following class, instantiated via "new
TestJMSSetup()" from my startup servlet, and I get the Exception mentioned
in the subject above.  The code below is simplified from code that works
with JBoss JMS, at least as of JBoss 3.2.7.  The simplified code and the
full code fail with the same exception at the same line --
qcf.createQueueConnection(USER_NAME,PASSWORD).  Note that if I instead call
qcf.createQueueConnection() I get the exact same exception.

Can anyone help identify what is missing here?  Or point me to a web page or
other documentation that spells out how to get an ActiveMQ broker fully
running within Tomcat, making use of the ActiveMQ JNDI for lookup?

Thanks!

      Eddie

My code is below, and the exception I get is below that.

package test;

import java.util.Properties;
import javax.jms.*;
import javax.naming.*;
import org.apache.log4j.Logger;

public class TestJMSSetup {
  protected static final Logger LOG = Logger.getLogger(TestJMSSetup.class);

  public static final String NAMING_CONTEXT_FACTORY =
"org.apache.activemq.jndi.ActiveMQInitialContextFactory";
  public static final String CONNECTION_FACTORY     = "ConnectionFactory";
  public static final String JMS_QUEUE_NAME         = "MyRequest";
  public static final String JMS_TOPIC_NAME         = "MyMessage";
  public static final int    NEVER_EXPIRE           = 0;
  public static final String USER_NAME              = "testuser";
  public static final String PASSWORD               = "testpassword";
  public static final String MESSAGE_LENGTH         = "MsgLen";

  protected final InitialContext         jndi;
  private final JMSTopicServer           jmsTopicServer;
  private final JMSQueueServer           jmsQueueServer;

  public TestJMSSetup() throws Exception {
    try {
      // Initialize JNDI
      LOG.info("setting up JNDI....");
      Properties env = new Properties();
      env.put(Context.INITIAL_CONTEXT_FACTORY, NAMING_CONTEXT_FACTORY);
      env.put(Context.PROVIDER_URL, "localhost");
      jndi = new InitialContext(env);

      // Initialize, then start JMS
      LOG.info("initializing JMS....");
      jmsTopicServer = new JMSTopicServer();
      jmsQueueServer = new JMSQueueServer();

      LOG.info("starting connections...");
      jmsQueueServer.start();
      jmsTopicServer.start();
      LOG.info("started connections");
    } catch (Exception e) {
      LOG.error("TestJMSSetup exception", e);
      throw e;
    }
  }

  /**
   * Handle incoming messages (from our client).
   * @param msg The message to handle
   */
  public void handleMessage(final String msg) {
    try {
      jmsTopicServer.publishMessage(msg);
    } catch (Exception e) {
      LOG.error("handleMessage() Exception", e);
    }
  }

  /**
   * This inner class handles all JMS Topic communication. After we receive
a
   * message from our client, the topic server is used to publish this
   * message to all receivers.
   */
  private class JMSTopicServer {
    private final TopicConnectionFactory  tcf;
    private final Topic                   jmsTopic;

    private volatile TopicConnection      tConnection = null;
    private volatile TopicSession         tSession    = null;
    private volatile TopicPublisher       publisher   = null;

    public JMSTopicServer() throws Exception {
      tcf      = (TopicConnectionFactory)jndi.lookup(CONNECTION_FACTORY);
      jmsTopic = (Topic)jndi.lookup(JMS_TOPIC_NAME);
    }

    protected void start() throws JMSException {
      LOG.info("creating Topic connection .....");
      tConnection = tcf.createTopicConnection(USER_NAME, PASSWORD);
      tSession    = tConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
      publisher   = tSession.createPublisher(jmsTopic);
      publisher.setTimeToLive(NEVER_EXPIRE);
      publisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

      LOG.info("starting Topic connection .....");
      tConnection.start();

      LOG.info("started Topic connection");
    }

    protected void stop() {
      try {
        tConnection.stop();
        tSession.close();
        tConnection.close();
      } catch (Exception e) {
        LOG.error("stop() caught exception", e);
      }
    }

    public void publishMessage(final String message) throws JMSException {
      ObjectMessage bytesMsg = tSession.createObjectMessage();
      bytesMsg.setObject(message);
      publisher.publish(bytesMsg);
    }
  }

  /**
   * This inner class handles all JMS Queue communication. We receive
requests
   * intended for the our client on this Queue and forward them to our
client
   * for processing.
   */
  private class JMSQueueServer {
    private final QueueConnectionFactory qcf;
    private final Queue                  jmsQueue;

    private volatile QueueConnection     qConnection = null;
    private volatile QueueSession        qSession    = null;
    private volatile QueueReceiver       qReceiver   = null;

    public JMSQueueServer() throws Exception {
      qcf      = (QueueConnectionFactory)jndi.lookup(CONNECTION_FACTORY);
      jmsQueue = (Queue)jndi.lookup(JMS_QUEUE_NAME);
    }

    public void start() throws JMSException {
      LOG.info("creating Queue connection .....");
      // NEXT LINE THROWS THE EXCEPTION *****
      qConnection = qcf.createQueueConnection(USER_NAME,PASSWORD);
      qSession    =
qConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
      qReceiver   = qSession.createReceiver(jmsQueue);
      qReceiver.setMessageListener(new JMSQueueListener());

      LOG.info("starting Queue connection .....");
      qConnection.start();

      LOG.info("started Queue connection");
    }

    public void stop() {
      try {
        qConnection.stop();
        qReceiver.close();
        qSession.close();
        qConnection.close();
      } catch (Exception e) {
        LOG.error("Exception caught in stop()", e);
      }
    }

    public class JMSQueueListener implements MessageListener {
      public void onMessage(final Message msg) {
        try {
          BytesMessage bytesMsg = (BytesMessage)msg;
          byte[] queueRequest = new
byte[msg.getIntProperty(MESSAGE_LENGTH)];
          bytesMsg.readBytes(queueRequest);

          String message = new String(queueRequest);
          LOG.info("Take action with the message we received: " + message);
          // CODE WOULD GO HERE
        } catch (Exception e) {
          LOG.error("onMessage() encountered exception: " + e.getMessage(),
e);
        }
      }
    }
  }
}

I get the log messages:

2008-06-18 17:50:13,524 -0500 INFO  [TestJMSSetup] - initializing JMS....
2008-06-18 17:50:13,524 -0500 INFO  [TestJMSSetup] - starting connections...
2008-06-18 17:50:13,524 -0500 INFO  [TestJMSSetup] - creating Queue
connection .....
2008-06-18 17:50:13,540 -0500 ERROR [TestJMSSetup] - TestJMSSetup exception
javax.jms.JMSException: Could not create Transport. Reason:
java.io.IOException: Transport not scheme specified: [localhost]
	at
org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
	at
org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:237)
	at
org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:250)
	at
org.apache.activemq.ActiveMQConnectionFactory.createQueueConnection(ActiveMQConnectionFactory.java:192)
	at test.TestJMSSetup$JMSQueueServer.start(TestJMSSetup.java:148)
	at test.TestJMSSetup.<init>(TestJMSSetup.java:58)
	at test.StartupServlet.init(StartupServlet.java:138)

-- 
View this message in context: http://www.nabble.com/%22Transport-not-scheme-specified%22-exception-trying-to-initialize-JMS-tp17994225p17994225.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message