I have an swing application that connects to a Jboss 7 AS. Invoking some background threads causes a no such ejb error on client side. Here is an example
package com.asf.capone.client.util;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.asf.capone.common.exception.AppException;
import ro.asf.capone.ejb.beans.security.SecurityController;
import ro.asf.capone.ejb.beans.security.SecurityControllerRemote;
public class TestJndi {
public static void main(final String[] args) throws AppException {
final Hashtable env = new Hashtable();
env.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
env.put("java.naming.provider.url", "remote://localhost:4447");
env.put("java.naming.security.credentials", "c4ca4238a0b923820dcc509a6f75849b");
env.put("java.naming.security.principal", "capone");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
env.put("jboss.naming.client.ejb.context", "true");
env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
try {
final InitialContext ctx = new InitialContext(env);
System.out.println("ctx: " + ctx);
final SecurityController o = (SecurityControllerRemote) ctx.lookup(
"ejb:agency-ear/agency-ejb/SecurityControllerBean!ro.asf.capone.ejb.beans.security.SecurityControllerRemote");
System.out.println("1outcome: " + o.getServerTimeMillis());
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("2outcome: " + o.getServerTimeMillis());
}
}).start();
} catch (final NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The output for this is:
ctx: javax.naming.InitialContext@307f6b8c
1outcome: 1443465336127
Exception in thread "Thread-4" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:agency-ear, moduleName:agency-ejb, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@381dfddb
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:754)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:253)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:198)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
at com.sun.proxy.$Proxy2.getServerTimeMillis(Unknown Source)
at com.asf.capone.client.util.TestJndi$1.run(TestJndi.java:36)
at java.lang.Thread.run(Thread.java:745)
I am missing something that should allow me to get the same output on both calls but I cannot figure what is the problem. Thanks!
It looks like this doesn't work on that version of Jboss (they've changed the remote) because my initial code worked in Jboss 7.3.0. My current Jboss version is JBoss EAP 6.4.0.GA (AS 7.5.0.Final-redhat-21) The code that works now is:
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.ejb.client.ContextSelector;
import org.jboss.ejb.client.EJBClientConfiguration;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;
import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;
import ro.asf.capone.ejb.beans.security.SecurityControllerRemote;
public class AppJboss {
public static void main(String[] args) throws NamingException {
System.out.println("Hello World!");
final String lookup = "ejb:agency-ear/agency-ejb//SecurityControllerBean!ro.asf.capone.ejb.beans.security.SecurityControllerRemote";
final Properties clientProperties = new Properties();
clientProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS",
"JBOSS-LOCAL-USER");
clientProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT",
"false");
clientProperties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
clientProperties.put("remote.connections", "default");
clientProperties.put("endpoint.name", "client-endpoint");
clientProperties.put("remote.connection.default.port", "4447");
clientProperties.put("remote.connection.default.host", "127.0.0.1");
clientProperties.put("remote.connection.default.username", "capone");
clientProperties.put("remote.connection.default.password", "c4ca4238a0b923820dcc509a6f75849b");
clientProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS",
"false");
final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(
clientProperties);
final ContextSelector<EJBClientContext> contextSelector = new ConfigBasedEJBClientContextSelector(
ejbClientConfiguration);
EJBClientContext.setSelector(contextSelector);
final Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(properties);
final SecurityControllerRemote myBean = (SecurityControllerRemote) context.lookup(lookup);
final long result = myBean.getServerTimeMillis();
System.out.println("result " + result);
new Thread(new Runnable() {
public void run() {
final long result = myBean.getServerTimeMillis();
System.out.println(result);
}
}).start();
}
}
The client library was taken from jboss/bin/client/jboss-client.jar
The same code works in Wildfly also, just with the change of port and client library. Hope this helps others.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments