我需要从Web服务获取XML响应。问题在于此响应的标头状态设置为HTTP/1.1 400 Bad Request
,并且此状态在Java中抛出WebServiceException,使得无法捕获xml响应(在SoapUI中,我可以清楚地看到xml响应及其所有信息)。 / p>
public RegistryResponseType sendRequest(SubmitObjectsRequest submitObjectsRequest) {
RegistryResponseType r = null;
SomeService service = new SomeService();
try {
r = service.do(submitObjectsRequest);
} catch (WebServiceException e) {
//do something to retrieve xml response
}
return r;
}
response.xml
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>xxx</wsa:To>
<wsa:MessageID>xxx</wsa:MessageID>
<wsa:Action>http://www.w3.org/2005/08/addressing/soap/fault</wsa:Action>
<wsa:RelatesTo>5c47a3df-12e5-4599-a5aa-0e70457a76e7</wsa:RelatesTo>
</soapenv:Header>
<soapenv:Body>
<soapenv:Fault>
<soapenv:Code>
<soapenv:Value>soapenv:Sender</soapenv:Value>
</soapenv:Code>
<soapenv:Reason>
<soapenv:Text xml:lang="en-US">Missing upload consent</soapenv:Text>
</soapenv:Reason>
<axis2ns1:Detail xmlns:axis2ns1="http://www.w3.org/2003/05/soap-envelope">
<wsse:InvalidSecurityToken xmlns:wsse="http://docs.oasisopen.org/wsrf/bf-2 bf-2.xsd">
<wsrf-bf:Timestamp xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2">2018-08-08T09:43:19.212CEST</wsrf-bf:Timestamp>
<wsrf-bf:ErrorCode xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2">PFA12</wsrf-bf:ErrorCode>
<wsrf-bf:Description xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2">Missing upload consent</wsrf-bf:Description>
</wsse:InvalidSecurityToken>
</axis2ns1:Detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
添加catch(SOAPFaultException e)
不能解决问题。是否可以处理异常并检索XML?
更新:
如我之前所说,该问题与标头状态有关,并且此状态取决于SOAP 1.2(进行一些调查后发现,对于SOAP 1.1中的同一问题,标头状态为500)
Apache CXF的MessageSenderInterceptor
引发异常。
有没有办法重写拦截器?