You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Yann Blazart <ya...@bycode.fr> on 2014/11/21 14:23:06 UTC

Remote EJB informations

Just to share some thing.

To access to a remote EJB, the doc show you can use a JndiProvider et an
@EJB annotation with a mapped name.

*This is non portable.*

To make it usable, in a portable manner I'm using it following theses
principles :

public String testRemote() {
        RemoteCalc remoteCalc;
        try {
            Properties properties = new Properties();
            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,

"org.apache.openejb.client.RemoteInitialContextFactory");
            properties.setProperty(Context.PROVIDER_URL,
                    "http://127.0.0.1:8080/tomee/ejb");
            final InitialContext initialContext = new
InitialContext(properties);
            remoteCalc = (RemoteCalc)
initialContext.lookup("global/chaton-serv/chaton-serv-web/RemoteCalcImpl!fr.bpi.chaton.chaton.remoteinterface.RemoteCalc");
            return "" + remoteCalc.calc(14, 15);
        } catch (NamingException ex) {
            return "ERR:" + ex.getMessage();
        }
    }

Of course, the properties for the initialContext could be loaded somewhere
else,
And the lookup parameter should be parameterized too.
With this you can use the load balacing too.

But, it could be better to use <JndiProvider> and make it possible to use
something like

initialContext.lookup("jndi:ext://provider/mybean")