2 Replies Latest reply on Jul 28, 2011 6:09 AM by Vinicius Carvalho

    Problems getting InitialContext

    Vinicius Carvalho Apprentice

      Hi there! I'm running AS 7.0 Final with the standalone-preview configuration.

       

      So I have this small code to lookup for jms ConnectionFactory (running outside the AS)

       

       

      Connection conn = null;
                          try {
                                    InitialContext ctx = InitialContextFactory.getContext();
                                    Queue destination = (Queue) ctx.lookup("/queue/testQueue");
                                    ConnectionFactory cf = (ConnectionFactory)ctx.lookup("/RemoteConnectionFactory");
                                    conn = cf.createConnection();
                                    conn.start();
                                    Session session = conn.createSession(false,Session.AUTO_ACKNOWLEDGE);
                                    MessageProducer producer = session.createProducer(destination);
                                    TextMessage message1 = session.createTextMessage("This is a text message1");
                                    producer.send(message1);
                          } catch (Exception e) {
                                    // TODO: handle exception
                                    e.printStackTrace();
                          }finally{
                                    if(conn != null){
                                              conn.close();
                                    }
                          }
      
      

       

      Properties props = new Properties();
                                    props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
                                    props.put("java.naming.provider.url","jnp://localhost:1099");
                                    props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
                                    try {
                                              ctx = new InitialContext(props);
                                    } catch (NamingException e) {
                                              e.printStackTrace();
                                    }
      
      

       

       

      On my classpath I have hornetq 2.2.6 jars (both core-client and jms-client), netty 3.2.3, jboss jms 1.0.0.Final, jnp-client and jnp-server from HornetQ lib folder.

       

      But I'm getting an exception when trying to access the jndi:

       

      javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming.CommunicationException: Failed to retrieve stub from server /159.107.170.27:1100 [Root exception is java.io.StreamCorruptedException: unexpected block data] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]]

                at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1763)

                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:693)

                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)

                at javax.naming.InitialContext.lookup(InitialContext.java:392)

                at com.furiousbob.hornetq.test.SimpleTextMessageProducer.sendSimpleMessage(SimpleTextMessageProducer.java:21)

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

                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

                at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

                at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)

                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)

                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)

                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

                at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

                at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

                at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

                at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

      Caused by: javax.naming.CommunicationException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]

                at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:335)

                at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1734)

                ... 27 more

      Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]

                at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:305)

                ... 28 more

      Caused by: java.net.ConnectException: Connection refused: connect

                at java.net.PlainSocketImpl.socketConnect(Native Method)

                at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)

                at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)

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

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

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

                at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:97)

                at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:82)

                at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:301)

                ... 28 more

       

       

      I really don't know why is it trying to get a stub from 1100, I don't have HA enabled. Any ideas?

       

      Regards