14 Replies Latest reply: Jun 29, 2012 4:19 AM by 890740 RSS

    Unable to send messag to JMS Queue using Java

    890740
      Hi all,

      I am trying to send a string to the JMS queue using java. I am unable to send the message. It is getting failed at the look up for connection factory. I am using the below code for this purpose.



      public static void messageEnqueue(String payload) throws JMSException,
      NamingException,
      IOException {

      Session session = null;
      MessageProducer publisher = null;
      TextMessage message = null;
      Context context = new InitialContext();
      QueueConnectionFactory connectionFactory =
      (QueueConnectionFactory)context.lookup("*java:comp/env/XAConnectionFactoryJNDIName*");
      Connection connection = connectionFactory.createConnection();
      Queue Queue1 =
      (Queue)context.lookup("*java:comp/env/QueueName*");
      session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
      publisher = session.createProducer(Queue1);

      message = session.createTextMessage(Payload);


      connection.start();
      publisher.send(message);
      connection.stop();
      connection.close();

      }
      }


      kindly help on this.

      Thanks

      Edited by: 887737 on Jun 28, 2012 9:47 PM
        • 1. Re: Unable to send messag to JMS Queue using Java
          EJP
          Define "unable" and "failed".
          • 2. Re: Unable to send messag to JMS Queue using Java
            890740
            Hi EJP ,

            I am trying to call a remote queue. I am doing a javacallout action in OSB and the payload which I want to send to queue is an XML file. I am changing xml to string i.e, serializing and

            sending that to the java method. In the java class I am trying to call a weblogic queue using below code snippet.

            QueueConnectionFactory connectionFactory =
            (QueueConnectionFactory)context.lookup("t3//servername:host/XAConnectionFactoryName");
            Connection connection = connectionFactory.createConnection();
            Queue IvyInboundQueue =
            (Queue)context.lookup("t3//servername:host/XAQueueName");

            When I am trying to do a javacallout in OSB it is unable to execute the code, I am getting some exception related to look up something similar to unable to find the queue.

            Am I doing something wrong in the java code. Kindly help me :( I am totally helpless and this is the first time I am dealing with queue.

            Thanks

            Edited by: 887737 on Jun 22, 2012 7:22 AM
            • 3. Re: Unable to send messag to JMS Queue using Java
              nigeldeakin
              In our first posting you said
              It is getting failed at the look up for connection factory. I am using the below code for this purpose.
              QueueConnectionFactory connectionFactory =
              (QueueConnectionFactory)context.lookup("*java:comp/env/XAConnectionFactoryJNDIName*");
              In your second posting you said:

              >
              QueueConnectionFactory connectionFactory =
              (QueueConnectionFactory)context.lookup("t3//servername:host/XAConnectionFactoryName");
              Connection connection = connectionFactory.createConnection();
              Queue IvyInboundQueue =
              (Queue)context.lookup("t3//servername:host/XAQueueName");

              When I am trying to do a javacallout in OSB it is unable to execute the code, I am getting some exception related to look up something similar to unable to find the queue.
              Please be consistent in your questions.

              But in both cases it looks as you are trying to lookup a connection factory, or a queue, that doesn't exist with the name you supplied. Did you create the connection factory and queue in the WebLogic admin console (or did someone else do it on your behalf?).

              Nigel
              • 4. Re: Unable to send messag to JMS Queue using Java
                EJP
                When I am trying to do a javacallout in OSB it is unable to execute the code. I am getting some exception related to look up something similar to unable to find the queue.
                Here we go again. Define 'unable', 'some exception', 'similar', etc.

                Surely you realize that all these vague statements are no help whatsoever? And that you should be posting the actual exception message and stack trace? Instead of just waffling on about 'unable' and 'fails' and 'some exception' and 'something similar'? After you are asked to define them?
                Am I doing something wrong in the java code.
                Obviously.
                Kindly help me :( I am totally helpless
                We are totally helpless until you answer the questions you are being asked.
                • 5. Re: Unable to send messag to JMS Queue using Java
                  890740
                  Hi nigeldeakin,

                  I am sorry if you got confused by my questions. Let me clear it.

                  In my first question I pasted a java code. That is the one which I am using to push a message into queue. I am using this java class for a java callout actionin OSB. My idea in doing this is to push the input message what ever i send to the proxy service in to the Queue if some some exception occurs in the flow. When I am trying to do this I am getting some ConnectionFactory look up exception.

                  As you have asked connection factory is not set by me. It was done by someone on my behalf. Kindly help me on this.

                  Thanks
                  • 6. Re: Unable to send messag to JMS Queue using Java
                    EJP
                    I am getting some ConnectionFactory look up exception.
                    For the sixth time, what exception?* You've been asked that several times, and you've been told several times that vague statements like this are completely useless.

                    If you can't ask a proper question, the thread will be locked. You are just wasting everybody's time with this.
                    • 7. Re: Unable to send messag to JMS Queue using Java
                      890740
                      Hi EJP,

                      First of all Extremely sorry for not expressing the question properly.
                      Kindly wait for a while don't lock the thread... I will post the complete trace soon. Servers r down so pls gimme some time.

                      Thanks
                      • 8. Re: Unable to send messag to JMS Queue using Java
                        890740
                        Hi EJP,

                        This is the Exception I got when I ran the java class directly from Jdeveloper. Can't I run the standalone class directly from Jdeveloper to insert the message into remote queue?

                        Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
                             at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
                             at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
                             at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
                             at javax.naming.InitialContext.lookup(InitialContext.java:392)
                             at javamail.MessageEnqueue.messageEnqueue(MessageEnqueue.java:30)
                             at javamail.MessageEnqueue.main(MessageEnqueue.java:51)


                        Regards
                        Phanindra.
                        • 9. Re: Unable to send messag to JMS Queue using Java
                          EJP
                          This is not just 'some ConnectionFactory look up exception'. The error message in this case is extremely complete and clear. What part of it don't you understand?
                          • 10. Re: Unable to send messag to JMS Queue using Java
                            nigeldeakin
                            887737 wrote:
                            Hi EJP,

                            This is the Exception I got when I ran the java class directly from Jdeveloper. Can't I run the standalone class directly from Jdeveloper to insert the message into remote queue?

                            Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
                                 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
                                 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
                                 at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
                                 at javax.naming.InitialContext.lookup(InitialContext.java:392)
                                 at javamail.MessageEnqueue.messageEnqueue(MessageEnqueue.java:30)
                                 at javamail.MessageEnqueue.main(MessageEnqueue.java:51)
                            Hmm. The stack trace doesn't involve any JMS code. Is javamail.MessageEnqueue.messageEnqueue your application? It seems to be doing a JNDI lookup, and you haven't configured JNDI properly. Exactly how to do this depends on what JNDI provider you are using. Earlier in the thread you mentioned you were using WebLogic, so the answer may lie in the WebLogic documentation.

                            Nigel
                            • 11. Re: Unable to send messag to JMS Queue using Java
                              890740
                              Hi EJP

                              This is what I didnt understand -- "Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial"

                              Kindly dont get irritated if my questions sound stupid. I am new to this area and don't have enough experience to understand the exceptions in this area. I don't have internet access

                              to most of the sites otherwise I would have first browsed some info regarding this. Kindly help me in calling a queue from a stand alone java class.

                              Thanks
                              • 12. Re: Unable to send messag to JMS Queue using Java
                                EJP
                                You need to browse the JNDI Tutorial.
                                • 13. Re: Unable to send messag to JMS Queue using Java
                                  890740
                                  Thx EJP

                                  Thanks
                                  • 14. Re: Unable to send messag to JMS Queue using Java
                                    890740
                                    thx for the help