• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

access ejb from outside container

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Is it possible to access a stateless session bean or any other bean type from outside the EJB container?

I tried to do a look-up of a deployed ejb in Weblogic from a standalone Java program and had some problems, below is the stack trace of exception:

Exception in thread "main" java.lang.ClassCastException: Cannot narrow remote object weblogic.rmi.internal.BasicRemoteRef - hostID: '-5351748351393873728S:127.0.0.1:[7001,7001,-1,-1,-1,-1,-1]:myDomain10:AdminServer', oid: '286', channel: 'null' to com.titan.travelagent.TravelAgentRemote
at weblogic.corba.server.naming.ReferenceHelperImpl.narrow(ReferenceHelperImpl.java:206)
at weblogic.rmi.extensions.PortableRemoteObject.narrow(PortableRemoteObject.java:88)
at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteObjectDelegateImpl.java:32)
at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at com.titan.clients.Client.main(Client.java:30)


Below is the code that seems to cause the excepption:

TravelAgentRemote dao = (TravelAgentRemote)
PortableRemoteObject.narrow(ref,TravelAgentRemote.class);

I would like to know if this should be possible and if so is it good practice to use EJB from outside the application server where its deployed?

Thanks,

J.C
 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
J.C.,

You can absolutely use EJBs outside the container. Indeed, that's one of the core EJB value propositions. On the exception that you are getting -- are you talking about EJB 2 or EJB 3? There is no need for the additional "narrow" call on EJB 3 remote objects.

Best regards,
Reza
 
James Clarke
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Reza,

Iam using EJB 3.0. the more complete version of the code I have given above:

Context jndiContext = getInitialContext( );
Object ref = jndiContext.lookup("EJBSample1titan_jarTravelAgentBean_TravelAgentRemote");//"TravelAgentBeanJ/remote"
print(ref.getClass().toString());
print("remote classloader:"+ref.getClass().getClassLoader().toString());
print("thread classloader:"+Thread.currentThread().getContextClassLoader().toString());
TravelAgentRemote dao = (TravelAgentRemote)ref;

output:
> class com.titan.travelagent.TravelAgentBean_12ko68_TravelAgentRemoteImpl_1001_WLStub
> remote classloader:weblogic.utils.classloaders.GenericClassLoader@af993e finder:
> weblogic.utils.classloaders.CodeGenClassFinder@f6ac0b annotation:
> local classloader:sun.misc.Launcher$AppClassLoader@a39137
> remote classloader:weblogic.utils.classloaders.GenericClassLoader@af993e finder:
> weblogic.utils.classloaders.CodeGenClassFinder@f6ac0b annotation:
> Exception in thread "main" java.lang.ClassCastException: com.titan.travelagent.TravelAgentBean_12ko68_TravelAgentRemoteImpl_1001_WLStub
at com.titan.clients.Client.main(Client.java:29)

Any idea what needs be changed?

Thanks,
James
 
Reza Rahman
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,

Looks like a class-loader issue. If your code is running in the web container, you need to make sure the interface classes are not duplicated (copied) in the web app classpath. Instead, you'll need to refer to the EJB-JAR as a web application module, so the app server class-loader loads in the interface class only once.

Cheers,
Reza
 
James Clarke
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Reza,

The code thats looking up and trying to invoke the session bean is a stand-alone Java program as I mention in my first post.. any ideas how to get around this?

Thanks,
James
 
Reza Rahman
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,

Unfortunately, not off-hand. It looks like a class-loader issue (the interface implemented by the bean is not the "same" as the interface you are casting to). The other alternative is that you are looking up the wrong EJB. You might want to try explicitly specifying mappedName: http://forums.bea.com/thread.jspa?threadID=300004729. It's difficult to tell for sure, but I would say you might be looking at a WLS specific issue.

Cheers,
Reza
 
James Clarke
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem solved. The client stub used by weblogic need to be created and included in client classpath and the stub name should be used as the type when declaring+casting the object that results from the JNDI lookup.

Only tihng I dont like about this is the stub name is: TravelAgentBean_12ko68_TravelAgentRemoteImpl_1001_WLStub (very long!)

I have no idea how to inform WL to use a different name.

Thanks,

J.C
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic