0 Replies Latest reply on Jan 27, 2014 9:30 AM by nick ni

    ActiveMq in remote client use Context error

    nick ni Newbie

      soft:activemq 5.9,jboss-7.1.1.Final,eclipse-4.34

       

      Server Singleton

      package com.nick.test;
      
      
      import javax.ejb.Singleton;
      
      
      /**
       * Session Bean implementation class HelloHello
       */
      @Singleton
      public class HelloHello implements HelloHelloRemote {
          public HelloHello() {
              
          }
      
      
        @Override
        public String returnHello(String userName) {
        if(userName != null){
        return "Hello "+userName;
        }else{
        return "no";
        }
        }
      
      
      }
      

       

      interface

      package com.nick.test;
      
      
      import javax.ejb.Remote;
      
      
      @Remote
      public interface HelloHelloRemote {
        public String returnHello(String userName);
      }
      

       

       

      client

       

       

      package com.test.client;

       

       

      import java.util.Properties;

      import java.util.logging.Level;

      import java.util.logging.Logger;

       

       

      import javax.jms.Connection;

      import javax.jms.JMSException;

      import javax.jms.Message;

      import javax.jms.MessageConsumer;

      import javax.jms.MessageListener;

      import javax.jms.ObjectMessage;

      import javax.jms.Session;

      import javax.jms.Topic;

      import javax.naming.Context;

      import javax.naming.InitialContext;

      import javax.naming.NamingException;

       

       

      import org.apache.activemq.ActiveMQConnectionFactory;

       

       

       

       

       

       

       

       

      import com.nick.test.HelloHelloRemote;

       

       

       

       

      public class SayHello implements Runnable,MessageListener {

        Context ctx =null;

        HelloHelloRemote helloEjb;

        private Connection connection;

        private Session session;

        private Topic topic;

        String name = "nick";

       

        public SayHello(){

        Properties props = new Properties();

        props.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");

        props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");

        props.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");

        props.put(Context.SECURITY_PRINCIPAL, "nick");

        props.put(Context.SECURITY_CREDENTIALS, "123456");

        props.put("jboss.naming.client.ejb.context", true);

        try {

        ctx = new InitialContext(props);

        helloEjb = (HelloHelloRemote) ctx.lookup("ejb:JBossTestDeploy/JbossTestEjb/HelloHello!com.nick.test.HelloHelloRemote");

        System.out.println(helloEjb.returnHello("nick"));

        } catch (NamingException e) {

                 Logger.getLogger(SayHello.class.getName()).log(Level.SEVERE, null, e);

        }

        initActiveMq();

        }

        private void initActiveMq() {

        String url = "tcp://localhost:61616";

        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);

        int errorCount = 0;

        while (errorCount++ < 10) {

        try {

        connection = factory.createConnection();

       

       

        session = connection.createSession(false,

        Session.AUTO_ACKNOWLEDGE);

       

        topic = session.createTopic("test");

       

       

       

        MessageConsumer consumer = session.createConsumer(topic);

        consumer.setMessageListener(this);

       

       

        connection.start();

        break;

        } catch (JMSException ex) {

          Logger.getLogger(SayHello.class.getName()).log(Level.SEVERE, null, ex);

        continue;

        }

        }

       

       

        }

       

       

       

        public static void main(String[] args) {

        // TODO Auto-generated method stub

       

        SayHello hello = new SayHello();

        new Thread(hello).run();

        }

       

       

       

       

       

       

        @Override

        public void run() {

       

        try {

        System.out.println(helloEjb.returnHello("nick"));

        } catch (Exception e) {

          Logger.getLogger(SayHello.class.getName()).log(Level.SEVERE, null, e);

        }

       

        }

       

       

       

       

       

       

        @Override

        public void onMessage(Message arg0) {

        ObjectMessage msg = (ObjectMessage)arg0;

        try {

        name = msg.getStringProperty("name");

        System.out.println(helloEjb.returnHello(name));

        } catch (Exception e) {

          Logger.getLogger(SayHello.class.getName()).log(Level.SEVERE, null, e);

        }

       

        Properties props = new Properties();

        props.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");

        props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");

        props.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");

        props.put(Context.SECURITY_PRINCIPAL, "nick");

        props.put(Context.SECURITY_CREDENTIALS, "123456");

        props.put("jboss.naming.client.ejb.context", true);

        try {

        Context ctx2 = new InitialContext(props);

        HelloHelloRemote helloEjb2 = (HelloHelloRemote) ctx2.lookup("ejb:JBossTestDeploy/JbossTestEjb/HelloHello!com.nick.test.HelloHelloRemote");

        System.out.println(helloEjb.returnHello(name));

        } catch (Exception e) {

          Logger.getLogger(SayHello.class.getName()).log(Level.SEVERE, null, e);

        }

        }

       

       

      }

       

       

      run is success,But JMS

        ObjectMessage msg = (ObjectMessage)arg0;

        try {

        name = msg.getStringProperty("name");

        System.out.println(helloEjb.returnHello(name));

        } catch (Exception e) {

          Logger.getLogger(SayHello.class.getName()).log(Level.SEVERE, null, e);

        }

      is run And sendJMS message to this

      error message:

       

       

      console:

      Hello nick
      Hello nick
       com.test.client.SayHello onMessage
      SEVERE: null
      java.lang.IllegalStateException: No EJB receiver available for handling [appName:JBossTestDeploy,modulename:JbossTestEjb,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@183a37d9
        at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
        at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
        at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
        at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
        at com.sun.proxy.$Proxy0.returnHello(Unknown Source)
        at com.test.client.SayHello.onMessage(SayHello.java:123)
        at org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:1361)
        at org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:131)
        at org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:202)
        at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:129)
        at org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:47)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
      
      
      Hello jboss
      

       

      TO CREATE NEW CONTEXT IS OK. GlassFish is no problem , is this jboss features or bug?