xml 安全性的 ClassCastException(TransformC14NExclusive)

ClassCastException for xml security (TransformC14NExclusive)

我已经为我的应用程序 (jdk 1.6.24) 实现了一个带有 cxf 的 Web 服务,它在 jboss 5.1.0 上运行良好。 一段时间后,Web 服务无法正常工作,因为它会抛出以下异常

java.lang.ClassCastException: org.apache.xml.security.transforms.implementations.TransformC14NExclusive cannot be cast to org.apache.xml.security.transforms.TransformSpi
        at org.apache.xml.security.transforms.Transform.getTransformSpi(Unknown Source)
        at org.apache.xml.security.transforms.Transform.<init>(Unknown Source)
        at org.apache.xml.security.transforms.Transform.getInstance(Unknown Source)
        at org.apache.xml.security.transforms.Transform.getInstance(Unknown Source)
        at org.apache.xml.security.transforms.Transforms.addTransform(Unknown Source)
        at org.apache.ws.security.message.WSSecSignature.addReferencesToSign(WSSecSignature.java:599)
        at org.apache.ws.security.message.WSSecSignature.build(WSSecSignature.java:774)
        at org.apache.ws.security.action.SignatureAction.execute(SignatureAction.java:65)
        at org.apache.ws.security.handler.WSHandler.doSenderAction(WSHandler.java:206)
        at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor.access0(WSS4JOutInterceptor.java:50)
        at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:257)
        at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:134)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:516)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
        at $Proxy566.getEntityRepresentatives(Unknown Source)
        at mycodeClient()
        at mycodeMethodCall()
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
        at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
        at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
        at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
        at sun.reflect.GeneratedMethodAccessor325.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
        at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
        at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_1509825954.invoke(InvocationContextInterceptor_z_fillMethod_1509825954.java)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
        at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
        at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_1509825954.invoke(InvocationContextInterceptor_z_setup_1509825954.java)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
        at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
        at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
        at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
        at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)

我使用的解决方法是从 jboss 中删除 tmp、数据和工作文件夹。 之后它工作正常,直到它稍后再次抛出此错误。

异常的最可能原因是您获得了由多个 classloader 加载的相同 class。

你必须检查你是如何打包你的应用程序的。

JBoss 有一些 CXF jar,默认情况下它们对您的应用程序可见。 如果您还将 CXF jar 与您的应用程序打包在一起,那么您必须完全理解 JBoss class 加载规则以及如何调整它们。