• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet accessing Session Bean (sic)

 
Alex Nunez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!

I've got a problem with the topic above.

I've got a servlet accessing to a ssesion bean (facade). When tested with a POJO local client it works fine. Though, I've this ugly exception when trying it with a servlet executing remotely, in another app:

java.lang.ClassCastException at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)


I am executing all this in Sun Java Studio Enterprise IDE, which uses Tomcat 4.1 and Sun Application Server 7.

I've got in my WEB-INF/lib/ folder the files j2ee-1.3.jar and the jar file of my bean module (package StockBeans).

This is the code for the lookup:

----------------------------------------

StockBeans.Stock myStock;
StockBeans.StockHome home;


try{

Context initial = createInitialContext();
Object objRef = initial.lookup("ejb/Stock");
System.out.println(objRef.getClass().getName());

home = (AlmacenBeans.AlmacenHome) PortableRemoteObject.narrow(objRef, StockBeans.StockHome.class);

myStock = home.create();

myStock.someMethod();

}catch (Exception e){}


private static InitialContext createInitialContext() throws NamingException {
Properties env = new Properties();

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://127.0.0.1:49152");

return new InitialContext(env);
}

--------------------------------------

The problem is that the servlet does access to the EJB jar file, because if I put it away, I get a NoClassDefFoundError. Plus, the servlet does connect to the orb listener of my webapp (if I type another port I get an exception) and the server can see my deployed application (if I undeploy it... guess what).

Where's the problem then??

Thanks in advance!!!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex,
Welcome to JavaRanch!

I suspect that "ejb/Stock" is the JNDI name for the local interface and not the remote interface. It looks like you may have suspected this with the line:

What did this output?
 
Alex Nunez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your prompt reply!

hmm... I don't think so... take a look at my web.xml (and sorry, I forget the output of my code!)...

Output of System.out: com.sun.corba.ee.internal.iiop.CDRInputStream_1_0$1
(looks ok?)

And the web.xml fragment:

<ejb-ref-name>ejb/Stock</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>StockBeans.StockHome</home>
<remote>StockBeans.Stock</remote>
</ejb-ref>

In the ejb jar file, Stock extends EJBObject and StockHome extends EJBHome (it's remote for sure). His JNDI Name is "ejb/Stock". May the error be produced because the JNDI name of the bean is the same as when I try to lookup? Or is it mandatory?
 
Alex Nunez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Lord!

I solved my problem.

I was using an ejb jar created with "export ejb jar". I didn't noticed that when the module is inside an application, another option comes up: "export client ejb jar".

I feel so stupid. All this time wasted...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex,
Ah! Thanks for posting the solution for others who read this in the future.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic