1. Three ways to call EJB
The first method of calling EAP 6 EJBs, using the JBoss API, is as follows:
Properties p = new Properties(); p.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false"); p.put("remote.connections", "default"); p.put("remote.connection.default.host", "localhost"); p.put("remote.connection.default.port", "4447"); p.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false"); EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(p); ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc); EJBClientContext.setSelector(selector); Properties props = new Properties(); props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); InitialContext context = new InitialContext(props); final boolean useScopedExample = Boolean.getBoolean("UseScopedContext"); final String rcal = "ejb:jboss-ejb-multi-server-app-main/ejb//" + (useScopedExample ? "MainAppSContextBean" : "MainAppBean") + "!" + MainApp.class.getName(); final MainApp remote = (MainApp) context.lookup(rcal);
This method can be called normally in the Standalone client (client is not running inside of JBoss EAP 6), but in the EAP 6 environment it will report java.lang.SecurityException: EJBCLIENT000021: EJB client context selector may not be changed.
The second method uses the scoped context, the code is as follows:
Properties props = new Properties(); props.put("org.jboss.ejb.client.scoped.context", "true"); props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); //props.put(Context.OBJECT_FACTORIES, "org.jboss.ejb.client.naming.ejb.ejbURLContextFactory"); props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false"); props.put("remote.connections", "default"); props.put("remote.connection.default.port", 4447); props.put("remote.connection.default.host", host); //props.put("remote.connection.default.username", username); //props.put("remote.connection.default.password", password); props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); props.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); Context context = (Context) new InitialContext(props).lookup("ejb:"); try { final TimerExample bean = (TimerExample) context.lookup("TestTimer/TestTimerEJB/TimerExampleBean!org.example.jboss.timer.TimerExample"); bean.doSomething(); } finally { try { context.close(); } catch(Exception e) { } }