How to change my standalone client's remote ejb configuration to not reference org.jboss.ejb.client in JBoss EAP 7.1

Solution Verified - Updated

Environment

Red Hat JBoss Enterprise Application Platform (EAP) 7.1

Issue

  • How to change my standalone client's remote ejb configuration to not reference org.jboss.ejb.client in JBoss EAP 7.1
  • We are getting ClassNotFoundException org.jboss.ejb.client.EJBClientConfiguration when migrating an application to JBoss EAP 7.1
Caused by: java.lang.ClassNotFoundException: org.jboss.ejb.client.EJBClientConfiguration from [Module "deployment.application.ear" from Service Module Loader]
  at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
  at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
  at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
  ... 60 more 
  • We were using the PropertiesBasedEJBClientConfiguration configuration in JBoss EAP 6.x / 7.0 for our standalone application to call a remote EJB in JBoss EAP, is it possible to not depend on the org.jboss.ejb.client classes?
import org.jboss.ejb.client.EJBClientConfiguration;
import org.jboss.ejb.client.ContextSelector;
import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;

private void setupEJBContext(String host, String port, String username, String password) {
  Properties p = new Properties();           
  p.put("remote.connections", "default");
  p.put("remote.connection.default.host", host);
  p.put("remote.connection.default.port", port);
  p.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
  p.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
  p.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
  p.put("remote.connection.default.username", username);
  p.put("remote.connection.default.password", password);
   
  EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(p);
  ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc);
  EJBClientContext.setSelector(selector);
}
public void invokeEJB(String host, String port, String username, String password) {
  setupEJBContext(host, port, username, password);
  Properties env = new Properties();
  env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
  InitialContext ctx = new InitialContext(env);
  Hello ejbObject = (Hello) ctx.lookup("ejb:/ejb-client//Hello!jboss.example.ejb.Hello");
  System.out.println("Response: " + ejbObject.sayHello());
}

Resolution

In JBoss EAP 7.1, it has some enhancements for making it easier to setup and make remote EJB calls.
In EAP 7.1 you can just pass the Properties into new InitialContext(...) and remove the references to the org.jboss.ejb.client classes as shown below.

private Context setupEJBContext(String host, String port, String username, String password) {
  Properties p = new Properties();           
  p.put("remote.connections", "default");
  p.put("remote.connection.default.host", host);
  p.put("remote.connection.default.port", port);
  p.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
  p.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
  p.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
  p.put("remote.connection.default.username", username);
  p.put("remote.connection.default.password", password);

  p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
  return new InitialContext(p);  
}
public void invokeEJB(String host, String port, String username, String password) {
  Context ctx = setupEJBContext(host, port, username, password);
  Hello ejbObject = (Hello) ctx.lookup("ejb:/ejb-client//Hello!jboss.example.ejb.Hello");
  System.out.println("Response: " + ejbObject.sayHello());
}

[1] How configure an EJB client in EAP 7.1

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.