7 Replies Latest reply on Mar 28, 2013 10:36 AM by Lukasz Szymik

    JBoss remote connection to clustered EJB issue

    Lukasz Szymik Newbie

      Hello,

       

      I have issue with getting proper connection from remote Java client to EJB deployed in cluster. I have stateless session bean with annotation @Clustered. I am using domain with HA profile and ha-sockets. I have 2 nodes defined in host.xml file.

      The cluster starts properly and applicaiton is deployed without issues. I am using JBoss 7.1.3

       

      I also have client which is working fine with standalone version of JBoss. How I could use it for connecting to clustered version. I run simple tests and as soon as one node is killed, the second node is not taking over work. The failover is not working at all.

      I am using connection with remoting3.Endpoint, remoting3.Connection etc. I tried to use Google but there are many missleading informaiton. I could not use JNDI lookup with properties, because I am not getting connection at all. I tried for find documentation for Remoting3 but there was no such link.

       

       

      public class Connector {
      
          public final static Boolean SSL_ENABLED = Boolean.FALSE;
          public final static Boolean SASL_SERVER_AUTH = Boolean.FALSE;
          public final static Boolean SASL_POLICY_NOANONYMOUS = Boolean.FALSE;
          public final static Boolean SASL_POLICY_NOPLAINTEXT = Boolean.FALSE;
          public final static int CONNECTION_TIMEOUT_SECONDS = 5;
          public final static String URL_PKG_PREFIXES = "org.jboss.ejb.client.naming";
      
          private Endpoint endpoint;
      
          private Connection connection;
      
          return Instance of <code>Endpoint</code>
      
          public Endpoint getEndpoint() {
              return endpoint;
          }
      
          public Connection getConnection() {
              return connection;
          }
      
          private static ThreadLocalContextSelector<EJBClientContext> threadLocalContextSelector = new ThreadLocalContextSelector<EJBClientContext>(
                  new ThreadLocal<EJBClientContext>() {
       
                      @Override
                      protected EJBClientContext initialValue() {
                          return EJBClientContext.create();
                      }
                  });
      
          public static EJBClientContext getEjbClientContext() {
              return threadLocalContextSelector.getCurrent();
          }
      
          public void connect() {
              try {
                  endpoint = Remoting.createEndpoint("ejb-remote-client-endpoint", OptionMap.EMPTY);
      
      
                  endpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(), getConnectionProviderOptions());
      
      
                  final IoFuture<Connection> futureConnection = endpoint.connect(new URI(getProviderUrl()), getConnectionOptions(),
                          new MyCallbackHandler("admin", "admin".toCharArray()));
                  connection = IoFutureHelper.get(futureConnection, CONNECTION_TIMEOUT_SECONDS, TimeUnit.SECONDS);
      
                  EJBClientContext ejbClientContext = getEjbClientContext();
                  ejbClientContext.registerConnection(connection);
                  EJBClientContext.setConstantContext(ejbClientContext);
                  if (isIdentityPerThread()) {
                      // this selector will allow to create and maintain different connection per thread
                      EJBClientContext.setSelector(threadLocalContextSelector);
                  }
      
      
                  EJBClientTransactionContext localUserTxContext = EJBClientTransactionContext.createLocal();
                  EJBClientTransactionContext.setGlobalContext(localUserTxContext);
              }
              catch (Exception e) {
                  e.printStackTrace();
              }
          }
      
      
          /**
           * Close connection - should always be called before finishing application
           */
          public void close() {
              if (connection != null) {
                  try {
                      connection.close();
                  }
                  catch (Exception e) {
                      e.printStackTrace();
                  }
              }
              if (endpoint != null) {
                  try {
                      endpoint.close();
                  }
                  catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
      
      
          public static Hashtable<?, ?> getNamingProperties() {
              Hashtable<String, String> props = new Hashtable<String, String>();
              props.put(Context.URL_PKG_PREFIXES, URL_PKG_PREFIXES);
              return props;
          }
      
          private static OptionMap getConnectionProviderOptions() {
              return OptionMap.create(Options.SSL_ENABLED, SSL_ENABLED, Options.SASL_SERVER_AUTH, SASL_SERVER_AUTH);
          }
      
          private static OptionMap getConnectionOptions() {
              return OptionMap.create(Options.SASL_POLICY_NOPLAINTEXT, SASL_POLICY_NOPLAINTEXT, Options.SASL_POLICY_NOANONYMOUS,
                      SASL_POLICY_NOANONYMOUS);
          }
      
          private String getProviderUrl() {
              return "remote://" + "localhost" + ":" + "4547";
          }
      
          private boolean isIdentityPerThread() {
              return true;
          }
      
      
      }
      
      

       

       

      As soon as I am connecting there is error on cosole:

       

       

      2013-03-27 11:54:13,082 [ejb-client-cluster-node-connection-creation-3-thread-2] INFO  org.jboss.ejb.client.remoting.RemotingConnectionClusterNodeManager (RemotingConnectionClusterNodeManager.java:121) - Could not create a connection for cluster node ClusterNode{clusterName='ejb', nodeName='plklszymikdt:server-two', clientMappings=[ClientMapping{sourceNetworkAddress=/0:0:0:0:0:0:0:0, sourceNetworkMaskBits=0, destinationAddress='137.202.163.63', destinationPort=4547}], resolvedDestination=[Destination address=137.202.163.63, destination port=4547]} in cluster ejb
      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.RemotingConnectionClusterNodeManager.getEJBReceiver(RemotingConnectionClusterNodeManager.java:115)
                at org.jboss.ejb.client.ClusterContext$EJBReceiverAssociationTask.call(ClusterContext.java:406)
                at org.jboss.ejb.client.ClusterContext$EJBReceiverAssociationTask.call(ClusterContext.java:380)
                at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
                at java.util.concurrent.FutureTask.run(FutureTask.java:166)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
                at java.lang.Thread.run(Thread.java:722)
      Caused by: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
                at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:377)
                at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:226)
                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.RemotingConnectionClusterNodeManager.getEJBReceiver(RemotingConnectionClusterNodeManager.java:113)
                ... 7 more
      2013-03-27 11:54:13,082 [Remoting "ejb-remote-client-endpoint" read-1] ERROR org.jboss.remoting.remote.connection (RemoteConnection.java:99) - JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
      2013-03-27 11:54:13,084 [ejb-client-cluster-node-connection-creation-3-thread-1] INFO  org.jboss.ejb.client.remoting.RemotingConnectionClusterNodeManager (RemotingConnectionClusterNodeManager.java:121) - Could not create a connection for cluster node ClusterNode{clusterName='ejb', nodeName='plklszymikdt:server-one', clientMappings=[ClientMapping{sourceNetworkAddress=/0:0:0:0:0:0:0:0, sourceNetworkMaskBits=0, destinationAddress='137.202.163.63', destinationPort=4447}], resolvedDestination=[Destination address=137.202.163.63, destination port=4447]} in cluster ejb
      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.RemotingConnectionClusterNodeManager.getEJBReceiver(RemotingConnectionClusterNodeManager.java:115)
                at org.jboss.ejb.client.ClusterContext$EJBReceiverAssociationTask.call(ClusterContext.java:406)
                at org.jboss.ejb.client.ClusterContext$EJBReceiverAssociationTask.call(ClusterContext.java:380)
                at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
                at java.util.concurrent.FutureTask.run(FutureTask.java:166)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
                at java.lang.Thread.run(Thread.java:722)
      Caused by: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
                at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:377)
                at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:226)
                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.RemotingConnectionClusterNodeManager.getEJBReceiver(RemotingConnectionClusterNodeManager.java:113)
                ... 7 more
      
      

       

      The connection is established and remote method on session beans works. But there is always one node in use. There is no load balancing and no fail-over. I am testing with killing node but then connection is immediatelly closed. Long time ago I am used similar code on JBoss 6 and there was no issue with that.

       

      Could somebody please provide example of working remote client which will be capable to connect to cluster in domain with security credentials etc.

       

      Thanks

        • 2. Re: JBoss remote connection to clustered EJB issue
          Lukasz Szymik Newbie

          Ok, this has provide me lot of information. Thanks a lot. I tried to change client code but now I am getting such error, please find copy below.

          I assume that this is caused by not having MyCallbackHandler with user and password. How could I insert such password here. I have again tried lot of combination. I really missing some full document which will explain lot of complexity around remote connectoin to JBoss 7.

           

           

          ARN: Could not register a EJB receiver for connection to plk-lszymik-dt:4547

          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:119)

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

                    at Main2.main(Main2.java:60)

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

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

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

                    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:117)

                    ... 2 more

          • 4. Re: JBoss remote connection to clustered EJB issue
            Lukasz Szymik Newbie

            I saw that articles long time ago. We start trying to connect to JBoss 7.1.1. Then there was no other choices for me as to go into creation of Endpoint, connector with callback etc. Is there no way to finish example code provided by me to work with cluster. I am still getting Authentication failed if I tried to use JNDI connection.

             

            Thanks

            • 5. Re: JBoss remote connection to clustered EJB issue
              jaikiran pai Master

              Do you really want to establish the connections yourself using JBoss Remoting APIs? If not, let's take a step back and see why you are having problems with the properties based approach.

              • 6. Re: JBoss remote connection to clustered EJB issue
                Lukasz Szymik Newbie

                It will be good for me to get JBoss Remoting APi to work with cluster. This is so, that we have started to work with JBoss6, later with JBoss 7, JBoss 7.1.1, JBoss 7.1.2 and now with JBoss7.1.3 each time we are upgrading because of other issues. Long time ago we were not able to use JNDI connect lookup with JBoss 7 and we managed to do it with JBoss Remoting API. Now we have another issue and we will need to revert to JNDI and check if this will work for us. There is risk that we will face issues with JNDI. I simple running out of excused and I do not know what to say to my manager about one more refactor of code because something is not working as expected in JBoss. I need to have connection to EJB with cluster, SSL, authentication and LDAP. We need to pack user login dialog in GUI application without need to edit some property files manualy for each user. We need to be able to relogin user during working with GUI application (simle log in as different user)

                 

                I really do not kno what do futher with all that complexity of something such simple as getting remote connection to work.

                 

                I tried to provide login and password like:

                properties.put("remote.connection.cmc5102.username", "admin");

                properties.put("remote.connection.cmc5102.password", "admin");

                 

                But this is still not working. How I could apply login credentials for EJB lookup. Is there another user / password combination for JNDI. We are using DatabaseLoginModule but this is defined for our application.

                 

                 

                Thanks

                • 7. Re: JBoss remote connection to clustered EJB issue
                  Lukasz Szymik Newbie

                  I have made one step forward. I was able to remove security realm from remoting configuration:

                   

                  <subsystem xmlns="urn:jboss:domain:remoting:1.1">

                     <connector name="remoting-connector" socket-binding="remoting"/>

                  </subsystem>

                   

                  Then I was able to connect to server with JNDI.

                  I also have tried to provide different security realm for remoting (like Management one) and then I was able to connect as soon as I defined user and password for connection (I provide it for both connections)

                   

                  Is there a was to use JNDI connection with security realm defined as

                   

                  <security-realm name="ApplicationRealm">

                       <authentication>

                            <jaas name="AppLogin"/>

                       </authentication>

                  </security-realm>

                   

                  Where AppLogin has 2 login modules: database one and LDAP one. How to pass security credentials.

                   

                  Further I have session bean with security domain. Where I have to put credentials to get my secured bean to work. I am getting Invalid User always. Is there any way to provide CustomCallbachHandler which will be able to provide user name and password.

                   

                  Thanks
                  Łukasz