I have a question regarding the tutorial at the following link:
http://www.netbeans.org/kb/41/j2ee-server-integration.html I coded my
ejb, a simple stateless session bean and deployed it to a
jboss server. I then wrote client code, the guts of which is:
Integer ii = new Integer(args[0]);
int x = ii.intValue();
Properties p = new Properties();
p.load(new FileInputStream("jndi.properties"));
InitialContext ic = new InitialContext(p);
Object o = ic.lookup("FibonacciBean");
FibonacciHome home = (FibonacciHome) PortableRemoteObject.narrow(o, FibonacciHome.class);
Fibonacci f = home.create();
double [] fs = f.compute(x);
viola, it works, just as I'd expect it to.
Then, I decided to write a
servlet which did the same thing as my main.
It looks like:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
String anum = request.getParameter("limit");
int num = Integer.parseInt(anum);
Fibonacci f = lookupFiboBean();
double[] fibo = f.compute(num);
request.setAttribute("sequence", fibo);
RequestDispatcher view = request.getRequestDispatcher("response.jsp");
view.forward(request, response);
} catch (RemoteException ex) {
ex.printStackTrace();
}
}
private Fibonacci lookupFiboBean() {
try {
Context c = new InitialContext();
Object o = c.lookup("java:comp/env/FibonacciBean");
FibonacciHome home = (FibonacciHome) PortableRemoteObject.narrow(o, FibonacciHome.class);
return home.create();
} 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);
}
}
Now, when I deploy (it deploys ok) and run it, the index.jsp page shows
up and when I do the compute, 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)
servlets.FiboServlet.lookupFiboBean(FiboServlet.java:45)
servlets.FiboServlet.doPost(FiboServlet.java:28)
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)
root cause
java.lang.ClassCastException: $Proxy58 cannot be cast to org.omg.CORBA.Object
com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)
javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
servlets.FiboServlet.lookupFiboBean(FiboServlet.java:45)
servlets.FiboServlet.doPost(FiboServlet.java:28)
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)
Can anyone suggest a reason why? At one point, I DID get this to work
fine, I just can't remember what I did to do so? Is there some client
jar file I need loaded?
Thanks,
John