我正在使用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抛出。我找不到合适的解决方案。