Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JNDI Lookup of local EJB (no @EJB)

I have a requirement where I'm asked to load both remote and local EJBs with a JNDI lookup, so without the @EJB annotation.

My EJB is defined as follows:

@Remote
public interface MyObjectInterfaceRemote extends MyObjectInterface {

}

@Local
public interface MyObjectInterfaceLocal extends MyObjectInterface {

}

public interface MyObjectInterface {
    // A bunch of methods which both remote and local ejbs will inherit
}

@Remote(MyObjectInterfaceRemote.class)
@Local(MyObjectInterfaceLocal.class)
public class MyObjectEJB implements MyObjectInterfaceLocal, MyObjectInterfaceRemote {
    //implementation of all methods inherited from MyObjectInterface.
}

I'm using this code to lookup the remote EJB:

private MyObjectInterfaceRemote getEJB() throws NamingException {
    InitialContext context = new InitialContext();
    return (MyObjectInterfaceRemote) context.lookup(MyObjectInterfaceRemote.class.getName());
}

It works fine, but if I make another method like this:

private MyObjectInterfaceLocal getLocalEJB() throws NamingException {
    InitialContext context = new InitialContext();
    return (MyObjectInterfaceLocal) context.lookup(MyObjectInterfaceLocal.class.getName());
}

I get

javax.naming.NameNotFoundException: 
Context: Backslash-PCNode03Cell/nodes/Backslash-PCNode03/servers/server1, 
name: MyObjectInterfaceLocal: First component in name MyObjectInterfaceLocal not found. 
[Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: 
IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
[...]

What am I missing? Do I have to use something different to lookup a local ejb?

Note: If I use

@EJB
MyObjectInterfaceLocal ejb;

The local ejb gets succesfully loaded.

like image 291
BackSlash Avatar asked Mar 17 '23 19:03

BackSlash


1 Answers

Have you tried below code?

context.lookup("ejblocal:"+MyObjectInterfaceLocal.class.getName())

Webshpere uses different default binding pattern for remote and local interfaces.

like image 123
slwk Avatar answered Mar 29 '23 05:03

slwk