JBoss remote connection to clustered EJB issue
lszymik Mar 27, 2013 7:08 AMHello,
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