2 Replies Latest reply on Dec 12, 2006 12:01 PM by Uday Devarakonda

    Getting Exception while trying to access a Stateless EJB in

    Uday Devarakonda Newbie

      Hi...

      I am trying to access a Stateless EJB
      I am getting an Exception when trying to access the EJB which is deployed in the jboss server.

      ==========================================
      The client program from which I tried to access is :
      ==========================================
      package client;

      import java.util.Properties;

      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.rmi.PortableRemoteObject;

      import examples.ejb21.Hello;
      import examples.ejb21.HelloHome;

      public class HelloClient
      {
      public static void main (String args[])throws Exception
      {
      Properties props = new Properties();

      props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.HttpNamingContextFactory");
      props.put(Context.PROVIDER_URL,"jnp://localhost:8080");
      Context ctx = new InitialContext(props);
      Object obj = ctx.lookup("HelloHome");
      HelloHome home = (HelloHome)PortableRemoteObject.narrow(obj, HelloHome.class);
      Hello hello = home.create();

      System.out.println(hello.hello());

      hello.remove();
      }
      }

      =============================================================================================
      The Exception I got is

      javax.naming.NamingException: Failed to retrieve Naming interface [Root exception is java.io.StreamCorruptedException: invalid stream header]
      at org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java:69)
      at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
      at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
      at javax.naming.InitialContext.init(Unknown Source)
      at javax.naming.InitialContext.(Unknown Source)
      at client.HelloClient.main(HelloClient.java:30)
      Caused by: java.io.StreamCorruptedException: invalid stream header
      at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
      at java.io.ObjectInputStream.(Unknown Source)
      at org.jboss.naming.HttpNamingContextFactory.getNamingServer(HttpNamingContextFactory.java:119)
      at org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java:65)
      ... 5 more
      Exception in thread "main"


      ========================================================================

      Can anybody help me to come out of this Exception??

      Thanks in advance
      Uday

        • 1. Re: Getting Exception while trying to access a Stateless EJB
          jaikiran pai Master

           

          Properties props = new Properties();

          props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.HttpNamingContextFactory");
          props.put(Context.PROVIDER_URL,"jnp://localhost:8080");
          Context ctx = new InitialContext(props);


          This should be:

          Properties props = new Properties();
          
          props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
          props.put(Context.PROVIDER_URL,"jnp://localhost:1099");
          Context ctx = new InitialContext(props);


          • 2. Re: Getting Exception while trying to access a Stateless EJB
            Uday Devarakonda Newbie

             

            "jaikiran" wrote:
            Properties props = new Properties();

            props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.HttpNamingContextFactory");
            props.put(Context.PROVIDER_URL,"jnp://localhost:8080");
            Context ctx = new InitialContext(props);


            This should be:

            Properties props = new Properties();
            
            props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
            props.put(Context.PROVIDER_URL,"jnp://localhost:1099");
            Context ctx = new InitialContext(props);



            Thank you very much for quick response jaikiran. I tried to execute the client program by the changes you mentioned above. But still getting Exception. I have included the log4j.jar from <JBOSS_HOME>\client\ both in the build path of the project and in the jboss configuration.(Jboss is configured in eclipse).

            Can you please help me to come out of this exception...


            --------------------------------------------------------------------------------------------------------------------
            The ejb-jar.xml file is



            <?xml version="1.0" encoding="UTF-8"?>

            <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xs1="http://www.w3.org/2001/XMLSchema-instance" xs1:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">
            <enterprise-beans>

            <ejb-name>HelloHome</ejb-name>
            examples.ejb21.HelloHome
            examples.ejb21.Hello
            <local-home>examples.ejb21.HelloLocalHome</local-home>
            examples.ejb21.HelloLocal
            <ejb-class>examples.ejb21.HelloBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>

            </enterprise-beans>
            </ejb-jar>

            --------------------------------------------------------------------------------------------------------------------
            Exception is

            log4j:WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext).
            log4j:WARN Please initialize the log4j system properly.
            Exception in thread "main" javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]]
            at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1399)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:579)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
            at javax.naming.InitialContext.lookup(Unknown Source)
            at client.HelloClient.main(HelloClient.java:37)
            Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]
            at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:254)
            at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1370)
            ... 4 more
            Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused: connect]
            at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:228)
            ... 5 more
            Caused by: java.net.ConnectException: Connection refused: connect
            at java.net.PlainSocketImpl.socketConnect(Native Method)
            at java.net.PlainSocketImpl.doConnect(Unknown Source)
            at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
            at java.net.PlainSocketImpl.connect(Unknown Source)
            at java.net.SocksSocketImpl.connect(Unknown Source)
            at java.net.Socket.connect(Unknown Source)
            at java.net.Socket.connect(Unknown Source)
            at java.net.Socket.(Unknown Source)
            at java.net.Socket.(Unknown Source)
            at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:69)
            at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:62)
            at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:224)
            ... 5 more


            Thanks in advance
            Uday