![](/img/trans.png)
[英]How to add complex XML to SOAP Fault detail in Spring web service?
[英]How to map an exception thrown by a spring boot web service to a complex fault info?
我使用Spring Boot为现有的WSDL实现了一个服务提供者。 WSDL指定带有附加故障消息的服务。 相应的故障信息具有一些详细信息,包括时间戳,引起异常的类及其堆栈跟踪以及原始请求中包含的信息。 所有细节都单独定义为XML元素。
当在服务器上执行服务时,这些信息在运行时可用。 如果发生错误,则会引发包含这些信息的适当异常。
借助Spring Boot,可以配置org.springframework.ws.server.EndpointExceptionResolver
实例,以将异常映射到故障信息。 但是,似乎在所有实现类中只能添加故障信息消息和故障代码。 我没有找到添加结构化对象或更好的方法:定义了JAXB序列化的对象。
这怎么可能?
当然,这不是问题。
一种方法是创建一个自定义的SoapFaultMappingExceptionResolver,将异常映射到故障:
public class DetailSoapFaultDefinitionExceptionResolver extends SoapFaultMappingExceptionResolver {
private static final QName CODE = new QName("code");
private static final QName DESCRIPTION = new QName("description");
@Override
protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) {
logger.warn("Exception processed ", ex);
if (ex instanceof ServiceFaultException) {
ServiceFault serviceFault = ((ServiceFaultException) ex).getServiceFault();
SoapFaultDetail detail = fault.addFaultDetail();
detail.addFaultDetailElement(CODE).addText(serviceFault.getCode());
detail.addFaultDetailElement(DESCRIPTION).addText(serviceFault.getDescription());
}
}
}
请在此处找到完整的示例:
https://memorynotfound.com/spring-ws-add-detail-soapfault-exception-handling/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.