Remote clustered EJB invocation via JNDI
dweil Nov 16, 2012 11:31 AMIn our projects we have to use the JNDI style invocations of EJBs as described in https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project.
So we connect to the server and call EJBs like that:
Properties prop = new Properties(); prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); prop.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER"); prop.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", false); prop.put("jboss.naming.client.ejb.context", true); prop.setProperty(Context.PROVIDER_URL, "remote://localhost:4447"); prop.setProperty(Context.SECURITY_PRINCIPAL, "user"); prop.setProperty(Context.SECURITY_CREDENTIALS, "pwd"); InitialContext ctx = new InitialContext(prop);
Counter counter = (Counter) ctx.lookup("/showServer/CounterBean!de.gedoplan.seminar.demo.ejb.Counter");
counter.doSomething();
It works without problems for nonclusterd EJBs.
If I make the EJB clustered (i. e. use @Clustered or the equivalent jboss-ejb3.xml entry) the code above fails with
Exception in thread "main" java.lang.IllegalStateException: No EJB receiver contexts available in cluster ejb at org.jboss.ejb.client.EJBClientContext.requireClusterEJBReceiverContext(EJBClientContext.java:751) at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:87) at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121) at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104) at $Proxy0.getCounterAndServerDescription(Unknown Source) at de.gedoplan.seminar.demo.ejb.CounterClient.main(CounterClient.java:26)
I tried to add the file jboss-ejb-client.properties to the classpath as shown in https://docs.jboss.org/author/display/AS71/Clustered+EJBs - same result.
The JBoss version used is 7.1.3.Final.
So: what properties exactly have to be specified for constructing InitialContext and what exactly has to be in jboss-ejb-client.properties to enable clustered EJB calls when using the JNDI client API approach?
Thank you
Dirk