• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jboss and ejb2

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
John Gregory
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
John Gregory
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic