[jboss-user] [EJB 3.0] - ClassCastException: $Proxy94 cannot be cast ...

ttrepper do-not-reply at jboss.com
Tue Apr 8 14:22:36 EDT 2008


Hi all, 

I am using JBoss 4.2.2GA and Java(TM) SE Runtime Environment (build 1.6.0_05-b13) for my development environment. 

I have a stateless session bean called UtilityBean and an interfaces called UtilityBeanLocal, marked with @Local and the bean marked with @stateless and implements serializable and the local-interface. 

When I try to make a lookup through InitalContext I get a Proxy-Object, which cannot be casted to the local interface.

Stacktrace:
anonymous wrote : 
  | 20:05:44,843 ERROR [STDERR] java.lang.ClassCastException: $Proxy94 cannot be cast to test.ejb.stateless.UtilityBeanLocal
  | 20:05:44,843 ERROR [STDERR] 	at test.service.helper.ApplicationHelper.getApplicationSettings(ApplicationHelper.java:23)
  | 20:05:44,843 ERROR [STDERR] 	at test.service.helper.RegistrationHelper.isUsernameLongEnough(RegistrationHelper.java:32)
  | 20:05:44,843 ERROR [STDERR] 	at test.web.beans.RegistrationBean.checkUserComplete(RegistrationBean.java:395)
  | 20:05:44,843 ERROR [STDERR] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 20:05:44,843 ERROR [STDERR] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | 20:05:44,843 ERROR [STDERR] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | 20:05:44,843 ERROR [STDERR] 	at java.lang.reflect.Method.invoke(Method.java:597)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
  | 20:05:44,843 ERROR [STDERR] 	at javax.faces.validator.MethodExpressionValidator.validate(MethodExpressionValidator.java:84)
  | 20:05:44,843 ERROR [STDERR] 	at javax.faces.component.UIInput.validateValue(UIInput.java:1013)
  | 20:05:44,843 ERROR [STDERR] 	at javax.faces.component.UIInput.validate(UIInput.java:867)
  | 20:05:44,843 ERROR [STDERR] 	at javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
  | 20:05:44,843 ERROR [STDERR] 	at javax.faces.component.UIInput.processValidators(UIInput.java:666)
  | 20:05:44,843 ERROR [STDERR] 	at org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:335)
  | 20:05:44,843 ERROR [STDERR] 	at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:100)
  | 20:05:44,843 ERROR [STDERR] 	at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
  | 20:05:44,843 ERROR [STDERR] 	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
  | 20:05:44,843 ERROR [STDERR] 	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 20:05:44,843 ERROR [STDERR] 	at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
  | 20:05:44,843 ERROR [STDERR] 	at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 20:05:44,843 ERROR [STDERR] 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  | 20:05:44,843 ERROR [STDERR] 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
  | 20:05:44,843 ERROR [STDERR] 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
  | 20:05:44,843 ERROR [STDERR] 	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
  | 20:05:44,843 ERROR [STDERR] 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
  | 20:05:44,843 ERROR [STDERR] 	at java.lang.Thread.run(Thread.java:619)

The following code shows the part, which displays all implemented interfaces of the object:

  | System.out.println(obj.getClass().getName());
  | Class[] interfaces = obj.getClass().getInterfaces();
  | for (int i = 0; i < interfaces.length; ++i) {
  |    System.out.println(interfaces.getName());
  | }
Output:anonymous wrote : 20:05:44,843 INFO  [STDOUT] $Proxy94
  | 20:05:44,843 INFO  [STDOUT] test.ejb.stateless.UtilityBeanLocal
  | 20:05:44,843 INFO  [STDOUT] org.jboss.ejb3.JBossProxy

Stateless Bean:

  | @Stateless
  | public class UtilityBean implements UtilityBeanLocal, Serializable, Constants {
  | 	private static final long serialVersionUID = 1L;
  | ......
  | 
Interface:

  | @Local
  | public interface UtilityBeanLocal {
  | 	public static final String JNDI_NAME = "UtilityBeanLocal";
  | 	public ApplicationSettings getApplicationSettings();
  | }

Context-Lookup:

  | public class BeanLocator {
  | 	public static final String JNDI_PREFIX = "java:comp/env/ejb/";
  | 	private static transient BeanLocator instance = null;
  | 	private InitialContext initialcontext = null;
  | 	
  | 	//--------------------------------------------------------------------------
  | 	private BeanLocator() {
  | 		try {
  | 			Properties props = new Properties();
  | 			props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
  | 			props.put(Context.PROVIDER_URL,"jnp://localhost:1099");
  | 			props.put(Context.URL_PKG_PREFIXES,"org.jboss.naming.jnp.interfaces");
  | 			//Context ctx = new InitialContext(props);
  | 			this.initialcontext = new InitialContext(props);
  | 		} catch (NamingException e) {
  | 			//e.printStackTrace();
  | 			this.initialcontext = null;
  | 		}
  | 	}
  | 	
  | 	//--------------------------------------------------------------------------
  | 	public static BeanLocator getInstance() {
  | 		if (instance == null) {
  | 			instance = new BeanLocator();
  | 		}
  | 		return instance;
  | 	}
  | 
  |         //--------------------------------------------------------------------------
  | 	public Object locate(String jndiName, Class<?> clazz) throws NamingException {		 
  | 		Object obj = null;
  | 		if (this.initialcontext != null) {
  | 			//obj = PortableRemoteObject.narrow(initialcontext.lookup(jndiName), clazz);
  | 			obj = initialcontext.lookup(jndiName);
  | 			
  | 			System.out.println(obj.getClass().getName());
  | 			Class[] interfaces = obj.getClass().getInterfaces();
  | 			for (int i = 0; i < interfaces.length; ++i) {
  | 			 System.out.println(interfaces.getName());
  | 			}
  | 		}
  | 		return obj;
  | 	}
  | }

It is not working with or without passing the properties to the context. 

The main question is, why I cannot cast, even if the interface is implemented???

What am I missing? Does anybody has a clue?

Thanks in advance and best regards,

Thomas


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

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



More information about the jboss-user mailing list