5 Replies Latest reply on Dec 13, 2005 7:14 AM by Terry Paterson

    SocketException

    Huai-Shih Wen Newbie

      Hi,
      I have a stand alone MDB client that sends message to the defaule queue/A and a MDB that read the message from queue/A and display on the screen using System.out. I keep getting the Socket closed exception. Where do I go wrong? Thanks.

      JBoss Version: 3.2.5

      from the log:
      2004-08-14 14:17:49,375 DEBUG [org.jboss.mq.il.uil2.SocketManager] Begin ReadTask.run
      2004-08-14 14:17:49,375 DEBUG [org.jboss.mq.il.uil2.SocketManager] Begin WriteTask.run
      2004-08-14 14:17:49,375 DEBUG [org.jboss.mq.il.uil2.SocketManager] Created ObjectOutputStream
      2004-08-14 14:17:49,453 DEBUG [org.jboss.mq.il.uil2.SocketManager] Created ObjectInputStream
      2004-08-14 14:17:49,500 DEBUG [org.jboss.mq.il.uil2.ServerSocketManagerHandler] Setting up the UILClientIL Connection
      2004-08-14 14:17:49,500 DEBUG [org.jboss.mq.il.uil2.ServerSocketManagerHandler] The UILClientIL Connection is set up
      2004-08-14 14:18:28,078 DEBUG [org.jboss.mq.il.uil2.SocketManager] End WriteTask.run
      2004-08-14 14:18:28,078 DEBUG [org.jboss.mq.il.uil2.ServerSocketManagerHandler] Exiting on IOE
      java.net.SocketException: socket closed
      at java.net.SocketInputStream.socketRead0(Native Method)
      at java.net.SocketInputStream.read(SocketInputStream.java:129)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
      at org.jboss.util.stream.NotifyingBufferedInputStream.read(NotifyingBufferedInputStream.java:67)
      at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2133)
      at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(ObjectInputStream.java:2313)
      at java.io.ObjectInputStream$BlockDataInputStream.refill(ObjectInputStream.java:2380)
      at java.io.ObjectInputStream$BlockDataInputStream.read(ObjectInputStream.java:2452)
      at java.io.ObjectInputStream$BlockDataInputStream.readByte(ObjectInputStream.java:2601)
      at java.io.ObjectInputStream.readByte(ObjectInputStream.java:845)
      at org.jboss.mq.il.uil2.SocketManager$ReadTask.run(SocketManager.java:279)
      at java.lang.Thread.run(Thread.java:534)
      2004-08-14 14:18:28,078 DEBUG [org.jboss.mq.il.uil2.SocketManager] End ReadTask.run

      My MDB class

      public class SimpleMessageBean implements MessageDrivenBean,
      MessageListener {

      private transient MessageDrivenContext mdc = null;
      private Context context;

      public SimpleMessageBean() {
      System.out.println("In SimpleMessageBean.SimpleMessageBean()");
      }

      public void setMessageDrivenContext(MessageDrivenContext mdc) {
      System.out.println("In "
      + "SimpleMessageBean.setMessageDrivenContext()");
      this.mdc = mdc;
      }

      public void ejbCreate() {
      System.out.println("In SimpleMessageBean.ejbCreate()");
      }

      public void onMessage(Message inMessage) {
      TextMessage msg = null;

      try {
      if (inMessage instanceof TextMessage) {
      msg = (TextMessage) inMessage;
      System.out.println("MESSAGE BEAN: Message received: "
      + msg.getText());
      } else {
      System.out.println("Message of wrong type: "
      + inMessage.getClass().getName());
      }
      } catch (JMSException e) {
      e.printStackTrace();
      mdc.setRollbackOnly();
      } catch (Throwable te) {
      te.printStackTrace();
      }
      } // onMessage

      public void ejbRemove() {
      System.out.println("In SimpleMessageBean.remove()");
      }

      } // class

      ejb-jar.xml
      <ejb-jar>
      <enterprise-beans>
      <message-driven>
      <ejb-name>SimpleMessageBean</ejb-name>
      <ejb-class>com.hp.mdb.SimpleMessageBean</ejb-class>
      <transaction-type>Container</transaction-type>
      <message-driven-destination>
      <destination-type>javax.jms.Queue</destination-type>
      </message-driven-destination>
      <!--resource-ref>
      <res-ref-name>jms/QCF</res-ref-name>
      <res-type>javax.jms.QueueConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref-->
      </message-driven>
      </enterprise-beans>
      </ejb-jar>

      jboss.xml


      <enterprise-beans>
      <message-driven>
      <ejb-name>SimpleMessageBean</ejb-name>
      <destination-jndi-name>queue/A</destination-jndi-name>
      <!--resource-ref>
      <res-ref-name>jms/QCF</res-ref-name>
      <resource-name>ConnectionFactory</resource-name>
      </resource-ref-->
      </message-driven>
      </enterprise-beans>


      My client class

      public class SimpleMessageClient {

      public static void main(String[] args) {

      Context jndiContext = null;
      QueueConnectionFactory queueConnectionFactory = null;
      QueueConnection queueConnection = null;
      QueueSession queueSession = null;
      Queue queue = null;
      QueueSender queueSender = null;
      TextMessage message = null;
      final int NUM_MSGS = 3;

      try {
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL, "localhost:1099");
      jndiContext = new InitialContext(env);
      } catch (NamingException e) {
      System.out.println("Could not create JNDI " +
      "context: " + e.toString());
      System.exit(1);
      }

      try {
      // queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("java:comp/env/jms/QCF");
      queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("UILConnectionFactory");
      queue = (Queue) jndiContext.lookup("queue/A");
      } catch (NamingException e) {
      System.out.println("JNDI lookup failed: " +
      e.toString());
      System.exit(1);
      }

      try {
      queueConnection =
      queueConnectionFactory.createQueueConnection();
      queueSession =
      queueConnection.createQueueSession(false,
      Session.AUTO_ACKNOWLEDGE);
      queueSender = queueSession.createSender(queue);
      message = queueSession.createTextMessage();

      for (int i = 0; i < NUM_MSGS; i++) {
      message.setText("This is message #" + (i + 1));
      System.out.println("Sending message: " +
      message.getText());
      queueSender.send(message);
      }

      } catch (JMSException e) {
      System.out.println("Exception occurred: " + e.toString());
      } finally {
      if (queueConnection != null) {
      try {
      queueConnection.close();
      } catch (JMSException e) {}
      } // if
      System.exit(0);
      } // finally
      } // main
      } // class

        • 1. Re: SocketException
          Adam Rice Newbie

          I am experiencing the exact same behavior. Did you figure out what was wrong? My first thought was that the queue connection was not closed, but explicitly calling queueConnection.close() did not make a difference.

          Any thoughts?

          Thanks,
          Adam Rice

          "hswen" wrote:
          Hi,
          I have a stand alone MDB client that sends message to the defaule queue/A and a MDB that read the message from queue/A and display on the screen using System.out. I keep getting the Socket closed exception. Where do I go wrong? Thanks.

          JBoss Version: 3.2.5

          from the log:
          2004-08-14 14:17:49,375 DEBUG [org.jboss.mq.il.uil2.SocketManager] Begin ReadTask.run
          2004-08-14 14:17:49,375 DEBUG [org.jboss.mq.il.uil2.SocketManager] Begin WriteTask.run
          2004-08-14 14:17:49,375 DEBUG [org.jboss.mq.il.uil2.SocketManager] Created ObjectOutputStream
          2004-08-14 14:17:49,453 DEBUG [org.jboss.mq.il.uil2.SocketManager] Created ObjectInputStream
          2004-08-14 14:17:49,500 DEBUG [org.jboss.mq.il.uil2.ServerSocketManagerHandler] Setting up the UILClientIL Connection
          2004-08-14 14:17:49,500 DEBUG [org.jboss.mq.il.uil2.ServerSocketManagerHandler] The UILClientIL Connection is set up
          2004-08-14 14:18:28,078 DEBUG [org.jboss.mq.il.uil2.SocketManager] End WriteTask.run
          2004-08-14 14:18:28,078 DEBUG [org.jboss.mq.il.uil2.ServerSocketManagerHandler] Exiting on IOE
          java.net.SocketException: socket closed
          at java.net.SocketInputStream.socketRead0(Native Method)
          at java.net.SocketInputStream.read(SocketInputStream.java:129)
          at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
          at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
          at org.jboss.util.stream.NotifyingBufferedInputStream.read(NotifyingBufferedInputStream.java:67)
          at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2133)
          at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(ObjectInputStream.java:2313)
          at java.io.ObjectInputStream$BlockDataInputStream.refill(ObjectInputStream.java:2380)
          at java.io.ObjectInputStream$BlockDataInputStream.read(ObjectInputStream.java:2452)
          at java.io.ObjectInputStream$BlockDataInputStream.readByte(ObjectInputStream.java:2601)
          at java.io.ObjectInputStream.readByte(ObjectInputStream.java:845)
          at org.jboss.mq.il.uil2.SocketManager$ReadTask.run(SocketManager.java:279)
          at java.lang.Thread.run(Thread.java:534)
          2004-08-14 14:18:28,078 DEBUG [org.jboss.mq.il.uil2.SocketManager] End ReadTask.run

          My MDB class

          public class SimpleMessageBean implements MessageDrivenBean,
          MessageListener {

          private transient MessageDrivenContext mdc = null;
          private Context context;

          public SimpleMessageBean() {
          System.out.println("In SimpleMessageBean.SimpleMessageBean()");
          }

          public void setMessageDrivenContext(MessageDrivenContext mdc) {
          System.out.println("In "
          + "SimpleMessageBean.setMessageDrivenContext()");
          this.mdc = mdc;
          }

          public void ejbCreate() {
          System.out.println("In SimpleMessageBean.ejbCreate()");
          }

          public void onMessage(Message inMessage) {
          TextMessage msg = null;

          try {
          if (inMessage instanceof TextMessage) {
          msg = (TextMessage) inMessage;
          System.out.println("MESSAGE BEAN: Message received: "
          + msg.getText());
          } else {
          System.out.println("Message of wrong type: "
          + inMessage.getClass().getName());
          }
          } catch (JMSException e) {
          e.printStackTrace();
          mdc.setRollbackOnly();
          } catch (Throwable te) {
          te.printStackTrace();
          }
          } // onMessage

          public void ejbRemove() {
          System.out.println("In SimpleMessageBean.remove()");
          }

          } // class

          ejb-jar.xml
          <ejb-jar>
          <enterprise-beans>
          <message-driven>
          <ejb-name>SimpleMessageBean</ejb-name>
          <ejb-class>com.hp.mdb.SimpleMessageBean</ejb-class>
          <transaction-type>Container</transaction-type>
          <message-driven-destination>
          <destination-type>javax.jms.Queue</destination-type>
          </message-driven-destination>
          <!--resource-ref>
          <res-ref-name>jms/QCF</res-ref-name>
          <res-type>javax.jms.QueueConnectionFactory</res-type>
          <res-auth>Container</res-auth>
          </resource-ref-->
          </message-driven>
          </enterprise-beans>
          </ejb-jar>

          jboss.xml

          <jboss>
          <enterprise-beans>
          <message-driven>
          <ejb-name>SimpleMessageBean</ejb-name>
          <destination-jndi-name>queue/A</destination-jndi-name>
          <!--resource-ref>
          <res-ref-name>jms/QCF</res-ref-name>
          <resource-name>ConnectionFactory</resource-name>
          </resource-ref-->
          </message-driven>
          </enterprise-beans>
          </jboss>

          My client class

          public class SimpleMessageClient {

          public static void main(String[] args) {

          Context jndiContext = null;
          QueueConnectionFactory queueConnectionFactory = null;
          QueueConnection queueConnection = null;
          QueueSession queueSession = null;
          Queue queue = null;
          QueueSender queueSender = null;
          TextMessage message = null;
          final int NUM_MSGS = 3;

          try {
          Hashtable env = new Hashtable();
          env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          env.put(Context.PROVIDER_URL, "localhost:1099");
          jndiContext = new InitialContext(env);
          } catch (NamingException e) {
          System.out.println("Could not create JNDI " +
          "context: " + e.toString());
          System.exit(1);
          }

          try {
          // queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("java:comp/env/jms/QCF");
          queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("UILConnectionFactory");
          queue = (Queue) jndiContext.lookup("queue/A");
          } catch (NamingException e) {
          System.out.println("JNDI lookup failed: " +
          e.toString());
          System.exit(1);
          }

          try {
          queueConnection =
          queueConnectionFactory.createQueueConnection();
          queueSession =
          queueConnection.createQueueSession(false,
          Session.AUTO_ACKNOWLEDGE);
          queueSender = queueSession.createSender(queue);
          message = queueSession.createTextMessage();

          for (int i = 0; i < NUM_MSGS; i++) {
          message.setText("This is message #" + (i + 1));
          System.out.println("Sending message: " +
          message.getText());
          queueSender.send(message);
          }

          } catch (JMSException e) {
          System.out.println("Exception occurred: " + e.toString());
          } finally {
          if (queueConnection != null) {
          try {
          queueConnection.close();
          } catch (JMSException e) {}
          } // if
          System.exit(0);
          } // finally
          } // main
          } // class


          • 2. Re: SocketException
            Bill Lindsay Newbie

            I have the same issue even using the exmaples from the AdminDevelop book. The MDB is still able to process though...it just keeps reporting SOCKET CLOSED in the "Server Log"

            • 3. Re: SocketException
              Gavin Kearney Newbie

              I currently have this problem and im just wondering if there was ever a resolve to this issue?

              • 4. Re: SocketException
                Adrian Brock Master

                http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossHelp
                Will you stop posting ME TOO! They never get answered.

                • 5. Re: SocketException
                  Terry Paterson Newbie

                  I _think_ what you guys are seeing is simply a debug message -- it does'nt indicate any problem -- and can simply be gotten rid of by modifying your conf/log4j.xml file -- it seems like the standard log4j.xml ships with this anomalie !