2 Replies Latest reply: Feb 7, 2011 4:27 PM by 837659 RSS

    Forward a message to remote server in message driven bean

    833497
      Hi everybody.
      I try to forward a message in the onMessage-method of a message driven bean to a topic on a remote server. I use GlassFish. But I still get an exception (see below).

      It seems like the SerialInitContextFactory can't be found. But I have the same libraries included as I'm sending a message from a client.
      I tried to copy required libraries in glassfish / domain / domain1/lib folder and subfolder. But this doesn't work.
      How can I make it work?


      My MDB looks like this:


      @MessageDriven(mappedName = "jms/ServerTopic", activationConfig = {
      @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
      @ActivationConfigProperty(propertyName = "ConnectionFactoryName", propertyValue = "jms/ServerTConnectionFactory")
      })
      public class HalloMDB implements MessageListener {

      private String URL = "148.92.221.32";
      private Topic topic;
      private TopicPublisher publisher;
      private TopicSession topicSession;
      private TopicConnection topicConnection;

      public HalloMDB() {
      try {
      init();
      } catch (JMSException ex) {
      Logger.getLogger(HalloMDB.class.getName()).log(Level.SEVERE, null, ex);
      } catch (NamingException ex) {
      Logger.getLogger(HalloMDB.class.getName()).log(Level.SEVERE, null, ex);
      }
      }

      public void onMessage(Message message) {
      try {
      TextMessage m = (TextMessage) message;
      send(m);
      close();
      System.out.println("Incoming message: " + ((TextMessage) message).getText());
      } catch (JMSException ex) {
      Logger.getLogger(HalloMDB.class.getName()).log(Level.SEVERE, null, ex);
      }
      }

      private void init() throws JMSException, NamingException {
      System.out.println(this.getClass().getResource("").getPath());
      // SerialInitContextFactory cf= new SerialInitContextFactory();


      Properties env = new Properties();
      env.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
      env.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
      env.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
      env.setProperty("org.omg.CORBA.ORBInitialHost", URL);
      env.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

      InitialContext ctx = new InitialContext(env);
      TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) ctx.lookup("jms/ServerTConnectionFactory");
      topic = (Topic) ctx.lookup("jms/ServerTopic");
      topicConnection = topicConnectionFactory.createTopicConnection();
      topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      topicConnection.start();
      publisher = topicSession.createPublisher(topic);
      }

      public void send(TextMessage message) throws JMSException {
      publisher.publish(message);
      }

      public void close() throws JMSException {
      topicSession.close();
      topicConnection.stop();
      topicConnection.close();
      }
      }




      WARNUNG: Failed to load com.sun.enterprise.naming.SerialInitContextFactory using CommonClassLoader
      SCHWERWIEGEND: The log message is null.
      javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
      at com.sun.enterprise.naming.GlassFishNamingBuilder.createInitialContextFactory(GlassFishNamingBuilder.java:100)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:664)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
      at javax.naming.InitialContext.init(InitialContext.java:223)
      at javax.naming.InitialContext.<init>(InitialContext.java:197)
      at mdb.HalloMDB.init(HalloMDB.java:89)
      at mdb.HalloMDB.<init>(HalloMDB.java:47)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
      at java.lang.Class.newInstance0(Class.java:355)
      at java.lang.Class.newInstance(Class.java:308)
      at com.sun.ejb.containers.BaseContainer._constructEJBInstance(BaseContainer.java:1640)
      at com.sun.ejb.containers.BaseContainer.createEjbInstanceAndContext(BaseContainer.java:1623)
      at com.sun.ejb.containers.MessageBeanContainer.createMessageDrivenEJB(MessageBeanContainer.java:679)
      at com.sun.ejb.containers.MessageBeanContainer.access$100(MessageBeanContainer.java:95)
      at com.sun.ejb.containers.MessageBeanContainer$MessageBeanContextFactory.create(MessageBeanContainer.java:478)
      at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:200)
      at com.sun.ejb.containers.MessageBeanContainer._getContext(MessageBeanContainer.java:542)
      at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2467)
      at com.sun.ejb.containers.MessageBeanContainer.beforeMessageDelivery(MessageBeanContainer.java:982)
      at com.sun.ejb.containers.MessageBeanListenerImpl.beforeMessageDelivery(MessageBeanListenerImpl.java:72)
      at com.sun.enterprise.connectors.inbound.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:134)
      at $Proxy122.beforeDelivery(Unknown Source)
      at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:245)
      at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:92)
      at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:492)
      at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)
      Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:247)
      at com.sun.enterprise.naming.GlassFishNamingBuilder.loadClass(GlassFishNamingBuilder.java:130)
      at com.sun.enterprise.naming.GlassFishNamingBuilder.createInitialContextFactory(GlassFishNamingBuilder.java:96)
      ... 28 more

      SCHWERWIEGEND: MQRA:OMR:run:Caught Exception from onMessage():Redelivering:message-driven bean method public abstract void javax.jms.MessageListener.onMessage(javax.jms.Message) system exception
      WARNUNG: MDB00037: [MDB:HalloMDB]: Message-driven bean invocation exception: [javax.ejb.EJBException]
      WARNUNG: javax.ejb.EJBException
      javax.ejb.EJBException
      at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
      at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5017)
      at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4805)
      at com.sun.ejb.containers.MessageBeanContainer.afterMessageDeliveryInternal(MessageBeanContainer.java:1200)
      at com.sun.ejb.containers.MessageBeanContainer.afterMessageDelivery(MessageBeanContainer.java:1173)
      at com.sun.ejb.containers.MessageBeanListenerImpl.afterMessageDelivery(MessageBeanListenerImpl.java:81)
      at com.sun.enterprise.connectors.inbound.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:138)
      at $Proxy122.afterDelivery(Unknown Source)
      at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:324)
      at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:92)
      at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:492)
      at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)
      Caused by: java.lang.NullPointerException
      at mdb.HalloMDB.send(HalloMDB.java:99)
      at mdb.HalloMDB.onMessage(HalloMDB.java:66)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1056)
      at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1128)
      at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:4087)
      at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5272)
      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5252)
      at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1086)
      at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:76)
      at com.sun.enterprise.connectors.inbound.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:166)
      at $Proxy122.onMessage(Unknown Source)
      at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
      ... 3 more

      INFO: C:\glassfish_v3\glassfish\domains\domain1
      INFO: C:\glassfish_v3\glassfish\domains\domain1\abc
      INFO: /D:/STUDIUM/MASTER/WORKSPACE/Java/MESY/MDB/build/classes/mdb/
      WARNUNG: Failed to load com.sun.enterprise.naming.SerialInitContextFactory using CommonClassLoader
      SCHWERWIEGEND: The log message is null.
      javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
      at com.sun.enterprise.naming.GlassFishNamingBuilder.createInitialContextFactory(GlassFishNamingBuilder.java:100)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:664)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
      at javax.naming.InitialContext.init(InitialContext.java:223)
      at javax.naming.InitialContext.<init>(InitialContext.java:197)
      at mdb.HalloMDB.init(HalloMDB.java:89)
      at mdb.HalloMDB.<init>(HalloMDB.java:47)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
      at java.lang.Class.newInstance0(Class.java:355)
      at java.lang.Class.newInstance(Class.java:308)
      at com.sun.ejb.containers.BaseContainer._constructEJBInstance(BaseContainer.java:1640)
      at com.sun.ejb.containers.BaseContainer.createEjbInstanceAndContext(BaseContainer.java:1623)
      at com.sun.ejb.containers.MessageBeanContainer.createMessageDrivenEJB(MessageBeanContainer.java:679)
      at com.sun.ejb.containers.MessageBeanContainer.access$100(MessageBeanContainer.java:95)
      at com.sun.ejb.containers.MessageBeanContainer$MessageBeanContextFactory.create(MessageBeanContainer.java:478)
      at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:200)
      at com.sun.ejb.containers.MessageBeanContainer._getContext(MessageBeanContainer.java:542)
      at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2467)
      at com.sun.ejb.containers.MessageBeanContainer.beforeMessageDelivery(MessageBeanContainer.java:982)
      at com.sun.ejb.containers.MessageBeanListenerImpl.beforeMessageDelivery(MessageBeanListenerImpl.java:72)
      at com.sun.enterprise.connectors.inbound.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:134)
      at $Proxy122.beforeDelivery(Unknown Source)
      at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:245)
      at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:92)
      at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:492)
      at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)
      Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:247)
      at com.sun.enterprise.naming.GlassFishNamingBuilder.loadClass(GlassFishNamingBuilder.java:130)
      at com.sun.enterprise.naming.GlassFishNamingBuilder.createInitialContextFactory(GlassFishNamingBuilder.java:96)
      ... 28 more

      SCHWERWIEGEND: MQRA:OMR:run:Caught Exception from onMessage():Redelivering:message-driven bean method public abstract void javax.jms.MessageListener.onMessage(javax.jms.Message) system exception
      SCHWERWIEGEND: MQRA:OMR:run:Exhausted redeliveryAttempts-msg=com.sun.messaging.jms.ra.DirectTextPacket@1729275
      SCHWERWIEGEND: MQRA:OMR:run:Exhausted redeliveryAttempts-spec=ActvationSpec configuration=
      DestinationType =javax.jms.Topic
      Destination =physTopic01
      MessageSelector =null
      AcknowledgeMode =Auto-acknowledge
      SubscriptionDurability =NonDurable
      useSharedSubscriptionInClusteredContainer=true
      ClientId =null
      SubscriptionName =null
      EndpointPoolMaxSize =32
      EndpointPoolSteadySize =0
      EndpointPoolResizeCount =8
      EndpointPoolResizeTimeout =600
      EndpointExceptionRedeliveryAttempts =1
      EndpointExceptionRedeliveryInterval =500
      SendUndeliverableMsgsToDMQ =true
      GroupName =null
      RAUID =null
      InClusteredContainer =false
      MdbName =null
      UserName =null
      EnableRADirect =true
      EnableAPIDirect =false
      AddressList (in effect) =localhost:7676,localhost
      options =null

      SCHWERWIEGEND: MQRA:OMR:run:Message returned & marked for routing to the DMQ
      SCHWERWIEGEND: MQRA:OMR:run:omrId=0:Acked Undeliverable-Msg=com.sun.messaging.jms.ra.DirectTextPacket@1729275
      WARNUNG: MDB00037: [MDB:HalloMDB]: Message-driven bean invocation exception: [javax.ejb.EJBException]
      WARNUNG: javax.ejb.EJBException
      javax.ejb.EJBException
      at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
      at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5017)
      at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4805)
      at com.sun.ejb.containers.MessageBeanContainer.afterMessageDeliveryInternal(MessageBeanContainer.java:1200)
      at com.sun.ejb.containers.MessageBeanContainer.afterMessageDelivery(MessageBeanContainer.java:1173)
      at com.sun.ejb.containers.MessageBeanListenerImpl.afterMessageDelivery(MessageBeanListenerImpl.java:81)
      at com.sun.enterprise.connectors.inbound.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:138)
      at $Proxy122.afterDelivery(Unknown Source)
      at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:324)
      at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:92)
      at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:492)
      at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)
      Caused by: java.lang.NullPointerException
      at mdb.HalloMDB.send(HalloMDB.java:99)
      at mdb.HalloMDB.onMessage(HalloMDB.java:66)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1056)
      at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1128)
      at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:4087)
      at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5272)
      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5252)
      at com.sun.ejb.containers.MessageBeanContainer.deliverMessage(MessageBeanContainer.java:1086)
      at com.sun.ejb.containers.MessageBeanListenerImpl.deliverMessage(MessageBeanListenerImpl.java:76)
      at com.sun.enterprise.connectors.inbound.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:166)
      at $Proxy122.onMessage(Unknown Source)
      at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:258)
      ... 3 more

      Edited by: user13837924 on 01.02.2011 12:51

      Edited by: user13837924 on 01.02.2011 12:53

      Edited by: user13837924 on 01.02.2011 12:54