1 2 Previous Next 21 Replies Latest reply on Apr 8, 2008 3:52 AM by R B

    Basic EJB  - cant be invoked from client

    R B Newbie

      Hi,

      I am trying to create a simple EJB and deploy to JBoss. The EJB is created and deployed to JBoss successfully. However when i try to invoke it from a standalone client i am unable to do so. I get a javax.naming.CommunicationException: exception.

      Following is the code for my EJB Local interface:

      import javax.ejb.Local;
      
      @Local
      public interface CalculatorLocal
      {
       public float add(float x, float y);
      }
      

      Following is the code for the EJB:
      import javax.ejb.Local;
      import javax.ejb.Stateless;
      
      
      @Stateless
      public class CalculatorBean implements CalculatorLocal
      {
      
       public float add(float x, float y)
       {
       return x+y;
       }
      
      }
      

      Following is the code for the client:
      import javax.naming.InitialContext;
      
      import uk.co.autotrader.ejb3.stateless.CalculatorLocal;
      
      
      public class CalculatorClient
      {
       public static void main(String args[]){
       try {
       InitialContext ic = new InitialContext();
       CalculatorLocal calculator = (CalculatorLocal)ic.lookup("CalculatorBean/local");
       float total = calculator.add(2F, 5F);
       System.out.println("sum is "+total);
       }
       catch(Exception e){
       System.out.println("Exception "+e);
       }
       }
      }
      

      Following is the exception message at the console when the client is run:
      javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
      


      I have included the necessary JAR files and also have jndi.properties in my client code class path (After referring http://www.jboss.org/?module=bb&op=viewtopic&t=57223)

      I am using JBoss 4.2.2 GA.

      Can anyone help?

        • 1. Re: Basic EJB  - cant be invoked from client
          jaikiran pai Master

          How are you starting JBoss? Do you use -b option to start JBoss? And what have you specified in the jndi.properties file?

          • 2. Re: Basic EJB  - cant be invoked from client
            Jeroen Wenting Newbie

            that's a network error. Make sure the URI you refer to in your naming.properties is correct and can be reached from your client.

            • 3. Re: Basic EJB  - cant be invoked from client
              R B Newbie

              Thanks for the replies!

              I am not using -b to start JBoss. And I am using JNDI.properties from the JBoss/server/default/conf folder. It has the following :

              # DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
              #
              java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
              java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
              


              Is some other value required in JNDI.properties?

              • 4. Re: Basic EJB  - cant be invoked from client
                jaikiran pai Master

                What does the following command return from the machine where you are running the client:

                telnet localhost 1099




                • 5. Re: Basic EJB  - cant be invoked from client
                  R B Newbie

                  It returns the some the following response:

                   ¼Ã�sr↓java.rmi.MarshalledObject|¢▲ùÃ�c³>☻♥I♦hashlocBytest☻[BobjBytesq~☺xp]?Ãur☻[B¼
                  ↨°TÓ☻xp'¼Ã�t▬http://127.0.0.1:8083/q~q~uq~♥└¼Ã�sr org.jnp.server.NamingServer_Stub
                  ☻☻xrjava.rmi.server.RemoteStubÚ■▄╔ïße☻xr∟java.rmi.server.RemoteObjectËa┤æ
                   a3▲♥xpw
                  4
                   UnicastRef2 127.0.0.1♦JÌò↔°☺↓¶çOßÇx
                  
                  Connection to host lost.
                  


                  • 6. Re: Basic EJB  - cant be invoked from client
                    jaikiran pai Master

                    This output looks fine to me. Can you post the complete exception stacktrace that you are seeing?

                    • 7. Re: Basic EJB  - cant be invoked from client
                      R B Newbie

                      Following is the complete stacktrace:

                      
                      Exception in thread "main" javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
                       at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1465)
                       at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1594)
                       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:634)
                       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
                       at javax.naming.InitialContext.lookup(InitialContext.java:351)
                       at uk.co.autotrader.ejb3.client.CalculatorClient.main(CalculatorClient.java:13)
                      Caused by: java.net.SocketTimeoutException: Receive timed out
                       at java.net.PlainDatagramSocketImpl.receive0(Native Method)
                       at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:136)
                       at java.net.DatagramSocket.receive(DatagramSocket.java:712)
                       at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1435)
                       ... 5 more
                      
                      


                      • 8. Re: Basic EJB  - cant be invoked from client
                        jaikiran pai Master

                         

                        "r12345_2003" wrote:

                        I have included the necessary JAR files and also have jndi.properties in my client code class path


                        Can you try removing the jboss jar files that you have included in the client classpath and only include jbossall-client.jar file which you will find in %JBOSS_HOME%/client folder.

                        • 9. Re: Basic EJB  - cant be invoked from client
                          R B Newbie

                          Do you mean removing all JBoss related jar files & keep only jbossall-client.jar? I tried that & still doesnt work. I also tried removing all other jar files as well & keeping only jbossall-client.jar but its still the same :(

                          • 10. Re: Basic EJB  - cant be invoked from client
                            jaikiran pai Master

                            The code and the telnet output that you posted does not show any obvious errors to me. I usually place only the jbossall-client.jar file in the classpath as this includes almost all JBoss related classes. Can you post the console log that you see on the server when the server is started? Also can you access http://localhost:8080/jmx-console from the browser? Any firewalls/anti-virus running on your system?

                            • 11. Re: Basic EJB  - cant be invoked from client
                              R B Newbie

                              yes i can access JMX Console. I can even see the EJB in the JMX console.
                              Yes i think my system is behind a firewall.
                              Would that make a difference?
                              Its really driving me crazy.. i did not think deploying a simple EJB would be so difficult :(

                              • 12. Re: Basic EJB  - cant be invoked from client
                                jaikiran pai Master

                                 

                                "r12345_2003" wrote:

                                Yes i think my system is behind a firewall.
                                Would that make a difference?


                                Well if you are able to telnet from the machine where you have the client to the server, then i guess you should be able to run the client too. But probably, you could give it a try to disable the firewall and run the client. At this point, i am really running out of ideas.


                                • 13. Re: Basic EJB  - cant be invoked from client
                                  Jeroen Wenting Newbie

                                  A remote EJB client using an EJB local interface?
                                  Might be the problem.

                                  • 14. Re: Basic EJB  - cant be invoked from client
                                    Jeffrey Rosen Newbie

                                     

                                    "jwenting" wrote:
                                    A remote EJB client using an EJB local interface?
                                    Might be the problem.


                                    It would be a problem, but I think it would show up later. The exception occurs during the JNDI lookup. At worst he should get a NamingException.

                                    The problem is that he hasn't told the client where the naming provider is located. One possible solution would be to modify the something like:

                                    InitialContext ic = new InitialContext();
                                    Context jndiRoot = (Context) ic.lookup("jnp://localhost:1099");
                                    CalculatorLocal calculator = (CalculatorLocal)jndiRoot.lookup("CalculatorBean/local");
                                    


                                    Assuming that JBoss is running on the same machine as the client, otherwise adjust the URL accordingly.


                                    1 2 Previous Next