Cannot call an EJB from a remote client via the ejb client context API programatic approach
crytek Sep 30, 2013 12:38 PMHello,
I am trying to call an EJB from a remote client via the ejb client context context programmatic approach. So my code looks like this:
protected static InitialContext getInitialContext(String host, int port, String user, String pwd) {
final Properties clientProps = new Properties();
clientProps.put("remote.connections", "default");
clientProps.put("remote.connection.default.host", host);
clientProps.put("remote.connection.default.port", port);
clientProps.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS","false");
clientProps.put("remote.connection.default.username", user);
clientProps.put("remote.connection.default.password", pwd);
clientProps.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED","false");
clientProps.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
final EJBClientConfiguration ejbClientConf = new PropertiesBasedEJBClientConfiguration(clientProps);
final ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(ejbClientConf);
final ContextSelector<EJBClientContext> previousSelector = EJBClientContext.setSelector(selector);
final Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProps.put("jboss.naming.client.ejb.context", true);
InitialContext initialCtx = null;
try {
initialCtx = new InitialContext(jndiProps);
} catch (NamingException e) {
throw new RuntimeException(e);
}
return initialCtx;
}
and in another class, I am invoking the getInitialContext() method from above:
public static void init() throws NamingException {
InitialContext ctx1 = getInitialContext(CLUSTER_NODE1, CLUSTER_REMOTING_PORT,
APP_USER, APP_PWD);
InitialContext ctx2 = getInitialContext(CLUSTER_NODE2, CLUSTER_REMOTING_PORT,
APP_USER, APP_PWD);
MyBeanFacade1 = (MyBeanFacade1) ctx1
.lookup(MyBeanFacade1.JNDI_PATH);
MyBeanFacade2 = (MyBeanFacade2) ctx2
.lookup(MyBeanFacade2.JNDI_PATH);
}
This way, I am NOT using the jboss-ejb-client.properties file anymore. But, when I'm executing the program, I get the following error:
(I am using JbossAs 7.2.0.Final and main dependencies: jboss-ejb-client-1.0.16.Final.jar, jboss-remote-naming-1.0.5.Final.jar)
The error is genereted by the " InitialContext ctx1 = getInitialContext(...." line.
Am I missing something ?
Sep 30, 2013 7:13:40 PM org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.7.GA
Sep 30, 2013 7:13:40 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.7.GA
Sep 30, 2013 7:13:40 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.14.GA
Sep 30, 2013 7:13:40 PM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers
WARN: Could not register a EJB receiver for connection to @@@_your_host_@@@:4447
java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Net.java:85)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:597)
at org.xnio.nio.NioXnioWorker.connectTcpStream(NioXnioWorker.java:310)
at org.xnio.XnioWorker.connectStream(XnioWorker.java:184)
at org.jboss.remoting3.remote.RemoteConnectionProvider.connect(RemoteConnectionProvider.java:194)
at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:296)
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)
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.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:90)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:73)
at com.oneandone.qatro.spp_stylish_testsuite.timers_integration_tests.util.ZestUtil.getInitialContext(ZestUtil.java:45)
at com.oneandone.qatro.spp_stylish_testsuite.timers_integration_tests.ClusteredTimerTest.init(ClusteredTimerTest.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)