[jboss-user] [EJB 3.0] - java.lan.ClassCastException when casting to remote bean inte

manemannen do-not-reply at jboss.com
Wed Nov 19 14:47:03 EST 2008


I get a ClassCastException when trying to cast to a remote interface of stateful session bean (for some reason it works for the stateless ones..). To really pinpoint the problem I made the easiest project possible.

At the server application I have the following bean

@Stateful
  | public class SimpleStatefulBean implements SimpleStatefulBeanRemote, SimpleStatefulBeanLocal {
  | 
  | 	public SimpleStatefulBean() {
  | 	}
  | 
  | 	@Override
  | 	public boolean isSimple() {
  | 		return true;
  | 	}
  | }

The remote interface looks like this:

@Remote
  | public interface SimpleStatefulBeanRemote {
  | 	public boolean isSimple();
  | }
  | 

On the client side I have a web application. It is running on the same JBoss AS but is not deployed in the EAR as the bean above. I created a servlet to access the bean. 
In the doGet methods of the servlet..

  | 	try {
  | 			Properties p = new Properties();
  | 			p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  | 			p.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  | 			p.put("java.naming.provider.url", "localhost");
  | 			Context ctx = new InitialContext(p);
  | 			SimpleStatefulBeanRemote o = (SimpleStatefulBeanRemote) ctx.lookup("simpleserver/" + SimpleStatefulBean.class.getSimpleName() + "/remote");
  | 		} catch (Exception e) {
  | 			e.printStackTrace();
  | 		}

Now it does not work to cast it to the remote interface! I get the following error:

19:53:27,164 ERROR [STDERR] java.lang.ClassCastException: $Proxy90 cannot be cast to com.test.SimpleStatefulBeanRemote
  | 19:53:27,165 ERROR [STDERR] 	at com.test.SimpleTestServlet.doGet(SimpleTestServlet.java:38)
  | 19:53:27,165 ERROR [STDERR] 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
  | 19:53:27,165 ERROR [STDERR] 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  | 19:53:27,165 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  | 19:53:27,165 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 19:53:27,165 ERROR [STDERR] 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 19:53:27,165 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 19:53:27,165 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | .
  | .
  | .
  | 

Can someone please help me??


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

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



More information about the jboss-user mailing list