1 2 Previous Next 15 Replies Latest reply on Jul 27, 2012 12:10 PM by Paul Ferraro

    ClassCastException with Infinispan using multiple applications

    Randy Nott Newbie

      I'm getting a ClassCastException when using an Infinispan cache to share data between two web applications, A and B running in the same JBoss AS-7 instance. Application A writes to the cache while application B reads from it. Application B fails on the read as the value is tied to the classloader of application A.

       

      I've tried this with both standalone and HA configurations in JBoss AS-7.0.2, defining the cache as local, then distributed, with similar results. Here is my cache configuration (standalone-preview-ha.xml):

       

      {code:xml}

      <cache-container name="foo-cache" default-cache="foo">

        <distributed-cache mode="ASYNC" name="foo" start="EAGER">

            <eviction strategy="NONE"/>

        </distributed-cache>

      </cache-container>

      {code}

       

      I'm injecting the cache into both web applications using CDI with the following producer:

       

      {code}

      @Resource(mappedName="java:jboss/infinispan/foo-cache")

      private CacheContainer container;

       

      @FooCache

      @Produces @ApplicationScoped

      Cache<String, Foo> fooCache() {

          return container.getCache( "foo" );

      }

      {code}

       

      I'd prefer that the cache be embedded in the JBoss instance as opposed to remote if this is possible. Does anyone know the recipe for making this work?

       

      Here is a sample stack trace:

       

      {code}

      15:52:28,160 ERROR [com.example.common.api.EJBExceptionMapper] (http-localhost-127.0.0.1-8080-2) Unhandled EJB exception: java.lang.ClassCastException: com.example.common.Foo cannot be cast to com.example.common.Foo

                at com.example.common.CacheAccess.fetch(CacheAccess.java:132) [test-common-model-0.0.1-SNAPSHOT.jar:]

                at com.example.B.service.TestSession.fetch(TestSession.java:95) [test-B-services-0.0.1-SNAPSHOT.jar:]

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_29]

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_29]

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_29]

                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_29]

                at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:370) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:122) [jboss-as-weld-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:130) [jboss-as-weld-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:45) [jboss-as-jpa-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:44)

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.ee.component.ViewDescription$ComponentDispatcherInterceptor.processInvocation(ViewDescription.java:202)

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:50) [jboss-as-ejb3-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.ejb3.component.session.SessionInvocationContextInterceptor$CustomSessionInvocationContext.proceed(SessionInvocationContextInterceptor.java:126) [jboss-as-ejb3-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:211) [jboss-as-ejb3-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:284) [jboss-as-ejb3-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:182) [jboss-as-ejb3-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.ejb3.component.session.SessionInvocationContextInterceptor.processInvocation(SessionInvocationContextInterceptor.java:71) [jboss-as-ejb3-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.ejb3.security.AuthorizationInterceptor.processInvocation(AuthorizationInterceptor.java:115) [jboss-as-ejb3-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:68) [jboss-as-ejb3-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:146)

                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.0.Final.jar:1.1.0.Final]

                at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:76)

                at com.example.B.service.TestSession$$$view4.fetch(Unknown Source) [test-B-services-0.0.1-SNAPSHOT.jar:]

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_29]

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_29]

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_29]

                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_29]

                at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:125) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                at com.example.B.service.TestSession$Proxy$_$$_Weld$Proxy$.fetch(TestSession$Proxy$_$$_Weld$Proxy$.java) [test-B-services-0.0.1-SNAPSHOT.jar:]

                at com.example.B.api.TestWeb.fetch(TestWeb.java:55) [classes:]

                at com.example.B.api.TestWeb$Proxy$_$$_WeldClientProxy.fetch(TestWeb$Proxy$_$$_WeldClientProxy.java) [classes:]

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_29]

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_29]

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_29]

                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_29]

                at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140) [resteasy-jaxrs-2.2.1.GA.jar:]

                at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:255) [resteasy-jaxrs-2.2.1.GA.jar:]

                at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:220) [resteasy-jaxrs-2.2.1.GA.jar:]

                at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:209) [resteasy-jaxrs-2.2.1.GA.jar:]

                at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:519) [resteasy-jaxrs-2.2.1.GA.jar:]

                at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496) [resteasy-jaxrs-2.2.1.GA.jar:]

                at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.2.1.GA.jar:]

                at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.2.1.GA.jar:]

                at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.2.1.GA.jar:]

                at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.2.1.GA.jar:]

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)

                at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)

                at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:480) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]

                at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:49) [jboss-as-jpa-7.0.2.Final.jar:7.0.2.Final]

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952) [jbossweb-7.0.1.Final.jar:7.0.2.Final]

                at java.lang.Thread.run(Thread.java:680) [:1.6.0_29]

      {code}

       

        1 2 Previous Next