我使用的是Spring web服務,而spring web service/xml版本是2.1.3,但其他的spring core版本是3.2.3。我需要訪問肥皂標題並將響應標題設置爲與請求標題相同。我延長了PayloadValidationInterceptor添加如下額外的邏輯:Spring Web Service創建DomPoxMessage而不是SaajSoapMessage
@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));
}
}
}
在春天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。有誰知道爲什麼會發生這種情況。
實際的錯誤可能是有用的 –