3.2.10. Remote Invocation Changes Migrate JBoss EAP 5 Deployed Applications That Make Remote Invocations to JBoss EAP 6


In JBoss EAP 5, the EJB remote interface was bound in JNDI, by default, under the name "ejbName/local" for local interfaces, and "ejbName/remote" for the remote interfaces. The client application then looked up the bean using "ejbName/remote".

In JBoss EAP 6, a new specific EJB client API was introduced to do the invocation. However, if you do not want to rewrite your code to use the new API, you can modify the existing code to use the ejb:BEAN_REFERENCE for remote access to EJBs with the following syntax.
For stateless beans, the ejb:BEAN_REFERENCE syntax is:
For stateful beans, the ejb:BEAN_REFERENCE syntax is:
The values to be substituted in the above syntax are:
  • <app-name> - the application name of the deployed EJBs. This is typically the ear name without the .ear suffix, however, the name can be overridden in the application.xml file. If the application is not deployed as a .ear, this value is an empty string. Assume this example was not deployed as an EAR.
  • <module-name> - the module name of the deployed EJBs on the server. This is typically the jar name of the EJB deployment, without the .jar suffix, but can be overridden using the ejb-jar.xml. In this example, assume the EJBs were deployed in a jboss-ejb-remote-app.jar, so the module name is jboss-ejb-remote-app.
  • <distinct-name> - an optional distinct name for the EJB. This example does not use a distinct name, so it uses an empty string.
  • <bean-name> - by default, is the simple class name of the bean implementation class.
  • <fully-qualified-classname-of-the-remote-interface> - the remote view fully qualified class name.
Update the client code

Assume you have deployed the following stateless EJB to a JBoss EAP 6 server. Note that it exposes a remote view for the bean.

public class CalculatorBean implements RemoteCalculator {
    public int add(int a, int b) {
        return a + b;
    public int subtract(int a, int b) {
        return a - b;
In JBoss EAP 5, the client EJB lookup and invocation was coded something like this:
InitialContext ctx = new InitialContext();
RemoteCalculator calculator = (RemoteCalculator) ctx.lookup("CalculatorBean/remote");
int a = 204;
int b = 340;
int sum = calculator.add(a, b);
In JBoss EAP 6, using the information described above, the client lookup and invocation is coded like this:
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);
final String appName = "";
final String moduleName = "jboss-ejb-remote-app";
final String distinctName = "";
final String beanName = CalculatorBean.class.getSimpleName();
final String viewClassName = RemoteCalculator.class.getName();
final RemoteCalculator statelessRemoteCalculator =  (RemoteCalculator) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
int a = 204;
int b = 340;
int sum = statelessRemoteCalculator.add(a, b);
If your client is accessing a stateful EJB, you must append "?stateful" to the end of the context lookup like this:
final RemoteCalculator statefulRemoteCalculator =  (RemoteCalculator) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName + "?stateful")

A complete working example, including both server and client code, can be found in the Quickstarts. For more information, refer to Review the Quickstart Tutorials in the chapter entitled Get Started Developing Applications in the Development Guide for JBoss EAP 6 on https://access.redhat.com/site/documentation/JBoss_Enterprise_Application_Platform/.
For more information on remote invocations using JNDI, refer to Section, “Invoke a Session Bean Remotely using JNDI” .