[jboss-user] [EJB 3.0] - Re: java.lang.RuntimeException: java.lang.ClassCastException

ookami2110 do-not-reply at jboss.com
Thu Jul 9 10:30:58 EDT 2009


Hi,

I ran into the same problem.
But in my case the scoping didn't solve the problem.

I'm running two jboss servers:
One on a virtual machine (ubuntu-jeos, jboss5.1.0 GA). The other one on my windows (winXP, jboss5.0.1 GA).
I am developing 2 Applications on my windows with NetBeans6.7.
The fist is a Java EE project with one stateless session bean:

RemoteInterface:

  | 
  | package de.aco.avc.ejb;
  | import javax.ejb.Remote;
  | 
  | @Remote
  | public interface SessionBeanRemote {
  | 
  |     public String sayHello();
  | }
  | 
  | 

The Bean:

  | 
  | package de.aco.avc.ejb;
  | 
  | import javax.ejb.Stateless;
  | 
  | @Stateless
  | public class SessionBean implements SessionBeanRemote {
  | 
  |     public String sayHello()
  |     {
  |         String hello = "IT WORKS!";
  |         return hello;
  |     }
  | 
  | }
  | 

First I 'm deploying this project on my windows jboss server. After that I'm sending the [PROJECT].ear file to the remote jboss on my linux which binds the jndi names like that:


  | +- EE-AVC (class: org.jnp.interfaces.NamingContext)
  |   |   +- SessionBean (class: org.jnp.interfaces.NamingContext)
  |   |   |   +- remote (class: Proxy for: de.aco.avc.ejb.SessionBeanRemote)
  |   |   |   +- remote-de.aco.avc.ejb.SessionBeanRemote (class: Proxy for: de.aco.avc.ejb.SessionBeanRemote)
  | 

The second application is a java web project with one servlet to call the remote methods. It contains the .jar file of the EE application mentioned above plus:

  * servlet-api.jar
  * jbossall-client.jar
  * jboss-j2ee.jar
  * jboss-ejb3-proxy-client.jar


  | 
  | package de.aco.avc.web;
  | 
  | import de.aco.avc.ejb.SessionBean;
  | import de.aco.avc.ejb.SessionBeanRemote;
  | import java.io.IOException;
  | import java.io.PrintWriter;
  | import java.util.Properties;
  | import java.util.logging.Level;
  | import java.util.logging.Logger;
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | import javax.rmi.PortableRemoteObject;
  | import javax.servlet.ServletException;
  | import javax.servlet.http.HttpServlet;
  | import javax.servlet.http.HttpServletRequest;
  | import javax.servlet.http.HttpServletResponse;
  | 
  | public class AServlet extends HttpServlet {
  | 
  |     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  |     throws ServletException, IOException {
  |         response.setContentType("text/html;charset=UTF-8");
  |         PrintWriter out = response.getWriter();
  |         String hello = "DOESNT WORK";
  |         //String object = "NO OBJECT";
  |         try {
  |             try {
  | 
  |                 Properties props = new Properties();
  |                 props.setProperty("java.naming.factory.initial",
  |                                          "org.jnp.interfaces.NamingContextFactory");
  |                 props.setProperty("java.naming.factory.url.pkgs",
  |                                          "org.jboss.naming:org.jnp.interfaces");
  | 
  |                 //HOST
  |                 props.setProperty("java.naming.provider.url", "jnp://ubuntu-jeos.it-ng.local:1099");
  | 
  |                 /*DEBUG
  |                 InitialContext icx = new InitialContext(props);
  |                 Object obj = (Object)icx.lookup("EE-AVC/SessionBean/remote");
  |                 object = obj.toString();
  |                 */
  | 
  | 
  | 
  |                 SessionBeanRemote sbr = (SessionBeanRemote)icx.lookup("EE-AVC/SessionBean/remote");
  |                 hello = sbr.sayHello();
  | 
  | 
  |             } catch (NamingException ex) {
  |                 Logger.getLogger(AServlet.class.getName()).log(Level.SEVERE, null, ex);
  |             }
  | 
  | 
  |             out.println("<html>");
  |             out.println("<head>");
  |             out.println("<title>Servlet AServlet</title>");
  |             out.println("</head>");
  |             out.println("<body>");
  |             out.println("<h1>Servlet AServlet at " + request.getContextPath () + "</h1>");
  |             //out.println("<h2>" + object +"</h2>");
  |             out.println("<h2>" + hello +"</h2>");
  |             out.println("</body>");
  |             out.println("</html>");
  |  

I am running and deplying this application on my windows.
The lookup works perfect but I can't cast the remote object reference to my SessionBeanRemote object. 
Jboss throws an exception:

  | java.lang.ClassCastException: javax.naming.Reference cannot be cast to de.aco.avc.ejb.SessionBeanRemote
  | 

For scoping I edited the jboss-app.xml for the EE project like this:

  |     <loader-repository>
  |         de.aco.avc.ejb:loader=Loader1
  |     </loader-repository>
  | 
  | 
And the jboss-app.xml for the web project:

  |   <class-loading>
  |       <loader-repository>de.aco.avc.web:loader=Loader2</loader-repository>
  |   </class-loading>
  | 

I don't have any clue what i'm doing wrong. I also tried to run both applications on the same jboss, which works fine.

I hope this is enough information for you guys to see what my fault is.

Thanks,
Basti


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4242642#4242642

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4242642



More information about the jboss-user mailing list