7 Replies Latest reply: Mar 13, 2013 6:25 AM by r035198x RSS

    CommunicationException: Connection refused when we connect from Standalone

    SureshKreddy
      Hi friends,

      I am using JDevloper 10.1.3.3.0 as my IDE. I tried to connect EJB(2.1) using a standalone java class, but i am getting the below exception.

      javax.naming.CommunicationException: Connection refused: connect [Root exception is java.net.ConnectException: Connection refused: connect]
      javax.naming.CommunicationException: Connection refused: connect [Root exception is java.net.ConnectException: Connection refused: connect]
           at com.evermind.server.rmi.RMIClient.lookup(RMIClient.java:296)
           at com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:51)
           at javax.naming.InitialContext.lookup(InitialContext.java:351)

      Where as if i connect it from jspx page, its not giving any problem and its calling ejb methods and returning o/p.

      Can anyone guide me, in resolving this?

      Regards,
      Suresh K
        • 1. Re: CommunicationException: Connection refused when we connect from Standalone
          r035198x
          Maybe your standalone client is using the wrong connection details, client is behind a restrictive firewall or your program needs to have the right proxy sever details set. Either way it's a connection link problem between the two JVMs so try ping/telnet first then proxy in your application.
          • 2. Re: CommunicationException: Connection refused when we connect from Standalone
            SureshKreddy
            Here the server is local oc4j server(localhost)

            The same is getting called when i call it from jsf, but not from the client.

            The call to ejb from delegator is like below(delegator's method is called from client/jsf):

            initCtx = new InitialContext();
            LawyerCronJobSessionEJBHome lawyerCronJobSes =
            (LawyerCronJobSessionEJBHome)(PortableRemoteObject.narrow(initCtx.lookup("LawyerCronJobSessionEJB"),
            LawyerCronJobSessionEJBHome.class));
            LawyerCronJobSessionEJB lawyerCronJobSessionEJB;
            lawyerCronJobSessionEJB = lawyerCronJobSes.create();
            lawyerCronJobSessionEJB.sendExpireInfoMailToLawyer();

            Regards,
            Suresh K
            • 3. Re: CommunicationException: Connection refused when we connect from Standalone
              r035198x
              Suresh Kethireddy wrote:
              Here the server is local oc4j server(localhost)

              The same is getting called when i call it from jsf, but not from the client.

              The call to ejb from delegator is like below(delegator's method is called from client/jsf):

              initCtx = new InitialContext();
              LawyerCronJobSessionEJBHome lawyerCronJobSes =
              (LawyerCronJobSessionEJBHome)(PortableRemoteObject.narrow(initCtx.lookup("LawyerCronJobSessionEJB"),
              LawyerCronJobSessionEJBHome.class));
              LawyerCronJobSessionEJB lawyerCronJobSessionEJB;
              lawyerCronJobSessionEJB = lawyerCronJobSes.create();
              lawyerCronJobSessionEJB.sendExpireInfoMailToLawyer();

              Regards,
              Suresh K
              Your initCtx = new InitialContext(); won't work from a client. You need to create the InitialContext by passing it values in a HashMap that tell it where to look up the EJBs from. It works in JSF because that is running in a container and so the context is created from that server's settings.
              • 4. Re: CommunicationException: Connection refused when we connect from Standalone
                SureshKreddy
                I tried calling from existing initContext too like here:

                private static Context getInitialContext() throws NamingException, Exception {
                Hashtable env = new Hashtable();
                env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
                PropertiesLoader propLoader = new PropertiesLoader();
                     env.put(Context.SECURITY_AUTHENTICATION, propLoader.getValue("ORMI_SECURITY_AUTHENTICATION"));
                env.put(Context.SECURITY_PRINCIPAL, propLoader.getValue("ORMI_LOGIN_ID"));
                env.put(Context.SECURITY_CREDENTIALS, propLoader.getValue("ORMI_PASSWORD"));
                env.put(Context.PROVIDER_URL, propLoader.getValue("ORMI_PROVIDER_URL"));
                return new InitialContext(env);
                     }

                But still, its throwing the same error.

                Thanks for your quick replies :)

                Regards,
                Suresh K
                • 5. Re: CommunicationException: Connection refused when we connect from Standalone
                  r035198x
                  Did you verify that your PropertiesLoader is actually loading any properties and that properties are correct?
                  • 6. Re: CommunicationException: Connection refused when we connect from Standalone
                    SureshKreddy
                    Hi all,

                    Problem is solved, cause of the problem is wrong name given in the rmi url.

                    ormi://localhost:12401/xxxxx

                    where xxxx is the earlier given wrong name.

                    Now we corrected with proper name and its solved.

                    Regards,
                    Suresh K
                    • 7. Re: CommunicationException: Connection refused when we connect from Standalone
                      r035198x
                      Suresh Kethireddy wrote:
                      Hi all,

                      Problem is solved, cause of the problem is wrong name given in the rmi url.
                      Well that was the very first thing I asked you to check ...
                      r035198x wrote:
                      Maybe your standalone client is using the wrong connection details, ....