Advertise with us

Our eBooks

JBoss AS 7 EJB remote clients without configuration file

In order to lookup a remote EJB 3 with JBoss AS 7 you have to fill in some basic information, such as the host name and remoting port. This is normally achieved using a file named which needs to be placed in the client classpath. However the remote client API does provide some utility classes to perform a lookup without any configuration file.

In order to load the remote configuration, we will store the properties in a standard Properties object and use an org.jboss.ejb.client.EJBClientConfiguration object to provide the configurations that will be used for creating EJB receivers and managing the EJB client context.

Once done with it, we will need to create a ConfigBasedEJBClientContextSelector using the EJBClientConfiguration that we have just created.
This constructor creates a org.jboss.ejb.client.EJBClientContext and uses the passed ejbClientConfiguration to create and associate EJB receivers to that context.

Finally, a proxy for the ejb is created by passing an instance of the StatelessEJBLocator (or of the StatefulEJBLocator if you are running against a Stateful EJB) class to the EJBClient class:

So supposing you are going to recall the following EJB



public class CalculatorRemoteBean implements CalculatorRemote {

 . . . .


Here's the client for it:

Properties pr = new Properties();

pr.put("", "client-endpoint");
pr.put("", "false");
pr.put("remote.connections", "default");
pr.put("remote.connection.default.port", "4447");
pr.put("", "localhost");
pr.put("remote.connection.default.username", "user");
pr.put("remote.connection.default.password", "Password12345");

EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(pr);
final ContextSelector<EJBClientContext> ejbClientContextSelector = new ConfigBasedEJBClientContextSelector(cc);

// Now let's setup the EJBClientContext to use this selector

final ContextSelector<EJBClientContext> previousSelector = EJBClientContext.setSelector(ejbClientContextSelector);              
StatelessEJBLocator<CalculatorRemote> locator = new StatelessEJBLocator(CalculatorRemote.class, "", "calculator-demo", "CalculatorRemoteBean", "");               

CalculatorRemote ejb =  org.jboss.ejb.client.EJBClient.createProxy(locator);

© 2021 All Rights Reserved.

Please publish modules in offcanvas position.