File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI lookup for local SLSB interface?

 
Johann Dobbins
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic