EJB remoting – JBoss 6 – Wildfly9

Jelena Lazić

PROBLEM

The ability to call remote EJB across different versions of JBoss/Wildfly AS is not supported.

In order to call remote EJB, you’ll need a client library. This client library contains classes that are normally part of application server. When the client is standalone (Java SE) application, this is correct solution, but when the client is another Java EE application server this is not possible, since many classes are clashing.

The only exception is when the application servers are the exact same version, since no client library is needed then.

SOLUTION

Try to emulate standalone EJB client for target server.

Make remote EJB call in isolation from application server classloader and add only client libraries needed from another server.

PATH TO SOLUTION

In search for a solution, we stumbled upon a Carlo de Wolf (RedHat) blog (http://wolf-71.blogspot.rs/2010/02/et-phone-home.html) which addresses similar problem. The most important part was AluniteClassLoader class, which has no parent class loader and delegates to given class loaders in turn.

Also, very important was the correct way of including our own interface to be accessible to classloader, to avoid dreaded ClassCastExceptions.

PROOF OF CONCEPT

Cross-server communication project (https://github.com/infobip/jboss-wildfly-remoting)

  • 1 JAR module – cross-server-common, with IConnector remote interface, and JndiHandler class
  • 1 EJB module – cross-server-ejb-jboss6, with one implementation of IConnector, targeted for JBoss6
  • 1 EJB module – cross-server-ejb-wildfly9, with one implementation of IConnector, targeted for Wildfly9
  • 1 EAR module – profile-based build:
    • wildfly9 profile builds ear with cross-server-common, and cross-server-ejb-wildfly9
    • jboss6 profile builds ear with cross-server-common, and cross-server-ejb-jboss6 and excludes deployment descriptor jboss-deployment-structure.xml from ear

IConnector interface has two methods, hello() and answer(). Each hello() calls answer() on another server instance.

JndiHandler class has 3 methods, one for standard JBoss6 lookup, and two methods for Wildfly9 – for EJB client API based lookup, and for http-remoting style lookup based on jboss-remote-naming project:

lookupJboss6

		
	

lookupWildfly9 (EJB client API)

		
	

If you choose to use EJB client lookup, client must have jboss-ejb-client.properties on classpath.

lookupWildfly9HttpRemoting (jboss-remote-naming)

		
	

Each server needs to have client libraries from another server on local machine, but not deployed on application server.

Let’s start two application servers.

Let’s say we start JBoss6 AS on standard 8080 port, and Wildfly with port-offset 100.

JBOSS6-WILDFLY9 COMMUNICATION IN HELLO METHOD:

		
	

WILDFLY9-JBOSS6 COMMUNICATION IN HELLO METHOD:

		
	

AND MAGIC HAPPENS…

When we run Junit test in cross-server-wildfly9:

IConnector connector = (IConnector) lookup (“localhost”, “8180”); connector.hello(“Infobip”);

And similar, Junit test in cross-server-jboss6:

IConnector connector = (IConnector) lookup(“localhost”, “8080”); connector.hello(“Infobip”);

(By Jelena Lazic, Software Engineer)

Dec 28th, 2015
3 min read

Jelena Lazić