我编写了一个与UPS Web服务一起使用的Web服务客户端(使用Java Spring和JAXB Marshaller).当我发送有效请求时,一切正常.当我发送无效请求(权重> 150磅)时,UPS Web服务会响应SOAP Fault.客户端应用程序失败了
org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling
exception; nested exception is javax.xml.bind.UnmarshalException:
unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/",local:"Fault").
显然我的程序无法破译Web服务返回的SOAP错误.我写了一个自定义的FaultMessageResolver,但它没有被调用.这是代码:
public class UpsRateClient extends WebServiceGatewaySupport {
public UpsRateClient(WebServiceMessageFactory messageFactory) {
super(messageFactory);
getwebservicetemplate().setFaultMessageResolver(new UpsFaultMessageResolver());
}
public RateResponse getRate(RateRequest rateRequest) {
return (RateResponse) getwebservicetemplate().marshalSendAndReceive(rateRequest,new UpsRequestWSMC());
}
private class UpsFaultMessageResolver implements FaultMessageResolver {
public void resolveFault(WebServiceMessage message) throws IOException{
System.out.println("Inside UpsFaultMessageResolver");
}
}
}
谢谢你的时间!
最佳答案
采取wirehark跟踪.我想是也许Web服务使用(错误地)HTTP 200OK而不是500内部服务器错误发送SOAP错误,并且您的客户端尝试将其作为有效响应处理.
如果是这种情况那么问题在于Web服务没有加入SOAP标准(我的重点):
从SOAP RFC起
如果是这种情况那么问题在于Web服务没有加入SOAP标准(我的重点):
从SOAP RFC起
In case of a SOAP error while processing the request,the SOAP HTTP
server MUST issue an HTTP 500 “Internal Server Error” response and
include a SOAP message in the response containing a SOAP Fault element
(see section 4.4) indicating the SOAP processing error.
如果您不拥有Web服务,他们应该解决这个问题.
说实话,我不确定Spring-WS中的工作是什么.
如果我真的需要在Jax-Ws中工作,我会用Dispatcher替换存根调用以自己处理原始xml并避免自动编组/解组.
如果你能做同样的事情,请看看Spring-Ws,但这是Web服务的错误,而不是你的客户端
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。