【发布时间】:2014-12-08 16:14:19
【问题描述】:
我们在我们的应用程序上使用 spring-ws 2.2 来使用 Web 服务。很长一段时间以来,我们一直很高兴地这样做,并且一切正常,除了现在我需要访问响应中的 SOAP 标头,而我只是找不到这样做的方法。
我们正在使用配置有 Jaxb2Marshaller 的 WebServiceTemplate(来自 springs-ws)。 jaxb 文件是使用 xjc 从 wsdl 生成的。我的回复中的标题元素如下所示:
<soapenv:Header>
<v1:ResponseHeader status="OK">
<v1:description>test</v1:description>
</v1:ResponseHeader>
</soapenv:Header>
在我的 java 类中,解析响应的代码如下所示(我已经剥离了一些不相关的代码):
public CalculationData getValues(Integer id) throws IntegrationException {
WebServiceMessageCallback callback = createCallback(soapAction);
GetValuesRequest request = toGetValues(id);
GetValuesResponse response = null;
try {
response = (GetValuesResponse) webServiceTemplate.marshalSendAndReceive(request, callback);
} catch (SOAPFaultException fault) {
log.error("Soap fault occurred during getValues " + id);
throw new IntegrationException(fault);
}
CalculationData data = fromGetValues(response);
return data;
}
请帮助我找到从响应中提取 SOAP 标头信息的解决方案。我必须能够解析作为属性发送的状态代码。
顺便说一句。我还有一个从模式生成的 ResponseHeader.java jaxb 类。
最终更改更新:
这是内联 ClientInterceptor 实现后我的 handleResponse 方法的样子:
@Override
public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
SoapMessage message = (SoapMessage) messageContext.getResponse();
Iterator<SoapHeaderElement> responseHeaderElements =
message.getSoapHeader().examineAllHeaderElements();
SoapHeaderElement header = null;
if (responseHeaderElements.hasNext()) {
header = responseHeaderElements.next();
} else {
log.error("Error! No ResponseHeader found in response.");
return false;
}
String responseCode = header.getAttributeValue(new QName(STATUS_QNAME));
responseMsg.put(RESPONSE_MSG_KEY, responseCode);
return true;
}
我尝试通过 QName 获取 ResponseHeader 元素,但由于某种原因这似乎不起作用。但是,无论如何,我只希望在肥皂标题中获得一个元素,这样可以正常工作吗?
【问题讨论】:
标签: java spring jaxb spring-ws