8 Replies Latest reply on Sep 29, 2008 10:14 AM by jaikiran

    Help!! Failed to call remote methods in jboss 4. (EJB3, Stat

    mynameisdaniel

      Hi all,

      I got a problem with my first EJB3 test.
      I could call my remote method ONLY in the computer that runs JBoss.
      Here's the detailed situation:

      I wrote a Stateless Session Bean in Eclipse.
      It simply provides (remote) a static String method SayHello(String name).
      SayHello("Daniel") -> "Daniel says: Hello!"
      Then I copied the exported JAR file into server/default/deploy.
      JBoss 4 was launched and the jndi was up there. HelloWorldBean/remote
      Everything ran pretty well.

      Then I started another project in Eclipse which is called "SwingEJBTest"
      I wanted to use a Swing project to call the remote method.
      There was a JTextField (for Input), a JTextArea (for Output) and a JButton.
      I'm not good at describing things in English, please see my code below...

      I copied the interface HelloWorld.class and all the JARs in client folder.
      Then I set all the Classpaths, wrote codes and generated JAR with FatJAR.
      I launched the SwingEJBTest.jar with .bat file and everything was OK.
      I input "localhost:Daniel" and it outputs "Daniel says: Hello!".

      Then I copied the JAR to another computer and the problem came:
      I input "192.168.1.101:Daniel" (JBossServer: 192.168.1.101:1099).
      There was an exception thrown:
      Could not obtain connection to any of these urls: 192.168.1.101:1099...

      I closed the firewall on the JBossServer computer, pinged 198.168.1.101,
      but I found nothing abnormal. I can access the server computer,
      JBoss was still running there, firewall totally off.

      I packed the JAR with FatJAR, totally dependant from external JARs.

      Could anyone tell me why I got this Exception on another computer?

      Thanks a lot for your kind help.

      Regards,

      Daniel

        • 1. Re: Help!! Failed to call remote methods in jboss 4. (EJB3,
          mynameisdaniel

          oooops!!! Fogot to give the code.
          The code of EJB is totally ok. Here're some codes of the Swing client:

          /*
          *RemoteString.java
          */
          package ejbtest;

          import java.util.*;
          import javax.naming.*;
          import com.foshanshop.ejb3.HelloWorld;

          public class RemoteString {
          public static String getRemoteString(String name,String url) throws Exception{
          Properties props = new Properties();
          props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
          props.setProperty("java.naming.provider.url", url + ":1099");
          InitialContext ctx = new InitialContext(props);
          HelloWorld helloworld = (HelloWorld)ctx.lookup("HelloWorldBean/remote");
          return helloworld.SayHello(name);
          }
          }


          /*
          *A part of the codes for Swing, mouse event:
          */
          public void mouseReleased(MouseEvent arg0) {
          try{
          String info[] = textField.getText().split(":");
          textArea.setText(RemoteString.getRemoteString(info[1],info[0]));
          }
          catch(Exception e){textArea.setText(e.getMessage());}
          }


          I repeat: the SwingEJBTest.JAR ran well on the server computer,
          but not in other ones.

          • 2. Re: Help!! Failed to call remote methods in jboss 4. (EJB3,
            jaikiran

            Which version of JBoss do you use? For JBoss-4.2.x, you will have to start the server using the -b option. See this for details http://wiki.jboss.org/wiki/Wiki.jsp?page=JBoss42FAQ

            • 3. Re: Help!! Failed to call remote methods in jboss 4. (EJB3,
              mynameisdaniel

               

              "jaikiran" wrote:
              Which version of JBoss do you use? For JBoss-4.2.x, you will have to start the server using the -b option. See this for details http://wiki.jboss.org/wiki/Wiki.jsp?page=JBoss42FAQ


              Oh man! Problem solved by just starting JBoss with the -b option.
              I can't imagine that I just wasted a whole day for the "-b"!!
              I'm using JBoss AS 4.2.3.GA Release.

              Thanks a lot jaikiran!

              But another 2 questions here:

              1. What is the problem of "unprotected Instances of JBoss"?

              2. It takes about 3 seconds to call the remote method once, any way to accelerate the speed? I'm using a LAN system, I believe there're ways to make the callings much faster than 3 seconds.



              • 4. Re: Help!! Failed to call remote methods in jboss 4. (EJB3,
                jaikiran

                 

                "MyNameIsDaniel" wrote:


                1. What is the problem of "unprotected Instances of JBoss"?


                One well known problem is that through the jmx-console (which does not ask for a user/password by default) you can even shutdown the server.

                "MyNameIsDaniel" wrote:

                2. It takes about 3 seconds to call the remote method once, any way to accelerate the speed? I'm using a LAN system, I believe there're ways to make the callings much faster than 3 seconds.



                Every call takes 3 seconds? Does the server.log show any information on what is going on?

                • 5. Re: Help!! Failed to call remote methods in jboss 4. (EJB3,
                  mynameisdaniel

                  Well, I'm not providing the 8080 port cause I use Swing as my client-end. So there's no official way to access jmx-console.

                  I found it takes 3 seconds for the first-time-call, the second, third... call need only miliseconds. So I suppose it's the time needed to establish a kind of connection with the server. Guess it's normal.

                  Just now I tried to restart my firewall with the exception of 1099 (TCP) port. After restarting the firewall on the server, the Swing on client computer could no longer call the remote method (I didn't see any results). But no java exception reported. Do I need to set other ports free?

                  Sorry for bothering you with so many questions, I'm new to EJB.

                  • 6. Re: Help!! Failed to call remote methods in jboss 4. (EJB3,
                    jaikiran

                     

                    "MyNameIsDaniel" wrote:

                    Just now I tried to restart my firewall with the exception of 1099 (TCP) port. After restarting the firewall on the server, the Swing on client computer could no longer call the remote method (I didn't see any results). But no java exception reported. Do I need to set other ports free?



                    You will have to unblock the ports which JBoss uses. See this for details http://wiki.jboss.org/wiki/UsingJBossBehindAFirewall

                    • 7. Re: Help!! Failed to call remote methods in jboss 4. (EJB3,
                      mynameisdaniel

                      I'll spend some time reading this. Thanks for your kind help :-)

                      • 8. Re: Help!! Failed to call remote methods in jboss 4. (EJB3,
                        jaikiran

                        You're welcome :-)