10 Replies Latest reply on Aug 14, 2013 1:57 AM by jaikiran pai

    invoke EJB 3 from a remote server problem

    mid491 mid491 Newbie

      hi,

       

      I'am trying to call a remote EJB on a second server.

       

      First, I've tried on my local Jboss (7.1.1-final, Windows Seven) ) the tutorial (http://www.jboss.org/jdf/quickstarts/jboss-as-quickstart/ejb-remote/) & https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

      All works fine.

       

      Second, I've deployed on my remote Jboss the same tutorial and all works fine.

       

      Third, I've changed the "jboss-ejb-client.properties" on the client (the local) to target the remote server :

       

      remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

      remote.connections=default

      remote.connection.default.host=167.50.75.98

      remote.connection.default.port = 4447

      remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

       

      and add credentials :

       

      remote.connection.default.username=ejb

      remote.connection.default.password=test

       

      On server side (the remote Jboss) I've added the user (add-user.bat)

       

      Maven compile, and mvn exec:exec on client side, I got this error :

       

      5 ao¹t 2013 17:16:00 org.jboss.ejb.client.EJBClient <clinit>

      INFO: JBoss EJB Client version 1.0.16.Final

      5 ao¹t 2013 17:16:00 org.xnio.Xnio <clinit>

      INFO: XNIO Version 3.0.7.GA

      5 ao¹t 2013 17:16:00 org.xnio.nio.NioXnio <clinit>

      INFO: XNIO NIO Implementation Version 3.0.7.GA

      5 ao¹t 2013 17:16:00 org.jboss.remoting3.EndpointImpl <clinit>

      INFO: JBoss Remoting version 3.2.14.GA

      5 ao¹t 2013 17:16:00 org.jboss.remoting3.remote.RemoteConnection handleException

      ERROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed

      5 ao¹t 2013 17:16:00 org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers

      WARN: Could not register a EJB receiver for connection to 167.50.75.98:4447

      java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed

              at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:91)

              at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:148)

              at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:105)

              at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:73)

              at org.jboss.ejb.client.EJBClientContext.<clinit>(EJBClientContext.java:81)

              at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:156)

              at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:124)

              at $Proxy0.add(Unknown Source)

              at org.jboss.as.quickstarts.ejb.remote.client.RemoteEJBClient.invokeStatelessBean(RemoteEJBClient.java:56)

              at org.jboss.as.quickstarts.ejb.remote.client.RemoteEJBClient.main(RemoteEJBClient.java:37)

      Caused by: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed

              at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:332)

              at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:225)

              at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72)

              at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(TranslatingSuspendableChannel.java:189)

              at org.xnio.channels.TranslatingSuspendableChannel$1.handleEvent(TranslatingSuspendableChannel.java:103)

              at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72)

              at org.xnio.nio.NioHandle.run(NioHandle.java:90)

              at org.xnio.nio.WorkerThread.run(WorkerThread.java:187)

              at ...asynchronous invocation...(Unknown Source)

              at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:270)

              at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:386)

              at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:151)

              at org.jboss.ejb.client.remoting.NetworkUtil.connect(NetworkUtil.java:132)

              at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:146)

              ... 8 more

      5 ao¹t 2013 17:16:00 org.jboss.remoting3.remote.RemoteConnection handleException

      ERROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed

      Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:jboss-as-ejb-remote-server-side, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@2f74219d

              at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:693)

              at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)

              at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:183)

              at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:177)

              at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:161)

              at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:124)

              at $Proxy0.add(Unknown Source)

              at org.jboss.as.quickstarts.ejb.remote.client.RemoteEJBClient.invokeStatelessBean(RemoteEJBClient.java:56)

              at org.jboss.as.quickstarts.ejb.remote.client.RemoteEJBClient.main(RemoteEJBClient.java:37)

       

       

       

      did I miss something ?

       

      thanx!

        • 1. Re: invoke EJB 3 from a remote server problem
          Wolf-Dieter Fink Master

          Do you add the user as Application user? Management user is not for app login.

          • 2. Re: invoke EJB 3 from a remote server problem
            mid491 mid491 Newbie

            yes I did (b option) ... now it's working..;I guess I did not restart the server after add user ??

            • 3. Re: invoke EJB 3 from a remote server problem
              mid491 mid491 Newbie

              Now I tried to integrate tha sample into my app :EAR + WAR (JSF 2 + primefaces) and EJB Service Layer, Maven 3, Eclipse JUno with Jboss Tools

               

              I try to integrate code into a JSF controler :

              - jboss-ejb-client.properties into WEB-INF/

              - WAR pom :

               

                        <dependencyManagement>

                                  <dependencies>

                                            <dependency>

                                                      <groupId>org.jboss.spec</groupId>

                                                      <artifactId>jboss-javaee-6.0</artifactId>

                                                      <version>3.0.2.Final</version>

                                                      <type>pom</type>

                                                      <scope>import</scope>

                                            </dependency>

               

               

                                            <dependency>

                                                      <groupId>org.jboss.as</groupId>

                                                      <artifactId>jboss-as-ejb-client-bom</artifactId>

                                                      <version>7.1.1.Final</version>

                                                      <type>pom</type>

                                                      <scope>import</scope>

                                            </dependency>

                                  </dependencies>

                        </dependencyManagement>

               

              and

              <dependencies>

                <dependency>

                  <groupId>org.jboss.as.quickstarts</groupId>

                  <artifactId>jboss-as-ejb-remote-server-side</artifactId>

                  <type>ejb-client</type>

                  <version>7.1.2-SNAPSHOT</version>

              </dependency>

              ...

               

              The code himself is excactly the same as the sample :

               

                  public void runTests() {

                      RemoteCalculator statelessRemoteCalculator = null;

                      try {

                          statelessRemoteCalculator = lookupRemoteStatelessCalculator();

                      } catch (NamingException e) {

                          e.printStackTrace();

                      }

                      System.out("Obtained a remote stateless calculator for invocation");

                      // invoke on the remote calculator

                      int a = 204;

                      int b = 340;

                      System.out("Adding " + a + " and " + b + " via the remote stateless calculator deployed on the server");

                      int sum = statelessRemoteCalculator.add(a, b);

                      System.out.println("Remote calculator returned sum = " + sum);

              ....

               

                  @SuppressWarnings({ "rawtypes", "unchecked" })

                  public RemoteCalculator lookupRemoteStatelessCalculator()

                          throws NamingException {

               

               

                      Hashtable jndiProperties = new Hashtable();

                      jndiProperties.put(Context.URL_PKG_PREFIXES,  "org.jboss.ejb.client.naming");

                      Context context = new InitialContext(jndiProperties);

                      // let's do the lookup

                      return (RemoteCalculator) context.lookup("ejb:/jboss-as-ejb-remote-server-side/CalculatorBean!"+ RemoteCalculator.class.getName());

                  }

               

              Got this error after deployement  :

              14:40:43,256 INFO  [org.jboss.ejb.client] (http--0.0.0.0-8080-5) JBoss EJB Client version 1.0.5.Final

              14:40:43,260 INFO  [stdout] (http--0.0.0.0-8080-5) Obtained a remote stateless calculator for invocation

               

              14:40:43,261 INFO  [stdout] (http--0.0.0.0-8080-5) Adding 204 and 340 via the remote stateless calculator deployed on the server

               

               

              Caused by: javax.faces.el.EvaluationException: java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:jboss-as-ejb-remote-server-side,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@1af5e838

                        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]

                        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) [jsf-impl-2.1.7-jbossorg-2.jar:]

              java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:jboss-as-ejb-remote-server-side,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@7b068297

                        at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                        at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                        at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                        at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

               

               

              If I check the properties file inside code I got the keys ;

                      Properties props = new Properties();

                      try {

                          // load a properties file from class path, inside static method

                          props.load(getClass().getClassLoader().getResourceAsStream(

                                  "jboss-ejb-client.properties"));

               

               

                          for (String key : props.stringPropertyNames()) {

                              String value = props.getProperty(key);

                              System.out.println(" ### " + value);

                          }

               

               

                      } catch (IOException ex) {

                          ex.printStackTrace();

                      }

               

              So I guess the class-path is ok.

               

              any hints ? Maybe a problem on 7.1.1-final ? or is it something about Maven depdencies ? M2e with Jboss tools ?? Or maybe something with the JSF Controler context ?

              @ManagedBean(name = "TestController")

              @RequestScoped

              public class Controller

              • 4. Re: invoke EJB 3 from a remote server problem
                mid491 mid491 Newbie

                something I don't understand in regards of tutorials (https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI & https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance

                 

                If I choose the first way (JNDI) to call a remote EJB (server & client are on two different machines) Do I have to configure the client machine as specified into the second tutorial ?? (anyway I've tried to do that, same error..)

                • 5. Re: invoke EJB 3 from a remote server problem
                  Wolf-Dieter Fink Master

                  It's unclear to me what you do.

                  Is the 'client' a application deployed on a second server? Or is it a client running as simple Java program?

                  The difference between the two documentations is exact this difference 'remote+client' mean a standalone program 'remote+server+instance' mean an EE application deployed in AS7 call an EJB in another server.

                   

                  Also the lookup name change if you deploy the EJB in an EAR or JAR file

                  1 of 1 people found this helpful
                  • 6. Re: invoke EJB 3 from a remote server problem
                    mid491 mid491 Newbie

                    Thank you Wolf-Dieter to answer me

                     

                    Sorry if I was unclear ^^

                    I have two servers (two machines) , each a Jboss server 7.1.1-final.

                     

                    I first test the tutorial "as-it" : so I can call the server part (deployed on Jboss) from the client part (standalone). Nice.

                    Note the server side tutorial part is deployed as explain in the readme (mvn install and mvn jboss-as:deploy). So it is not deployed inside an EAR or WAR :

                     

                      java:global/jboss-as-ejb-remote-server-side/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator

                              java:app/jboss-as-ejb-remote-server-side/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator

                              java:module/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator

                              java:jboss/exported/jboss-as-ejb-remote-server-side/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator

                              java:global/jboss-as-ejb-remote-server-side/CalculatorBean

                              java:app/jboss-as-ejb-remote-server-side/CalculatorBean

                              java:module/CalculatorBean

                     

                    Now what I am tried to do is to call the server part (on distant machine) but with the client part tutorial code integrated inside an JEE application (EAR+WAR+EJB)

                     

                    About documentation : to me remote does not necessarily mean standalone only (Java main program) ? It's confusing...

                    So I have to follow up the 'remote+server+instance' If I want to make the tutorial code working inside a JEE application ?

                     

                    thx,

                    • 7. Re: invoke EJB 3 from a remote server problem
                      Wolf-Dieter Fink Master

                      mid491 mid491 schrieb:

                       

                      About documentation : to me remote does not necessarily mean standalone only (Java main program) ? It's confusing...

                      So I have to follow up the 'remote+server+instance' If I want to make the tutorial code working inside a JEE application

                      Yes, you have to follow that document.

                      Also you can have a look to my quickstart ejb-multi-server here. the main-app invoke applications deployed on other servers with different approaches.

                      1 of 1 people found this helpful
                      • 8. Re: invoke EJB 3 from a remote server problem
                        mid491 mid491 Newbie

                        Finaly got it. Thx Wolf-Dieter to point me the right way

                         

                        I restarted from scratch with my own simple :

                        - a provider project with a simple EJB project inside an EAR, deployed on the remote machine (Jboss 7.1.1-final).

                        - adding user with add-user.bat & following the sample article realm creation processus

                        - export the jar from Eclipse

                         

                        - create a client project into a EAR/WAR with servlet that consume the distant EJB deployed on the client machine

                        - adding into ClientWeb\WebContent\WEB-INF\lib the exported JAR from the provider project and adding jboss-client.jar into same directory (taken from jboss-as-7.1.1.Final\bin\client)

                         

                        Deploy, works perfect.

                        In can trace the network activity with wireShark :

                        795.966334000167.50.95.78167.50.95.58TCP20354227 > n1-rmgmt [PSH, ACK] Seq=1 Ack=1 Win=254 Len=149
                        835.972352000167.50.95.78167.50.95.58TCP66[TCP Dup ACK 79#1] 54227 > n1-rmgmt [ACK] Seq=150 Ack=1 Win=254 Len=0 SLE=48 SRE=60

                         

                         

                        My mistakes in my previous tests was the confusion beetwen remote Client unsing JNDI approach vs remote server instance and to put the jboss-ejb-client.xml at the wrong place I guess it s from M2e plugin that drop out the jboss-ejb-client.xml from EAR/META-INF during depoyment

                         

                        As said in comments of article (https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance) If things goes right you must have a log message into console during deployment like :

                        [org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver] (MSC service thread 1-4) Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@600a08, receiver=Remoting connection EJB receiver [connection=Remoting connection <18f57d2>,channel=jboss.ejb,nodename=nodeone]} on channel Channel ID b3e3f879 (outbound) of Remoting connection 0024e39f to localhost/127.0.0.1:4447

                         

                        Otherwise something is wrong like the jboss-ejb-client.xml not at the good place.

                         

                         

                         

                        Note : sample document has typo mistake at chap. 9 "Create a security realm on the client server" : I'll first shutdown the client server and edit the standlaone-full.xml file to add the following in the <management> section and after  jaikiran (...)

                        He did not edit the xml but used the jboss-cli.bat to create the realm. Indeed, we can do it the two ways but the article used the jboss-cli.bat one.

                         

                        Happy

                        • 9. Re: invoke EJB 3 from a remote server problem
                          mid491 mid491 Newbie

                          last question : the document https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project is "remote.client" oriented.  Is it usable for the same purpose (call EJB from one machine to another machine) ?

                          • 10. Re: invoke EJB 3 from a remote server problem
                            jaikiran pai Master

                            mid491 mid491 wrote:

                             

                            last question : the document https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project is "remote.client" oriented.  Is it usable for the same purpose (call EJB from one machine to another machine) ?

                            Yes, it applies for all remote EJB invocations.