如何正确处理由SOAP Web服务引发的客户端异常

时间:2019-07-18 12:24:09

标签: spring-boot soap

我正在使用Java中的Spring-boot设置客户端以访问soap端点(出于测试目的)。处理异常的最佳方法是什么?我想处理SOAPFaultClientExceptions ...

我已经尝试过: How to Parse SoapFaultClientException in spring-ws

但是它不能正常工作,因为我无法在getValue()上调用detail方法

try {
        JAXBElement res = (JAXBElement) getWebServiceTemplate().marshalSendAndReceive(url, request);
        return (GetBankResponseType) res.getValue();
    }catch (SoapFaultClientException ex) {
        SoapFaultDetail soapFaultDetail = ex.getSoapFault().getFaultDetail(); // <soapFaultDetail> node
        // if there is no fault soapFaultDetail ...
        if (soapFaultDetail == null) {
            throw ex;
        }
        SoapFaultDetailElement detailElementChild = soapFaultDetail.getDetailEntries().next();
        Source detailSource = detailElementChild.getSource();
        Object detail = getWebServiceTemplate().getUnmarshaller().unmarshal(detailSource);
        JAXBElement source = (JAXBElement) detail;
        System.out.println("Text::"+source.getValue());
    }//catch other Exceptions...Which ones?
    return null;
}

预期结果是已处理的Exception(SOAPFaultClientException)或其他...,如果传递了错误的参数,则该异常将被webservice抛出。我找不到合适的解决方案。

1 个答案:

答案 0 :(得分:0)

为您的WebServiceTemplate配置ClientInterceptorFaultMessageResolver,然后在其中进行错误处理。

相关问题