aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes jboss and ejb2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "jboss and ejb2" Watch "jboss and ejb2" New topic
Author

jboss and ejb2

John Gregory
Ranch Hand

Joined: Oct 05, 2006
Posts: 115
I have a servlet which calls an ejb (2.0). When I go to run the
app, I get the following error:

java.lang.ClassCastException
com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
fibo.servlets.FiboServlet.lookupFibonacciBean(FiboServlet.java:78)
fibo.servlets.FiboServlet.doPost(FiboServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

Here's the code I use to lookup my ejb:

private Fibonacci lookupFibonacciBean() {
try {
Context c = new InitialContext();
Object remote = c.lookup("FibonacciBean");
//Object remote = c.lookup("java:comp/env/FibonacciBean");
FibonacciHome fh = (FibonacciHome) javax.rmi.PortableRemoteObject.narrow(remote, compute.FibonacciHome.class);
Fibonacci fib = fh.create();
return fib;
} catch (NamingException ne) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
} catch (CreateException ce) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ce);
throw new RuntimeException(ce);
} catch (RemoteException re) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", re);
throw new RuntimeException(re);
}

I'm sure it has to do with my initial context, but I'm not sure how to
initialize it in a servlet. Both the webapp.war and the ejb.jar file are
on the same server instance.

Can anyone tell me what I need to change?

Thanks,

John
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
Yes Indeed this is a problem with your Initial Context. You need to set the Initialcontext correct with proper environment properties. Try the below code.



Make sure you use the correct Ip Address and port of your Jboss Server.


Amit Tank
Linked In
John Gregory
Ranch Hand

Joined: Oct 05, 2006
Posts: 115
Amit,

Ok, I put those variables in my Context variable. Now, what
happens, is I get an error stating that the compute.do is
not located -- compute.do is the name I gave it on the form
declaration. I know it works because before inserting the
ejb, I had a function that did the same thing. all I did was
remove any reference to the function and inserted the ejb
stuff.

Any ideas?

John
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10048
    
163

If the servlet and the EJB are on the same server then you dont have to pass the properties to the InitialContext constructor. JBoss will use the defaults.


java.lang.ClassCastException
com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)

FibonacciHome fh = (FibonacciHome) javax.rmi.PortableRemoteObject.narrow(remote, compute.FibonacciHome.class);


Are the webapp.war and ejb.jar part of an EAR? Or are they deployed separately?

Also, do have a look at Debug ClassCastException, specifically the jmx-console method mentioned over there.


[My Blog] [JavaRanch Journal]
John Gregory
Ranch Hand

Joined: Oct 05, 2006
Posts: 115
Jaikiran,

They're deployed separately. I haven't tried deploying
as an ear file. Also, would my choice of interfaces matter,
local vs remote?

If using the default is what jboss'll do, then how should
I make the call:

MyHome mh = ctx.lookup("myhome");

In other words, do I need something like ejb/myhome or
something totally different? Like I said, I got this to
work in a regular java client.....I'm just beating my head on
the wall trying to figure this out!

Thanks,

John
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10048
    
163

Originally posted by John Gregory:
Also, would my choice of interfaces matter,
local vs remote?

If the client is within the same JVM as the server then the bean can have either local or remote. So in case of a servlet running in the same server, you can use local bean interfaces. However with Java standalone client, you have to use a remote bean interface.

Originally posted by John Gregory:
If using the default is what jboss'll do, then how should
I make the call:

MyHome mh = ctx.lookup("myhome");

In other words, do I need something like ejb/myhome or
something totally different?


John, sorry i did not understand this question. Can you please explain more?

Originally posted by John Gregory:
Like I said, I got this to
work in a regular java client.....I'm just beating my head on
the wall trying to figure this out!


This gives me an impression that the issue is related to classloading. Probably you are packaging the bean interfaces in both the ejb jar and the war. Post the output of the following two commands:



 
Consider Paul's rocket mass heater.
 
subject: jboss and ejb2