7 Replies Latest reply: Mar 17, 2014 8:11 AM by Rosario RSS

    Error While accessing JMS Queue on Weblogic***** ASSERTION FAILED *****[ Environment not found on thread ]

    Sandy_01212

      Hi,

       

      I am trying to read response from JMS Queue hosted on Weblogic server and getting below exception. Any help on this will be appreciable.

       

      1. weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[ Environment not found on thread ]

            at weblogic.jndi.internal.NamingNodeReplicaHandler.<init>(NamingNodeReplicaHandler.java:148)

            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:274)

            at java.lang.Class.newInstance0(Class.java:308)

            at java.lang.Class.newInstance(Class.java:261)

            at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:90)

            at weblogic.common.internal.ChunkedObjectInputStream.readObjectWL(ChunkedObjectInputStream.java:159)

            at weblogic.common.internal.ChunkedObjectInputStream$NestedObjectInputStream.readObjectWL(ChunkedObjectInputStream.java:341)

            at weblogic.rmi.cluster.ReplicaAwareRemoteRef.readExternal(ReplicaAwareRemoteRef.java:356)

            at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1686)

            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1644)

            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)

            at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)

            at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:452)

            at weblogic.rmi.internal.StubInfo.readObject(StubInfo.java:95)

            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:324)

            at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:838)

            at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1746)

            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)

            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)

            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)

            at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:111)

            at weblogic.common.internal.ChunkedObjectInputStream.readObjectWL(ChunkedObjectInputStream.java:159)

            at weblogic.common.internal.ChunkedObjectInputStream$NestedObjectInputStream.readObjectWL(ChunkedObjectInputStream.java:341)

            at weblogic.jndi.internal.WLContextImpl.readExternal(WLContextImpl.java:425)

            at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1686)

            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1644)

            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)

            at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)

            at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)

            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)

            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)

            at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)

            at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)

            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)

            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)

            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)

            at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:111)

            at weblogic.rjvm.ResponseImpl.getThrowable(ResponseImpl.java:117)

            at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:106)

            at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:127)

            at weblogic.jms.dispatcher.DispatcherImpl_1035_WLStub.dispatchSyncNoTranFuture(Unknown Source)

            at weblogic.jms.dispatcher.DispatcherWrapperState.dispatchSyncNoTran(DispatcherWrapperState.java:341)

            at weblogic.jms.client.JMSSession.createDestination(JMSSession.java:1735)

            at weblogic.jms.client.JMSSession.createQueue(JMSSession.java:1296)




      Thanks

        • 1. Re: Error While accessing JMS Queue on Weblogic***** ASSERTION FAILED *****[ Environment not found on thread ]
          Rosario

          Hi,

           

          Can you confirm how you are trying to read from Weblogic Queue? like standalone or mdb etc and its configuration (like setting up context, looking up JNDI)

           

          I am more interested in when you are closing this context? Are you closing the context created before your session completes?

           

          Regards

          Rosario

          • 2. Re: Error While accessing JMS Queue on Weblogic***** ASSERTION FAILED *****[ Environment not found on thread ]
            Sandy_01212

            Hi,

             

            I am trying to read Queue standalone. Please find the code snippet below.  code highlighted in  where i am getting exception.

             

            public static void main(String[] args) {

            String jmsServerUrl = "t3://10.51.245.45:5858";

            String jmsUserName = "weblogic";

            String jmsPassword = "welcome123";

            String jndiFactory = "weblogic.jndi.WLInitialContextFactory";

            String jmsFactory = "jms/CBCMReplyConnectionFactory";

            String qName = "jms/CBCMOrderReplyQueue";

            QueueReceiver qReciever = null;

            JMSQueueReader.getQueueSession(jmsServerUrl,jmsUserName,jmsPassword,jndiFactory,jmsFactory);

             

            qReciever = JMSQueueReader.getQueueReceiver(qName);

            if (qReciever == null) {

            System.out.println("Unable to find JMS Queue Reciever for Queue Name: "

            + qName + " and JMS Server URL:"

            + jmsServerUrl);

             

            //isProcess = false;

            }

            }

             

             

            private static InitialContext getInitialContext(String url, String userName, String password,  String jndiFactory) throws NamingException {

            Hashtable env = new Hashtable();

            env.put(Context.INITIAL_CONTEXT_FACTORY, jndiFactory);

            env.put(Context.PROVIDER_URL, url);

            env.put(Context.SECURITY_PRINCIPAL, userName);

            env.put(Context.SECURITY_CREDENTIALS, password);

            return new InitialContext(env);

            }

             

             

            public static QueueReceiver getQueueReceiver(String qName) {

            try {

            if(qReceiver == null || !qName.equals(queueName))

            {

            queueName = qName;

            if(qReceiver != null)

            {

            qReceiver.close();

            qReceiver = null;

            }

            javax.jms.Queue queue = qSession.createQueue(queueName);

            //qReceiver = qSession.createReceiver(queue);

            qReceiver = qSession.createReceiver(queue, "JMSCorrelationID LIKE '"+SOHConstant.CBCM_BSCS_CORRELATION_ID_PREFIX+"%'");

            }

                        } catch (Throwable e) {

            e.printStackTrace();

            }

            return qReceiver;

            }

            • 4. Re: Error While accessing JMS Queue on Weblogic***** ASSERTION FAILED *****[ Environment not found on thread ]
              Rosario

              Hi,

               

              You haven't provided the complete program.

               

              Not sure, what this code is doing ---> JMSQueueReader.getQueueSession(jmsServerUrl,jmsUserName,jmsPassword,jndiFactory,jmsFactory); 

               

              When qSession is getting initialized? Most probably with above code???

               

              Please find below simplest code to receive message from a queue.

               

              ======================================================

               

              Change ---> JMS_FACTORY

              QUEUE

               

               

               

              import java.util.Hashtable;

              import javax.jms.*;

              import javax.naming.Context;

              import javax.naming.InitialContext;

              import javax.naming.NamingException;

               

               

              /**

              * This example shows how to establish a connection to

              * and receive messages from a JMS queue. The classes in this

              * package operate on the same JMS queue. Run the classes together to

              * witness messages being sent and received, and to browse the queue

              * for messages.  This class is used to receive and remove messages

              * from the queue.

              *

              * @author Copyright (c) 1999,2011, Oracle and/or its affiliates. All Rights Reserved.

              */

              public class QueueReceive implements MessageListener

              {

                // Defines the JNDI context factory.

                public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";

               

               

                // Defines the JMS connection factory for the queue.

                public final static String JMS_FACTORY="ForeignConnectionFactory";

               

               

                // Defines the queue.

                public final static String QUEUE="sampledes";

               

               

                private QueueConnectionFactory qconFactory;

                private QueueConnection qcon;

                private QueueSession qsession;

                private QueueReceiver qreceiver;

                private Queue queue;

                private boolean quit = false;

               

               

              /**

                * Message listener interface.

                * @param msg  message

                */

                public void onMessage(Message msg)

                {

                  try {

                    String msgText;

                    if (msg instanceof TextMessage) {

                      msgText = ((TextMessage)msg).getText();

                    } else {

                      msgText = msg.toString();

                    }

               

               

                    System.out.println("Message Received: "+ msgText );

               

               

                    if (msgText.equalsIgnoreCase("quit")) {

                      synchronized(this) {

                        quit = true;

                        this.notifyAll(); // Notify main thread to quit

                      }

                    }

                  } catch (JMSException jmse) {

                    System.err.println("An exception occurred: "+jmse.getMessage());

                  }

                }

               

               

                /**

                 * Creates all the necessary objects for receiving

                 * messages from a JMS queue.

                 *

                 * @param   ctx JNDI initial context

                 * @param queueName name of queue

                 * @exception NamingException if operation cannot be performed

                 * @exception JMSException if JMS fails to initialize due to internal error

                 */

                public void init(Context ctx, String queueName)

                  throws NamingException, JMSException

                {

                  qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);

                  qcon = qconFactory.createQueueConnection();

                  qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

                  queue = (Queue) ctx.lookup(queueName);

                  qreceiver = qsession.createReceiver(queue);

                  qreceiver.setMessageListener(this);

                  qcon.start();

                }

               

               

                /**

                 * Closes JMS objects.

                 * @exception JMSException if JMS fails to close objects due to internal error

                 */

                public void close()throws JMSException

                {

                  qreceiver.close();

                  qsession.close();

                  qcon.close();

                }

              /**

                * main() method.

                *

                * @param args  WebLogic Server URL

                * @exception  Exception if execution fails

                */

               

               

                public static void main(String[] args) throws Exception {

                  if (args.length != 1) {

                    System.out.println("Usage: java QueueReceive WebLogicURL");

                    return;

                  }

                  InitialContext ic = getInitialContext(args[0]);

                  QueueReceive qr = new QueueReceive();

                  qr.init(ic, QUEUE);

               

               

                  System.out.println("JMS Ready To Receive Messages (To quit, send a \"quit\" message).");

               

               

                  // Wait until a "quit" message has been received.

                  synchronized(qr) {

                    while (! qr.quit) {

                      try {

                        qr.wait();

                      } catch (InterruptedException ie) {}

                    }

                  }

                  qr.close();

                }

               

               

                private static InitialContext getInitialContext(String url)

                  throws NamingException

                {

                  Hashtable<String,String> env = new Hashtable<String,String>();

                  env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);

                  env.put(Context.PROVIDER_URL, url);

                  return new InitialContext(env);

                }

               

               

              }

              • 5. Re: Error While accessing JMS Queue on Weblogic***** ASSERTION FAILED *****[ Environment not found on thread ]
                Sandy_01212

                Hi Rosario,


                Below is the code for getting Queue Session.

                Above code is existing code it is running properly for JMS queues held on TIBCO.


                public static QueueSession getQueueSession(String serverUrl, String userName, String password, String jndiFactory,  String jmsFactory) {

                 

                try {

                if (qSession == null || !serverUrl.equals(serverURL)) {

                serverURL = serverUrl;

                releaseRecourse();

                /*QueueConnectionFactory qFactory = new com.tibco.tibjms.TibjmsQueueConnectionFactory(

                serverUrl);*/

                InitialContext ic = getInitialContext(serverUrl,userName,password,jndiFactory);

                QueueConnectionFactory qFactory = (QueueConnectionFactory)ic.lookup(jmsFactory);

                qConnection = qFactory.createQueueConnection(userName, password);

                qConnection.start(); // Need to implement this

                qSession = qConnection.createQueueSession(false,

                javax.jms.Session.AUTO_ACKNOWLEDGE);

                }

                            } catch (Throwable e) {

                e.printStackTrace();

                }

                return qSession;

                }

                • 6. Re: Error While accessing JMS Queue on Weblogic***** ASSERTION FAILED *****[ Environment not found on thread ]
                  Sandy_01212

                  Hi Rosario,

                   

                  Thanks for the help. I referred to your code and finally was able to resolve the issue.

                  I was facing issue while getting queue object.

                   

                  what i was using is

                  javax.jms.Queue queue = qSession.createQueue(queueName);

                   

                  then i tried with

                   

                  queue = (Queue)ctx.lookup("qName"); and issue is solved with this.

                   

                  Could you please help me understand this. Actually I am new to this technology.

                   

                  Regards,

                  • 7. Re: Error While accessing JMS Queue on Weblogic***** ASSERTION FAILED *****[ Environment not found on thread ]
                    Rosario

                    Hi,

                     

                    I haven't looked at your program completely, but before getting the session, there would be internal context lookup and in your case, the context was not available for the session and thus it had thrown the error.

                     

                    Regards

                    Rosario