加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Java Spring Web服务客户端故障处理

发布时间:2020-12-15 01:40:35 所属栏目:大数据 来源:网络整理
导读:我编写了一个与UPS Web服务一起使用的Web服务客户端(使用Java Spring和JAXB Marshaller).当我发送有效请求时,一切正常.当我发送无效请求(权重 150磅)时,UPS Web服务会响应SOAP Fault.客户端应用程序失败了 org.springframework.oxm.UnmarshallingFailureExce

我编写了一个与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起

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服务的错误,而不是你的客户端

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读