12 Replies Latest reply: Jun 24, 2013 1:14 AM by Samir Vaidya RSS

    Remote JMS connection with UnknownHostException

    brian essen Newbie

      I have a JMS client that connects to JBoss AS 7.1.1.Final. The client provides connection properties to the remote server using IP address (not hosname). However, the server appears to return the hostname and since it is not on our DNS server, the client code returns with UnknownHostException. This problem does not happens with EJB remote lookup.

       

      If I'll add this server name myhost to the client HOSTS file it will work, but this is not acceptable by the costumers (to make changes to all clients). I have tried to run JBoss with -b <IP> option and it still did not help.

       

      is the a way to config JBoss AS 7 to work only with the IP address?

       

      Here is my sample code and the stack trace:

       

      public class MessageClient {

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

              final Context context = getInitialContext();

              QueueConnection conn = null;

              QueueSession session = null;

       

              try {

                  QueueConnectionFactory qcf = (QueueConnectionFactory)context.lookup("jms/RemoteConnectionFactory");

                  conn = qcf.createQueueConnection("jmsuser", "password");

                  conn.start();

                  Queue queue = (Queue)context.lookup("queue/test");

                  session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

       

                  System.out.println("Got qcf " + qcf);

                  System.out.println("Got q " + queue);

       

       

       

              } finally {

                  try {

                      conn.stop();

                  } catch (Exception ignore) {

                  }

                  try {

                      session.close();

                  } catch (Exception ignore) {

                  }

                  try {

                      conn.close();

                  } catch (Exception ignore) {

                  }

              }

          }

       

          public static Context getInitialContext( ) throws javax.naming.NamingException {

       

              Properties p = new Properties( );

              p.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());

              p.put(Context.PROVIDER_URL, "remote://x.x.x.x:4447");

              p.put("jboss.naming.client.ejb.context", true);

              return new javax.naming.InitialContext(p);

          }

      }

      stacktrace:

       

      SEVERE: Failed to create netty connection

      java.net.UnknownHostException: myhost

              at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)

              at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)

              at java.net.Socket.connect(Socket.java:529)

              at org.jboss.netty.channel.socket.oio.OioClientSocketPipelineSink.connect(OioClientSocketPipelineSink.java:114)

              at org.jboss.netty.channel.socket.oio.OioClientSocketPipelineSink.eventSunk(OioClientSocketPipelineSink.java:74)

              at org.jboss.netty.channel.Channels.connect(Channels.java:541)

              at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:210)

              at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)

              at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)

              at org.hornetq.core.remoting.impl.netty.NettyConnector.createConnection(NettyConnector.java:473)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnection(ClientSessionFactoryImpl.java:1143)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnectionWithRetry(ClientSessionFactoryImpl.java:993)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.connect(ClientSessionFactoryImpl.java:224)

              at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:747)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:601)

              at org.hornetq.jms.client.HornetQConnectionFactory.createQueueConnection(HornetQConnectionFactory.java:131)

              at com.client.MessageClient.main(MessageClient.java:34)