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

我编写了一个与UPS Web服务配合使用的Web服务客户端(使用Java Spring和JAXB Marshaller)。当我发送有效请求时,一切正常。当我发送无效请求(重量> 150磅)时,UPS Web服务会响应SOAP Fault。客户端应用程序失败了

I have written a web service client (using Java Spring and JAXB Marshaller) that works with the UPS web service. When I send a valid request everything works well. When I send an invalid request (weight > 150 lbs) then the UPS web service responds with a SOAP Fault. The client application just fails with a

org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling 
exception; nested exception is javax.xml.bind.UnmarshalException: 
unexpected element (uri:"", local:"Fault").


Obviously my program isn't able to decipher the SOAP fault returned by the web service. I wrote a custom FaultMessageResolver, but it doesn't get invoked. Here's the code:

public class UpsRateClient extends WebServiceGatewaySupport {
    public UpsRateClient(WebServiceMessageFactory 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");   


 1 条回答