LookUp remote EJB from local EJB
fargus Jul 6, 2012 9:42 AMHello
Please help me with my problem.
I have many servers and one main server that should manage others. All servers is JBoss AS 7.1.1Final and deployed same ear file.
Main server can administrate remote servers and should use ejb of these servers.
Inside of ebj on main server i use next code for lookup remote ejb:
final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory"; String PROVIDER_URL = "remote://" + host + ":4447"; Properties connectProperties = new Properties(); connectProperties.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); connectProperties.put(Context.PROVIDER_URL, PROVIDER_URL); connectProperties.put("jboss.naming.client.ejb.context", "true"); connectProperties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); connectProperties.put(Context.SECURITY_PRINCIPAL, "admin"); connectProperties.put(Context.SECURITY_CREDENTIALS, "admin"); Environment env = null; try { InitialContext initialContext = new InitialContext(connectProperties); env = (Environment) initialContext.lookup("es-ear/es-core/Environment!com.service.Environment"); } catch (Exception e) { e.printStackTrace(); } return env;
but getting next error:
17:26:03,782 ERROR [stderr] (DefaultQuartzScheduler_Worker-1) javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jboss.nami
g.remote.client.InitialContextFactory from classloader ModuleClassLoader for Module "deployment.es-ear.ear.es-core-0.0.1-SNAPSHOT.jar:main" from Service Module
Loader♪
17:26:03,782 ERROR [stderr] (DefaultQuartzScheduler_Worker-1) at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextF
ctoryBuilder.java:64)♪
17:26:03,782 ERROR [stderr] (DefaultQuartzScheduler_Worker-1) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:681)♪
17:26:03,798 ERROR [stderr] (DefaultQuartzScheduler_Worker-1) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)♪
17:26:03,798 ERROR [stderr] (DefaultQuartzScheduler_Worker-1) at javax.naming.InitialContext.init(InitialContext.java:242)♪
17:26:03,798 ERROR [stderr] (DefaultQuartzScheduler_Worker-1) at javax.naming.InitialContext.<init>(InitialContext.java:216)♪
If I use "org.jboss.as.naming.InitialContextFactory" as context factory I dont get any errors but any lookup returns instance from local server, not from remote.
How I can invoke remote ejb methods inside local ejb, if i dynamically add remote servers and cant edit config files?