我正在使用 Spring Web 服务,并且 Spring Web Service/xml 版本是 2.1.3,而另一个 Spring 核心版本是 3.2.3。我需要访问soap标头并将响应标头设置为与请求标头相同。我扩展了 PayloadValidationInterceptor 以添加额外的逻辑,如下所示:
@Override
public void afterCompletion(MessageContext messageContext, Object endpoint,
Exception ex) {
//System.out.println("afterCompletion");
SaajSoapMessage soapRequest = (SaajSoapMessage) messageContext
.getRequest();
SoapHeader reqheader = soapRequest.getSoapHeader();
SaajSoapMessage soapResponse = (SaajSoapMessage) messageContext
.getResponse();
SoapHeader respheader = soapResponse.getSoapHeader();
if( reqheader !=null ){
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
try {
Transformer transformer = transformerFactory.newTransformer();
Iterator<SoapHeaderElement> itr = reqheader
.examineAllHeaderElements();
while (itr.hasNext()) {
SoapHeaderElement ele = itr.next();
transformer.transform(ele.getSource(), respheader.getResult());
}
} catch (Exception e) {
LOG.error(Toolkit.getStackTrace(e));
}
}
}
并且在 Spring Web 服务配置中,我添加了以下消息工厂以确保使用 SAAJ Soap 消息。
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
</property>
</bean>
测试时,一切正常。但是现在在生产中,当工作负载很高时,我开始收到 ClassCastException,因为 messageContext.getRequest() 返回的是 DomPoxMessage 而不是 SaajSoapMessage。有谁知道为什么会这样。