wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes JNDI lookup for local SLSB interface? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JNDI lookup for local SLSB interface?" Watch "JNDI lookup for local SLSB interface?" New topic
Author

JNDI lookup for local SLSB interface?

Johann Dobbins
Ranch Hand

Joined: Oct 16, 2008
Posts: 62
Hi, I am new to EJB3 and am unsure if this is possible, any help would be greatly appreciated.


Say I have a public interface MyInterface which has some methods and a string:

public final static String JNDI_NAME = ".../ejb/MySlsb/remote"


And then I have a slsb MySlsb that implements MyInterface and has a string:

public final static String NAME = "MySlsb"


now, I have a test class that is running outside the container. in this test i can instantiate a MyInterface by:

InitialContext ctx = new InitialContext();
MyInterface myInterface = (MyInterface) ctx.lookup(MyInterface.JNDI_NAME);


however, i would like to implement some methods in MySlsb that i don't want to expose in MyInterface, so, in order to call these methods i need to instantiate a MySlsb object, not a MyInterface object. (simply casting MyInterface object to MySlsb does not work, this throws a class cast exception at runtime, having something to do with wrapper classes...)

is there anyway to instantiate the MySlsb object?

thank you

[ October 16, 2008: Message edited by: Johann Dobbins ]
[ October 16, 2008: Message edited by: Johann Dobbins ]
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Johann,

The way to do this right now would be to have another interface specific for testing. You can deploy this interface via a deployment descriptor without changing the actual EJB implementation and use the descriptor only for testing purposes.

If you don't need container services anyway, you can just instantiate the bean class with "new". That's often the case with internal unit test cases which is what I suspect you are talking about. Otherwise, why have a method that's not client invokable :-)

Cheers,
Reza

P.S.: In EJB 3.1, interfaces are optional, so if you really want to, you can look up the bean class directly. All public methods are automatically invokable.


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI lookup for local SLSB interface?