我有一个 J2EE 应用程序(出于遗留原因),它同时具有 Axis2 和 CXF 库,用于应用程序使用的不同提供程序端点。
我已经实现了一个新的客户端端点,它通过 CXF 连接到第三方提供商。端点要求将身份验证详细信息放入 SoapHeaders(而不是 HTTP 标头)中。
弹簧配置如下:
<jaxws:client id="fareSearchServicePort" serviceClass="org.openaxisgroup.axisschemadocs.v1r1_va.AxisPort"
address="${endpoint}faresearch">
<jaxws:features>
<ref bean="gzipFeature"/>
<ref bean="fastInfosetFeature"/>
<!--<ref bean="loggingFeature"/>-->
</jaxws:features>
<jaxws:properties>
<entry key="org.apache.cxf.binding.soap.messageFactoryClassName" value="com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl" />
</jaxws:properties>
<jaxws:outInterceptors>
<ref bean="outPasswordInterceptor" />
</jaxws:outInterceptors>
</jaxws:client>
<bean id="outPasswordInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken" />
<entry key="passwordType" value="PasswordText" />
<entry key="signaturePropFile" value="..."/>
<entry key="passwordCallbackRef" value-ref="myPasswordCallback"/>
</map>
</constructor-arg>
</bean>
如果没有 outInterceptors,连接工作正常,只是无法进行身份验证。
在包含拦截器的情况下,代码被委托给 Axis2 库,从而导致“org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR”。甚至在密码回调方法被触摸之前。堆栈跟踪:
org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.
at org.apache.axiom.om.impl.dom.ParentNode.insertBefore(ParentNode.java:224)
at org.apache.axiom.om.impl.dom.NodeImpl.appendChild(NodeImpl.java:240)
at org.apache.axis2.saaj.SOAPPartImpl.appendChild(SOAPPartImpl.java:979)
at org.apache.cxf.staxutils.W3CDOMStreamWriter.setChild(W3CDOMStreamWriter.java:114)
at org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.java:104)
at org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamWriter.java:132)
at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:122)
at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:81)
at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:61)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:244)
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 $Proxy144.axisTransaction(Unknown Source)
如何指定要使用的 SOAPPartImpl?(即 com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl)