6 Replies Latest reply on May 2, 2003 8:44 AM by krishkumar

    my first JMS Bean

    krishkumar Newbie

      I have written my first JMS Bean, I did not have any problem deploying the bean, but, when I try to run it I am getting the following error. Please help


      Got context
      javax.naming.NameNotFoundException: javax.jms.TopicConnectionFactory not bound

      Source CODE:
      ------------------


      package com.DS.JMS;

      import javax.ejb.*;
      import javax.jms.*;

      /**
      * @author bthirnr
      *
      * To change this generated comment edit the template variable "typecomment":
      * Window>Preferences>Java>Templates.
      * To enable and disable the creation of type comments go to
      * Window>Preferences>Java>Code Generation.
      */

      public class JMS_Bean implements MessageDrivenBean, MessageListener {
      protected MessageDrivenContext context = null;

      public void setMessageDrivenContext(MessageDrivenContext ctx) {
      context = ctx;
      }

      public void ejbCreate() {
      System.out.println( "ejbCreate Method Called ");
      }

      public void onMessage(Message msg) {
      if (msg instanceof TextMessage) {
      TextMessage message = (TextMessage) msg;

      try {
      System.out.println("MESSAGE : " + message.getText() );
      }
      catch (JMSException e) {
      e.printStackTrace();
      }
      }
      }

      public void ejbRemove() {
      System.out.println("ejbRemove Method called");
      }
      }



      Client Code
      ---------------


      import javax.naming.*;
      import javax.ejb.*;
      import javax.jms.*;
      import javax.rmi.*;
      import java.util.*;
      import java.sql.*;

      import com.DS.JMS.*;
      //import com.javapro.ejb.*;


      /**
      * @author bthirnr
      *
      * To change this generated comment edit the template variable "typecomment":
      * Window>Preferences>Java>Templates.
      * To enable and disable the creation of type comments go to
      * Window>Preferences>Java>Code Generation.
      */
      public class JMS_Client {

      public static void main (String args[]) {

      // preparing properties for constructing an InitialContext object
      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.PROVIDER_URL, "localhost:1099");

      try {
      // Get an initial context
      InitialContext jndiContext = new InitialContext(properties);
      System.out.println("Got context");

      TopicConnectionFactory factory = (TopicConnectionFactory)jndiContext.lookup("javax.jms.TopicConnectionFactory");
      TopicConnection connection = factory.createTopicConnection();
      TopicSession session = connection.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);
      Topic topic = (Topic)jndiContext.lookup("testtopic");
      TopicPublisher publisher = session.createPublisher(topic);

      TextMessage message = session.createTextMessage();
      message.setText(" THIS IS TEST MESSAGE FROM CLIENT");
      publisher.publish(message);
      }
      catch(Exception e) {
      System.out.println(e.toString());
      }
      }
      }

        • 1. Re: my first JMS Bean
          Adrian Brock Master

          lookup("ConnectionFactory")

          Regards,
          Adrian

          • 2. Re: my first JMS Bean
            Adrian Brock Master

            Before you ask
            lookup("topic/testtopic");

            Regards,
            Adrian

            • 3. Re: my first JMS Bean
              krishkumar Newbie

              Thanks for the reply,

              I am not getting
              javax.naming.NameNotFoundException: javax.jms.TopicConnectionFactory not bound
              error any more

              but it complaints about
              javax.naming.NameNotFoundException: testtopic not bound

              I do lookup
              lookup("topic/testtopic");

              • 4. Re: my first JMS Bean
                krishkumar Newbie

                I am getting an
                OILSerivceIL Connection failure,


                -Balaji

                • 5. Re: my first JMS Bean
                  Adrian Brock Master

                  Did you create testtopic?

                  There is one called testTopic.

                  Post the full stacktrace for the other error.

                  Regards,
                  Adrian

                  • 6. Re: my first JMS Bean
                    krishkumar Newbie

                    This is the stack trace I am getting on the server (JBoss) side. I have attached the client code also for your reference.

                    java.net.SocketException: Connection reset by peer: JVM_recv in socket input str
                    eam read
                    at java.net.SocketInputStream.socketRead(Native Method)
                    at java.net.SocketInputStream.read(SocketInputStream.java:85)
                    at java.io.BufferedInputStream.fill(BufferedInputStream.java:181)
                    at java.io.BufferedInputStream.read(BufferedInputStream.java:199)
                    at java.io.ObjectInputStream.peekCode(ObjectInputStream.java:1545)
                    at java.io.ObjectInputStream.refill(ObjectInputStream.java:1679)
                    at java.io.ObjectInputStream.read(ObjectInputStream.java:1655)
                    at java.io.ObjectInputStream.readByte(ObjectInputStream.java:1901)
                    at org.jboss.mq.il.oil.OILServerILService$Client.run(OILServerILService.
                    java:205)
                    at java.lang.Thread.run(Thread.java:479)


                    Client Code
                    ---------------



                    public class JMS_Client {

                    public static void main (String args[]) {

                    // preparing properties for constructing an InitialContext object
                    Properties properties = new Properties();
                    properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                    properties.put(Context.PROVIDER_URL, "localhost:1099");

                    try {
                    // Get an initial context
                    InitialContext jndiContext = new InitialContext(properties);
                    System.out.println("Got context");

                    TopicConnectionFactory factory = (TopicConnectionFactory)jndiContext.lookup("ConnectionFactory");
                    //TopicConnectionFactory factory = (TopicConnectionFactory)jndiContext.lookup("TopicConnectionFactory");
                    TopicConnection connection = factory.createTopicConnection();
                    System.out.println("Created a Topic connection ");
                    TopicSession session = connection.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);
                    Topic topic = (Topic)jndiContext.lookup("topic/testTopic");
                    TopicPublisher publisher = session.createPublisher(topic);

                    TextMessage message = session.createTextMessage();
                    message.setText(" THIS IS TEST MESSAGE FROM CLIENT");
                    publisher.publish(message);
                    }
                    catch(Exception e) {
                    System.out.println(e.toString());
                    }
                    }
                    }