在SpringWS中向@soapfault响应添加详细信息

8fq7wneg  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(316)

在我的应用程序中,我希望为其中一个异常返回自定义响应。我通过异常上方的@soapfault注解找到了一种方法,它起到了一半的作用,我得到了自定义错误代码,但由于某些原因,它没有在自定义异常解析程序中找到我的CustomizeDefault方法,因此我无法向响应中添加详细信息。代码:

public class DetailSoapFaultAnnotationExceptionResolver extends SoapFaultAnnotationExceptionResolver {
    private static final QName DESCRIPTION = new QName("description");
    private static final QName ERROR = new QName("code");

    @Override
    protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) {
        SoapFaultDetail detail = fault.addFaultDetail();

        if (ex instanceof ValidationException) {
            detail.addFaultDetailElement(DESCRIPTION).addText(validationException.getMessage());
            detail.addFaultDetailElement(ERROR).addText("Validation Error");
        }

        log.error(ex.getMessage(), ex);
    }

例外情况:

@SoapFault(faultCode = FaultCode.CLIENT, locale = "en", faultStringOrReason = "Validation error", customFaultCode = "{URI}SOAP-ENV:Client")
public class ValidationException extends RuntimeException {
    public ValidationException(String errorMessage) {
        super(errorMessage);
    }
}

配置:

@Bean
    public DetailSoapFaultAnnotationExceptionResolver detailSoapFaultAnnotationExceptionResolver()  {
        DetailSoapFaultAnnotationExceptionResolver soapFaultAnnotationExceptionResolver = new DetailSoapFaultAnnotationExceptionResolver();

        SoapFaultDefinition faultDefinition = new SoapFaultDefinition();
        faultDefinition.setFaultCode(SoapFaultDefinition.CLIENT);
        soapFaultAnnotationExceptionResolver.setDefaultFault(faultDefinition);
        soapFaultAnnotationExceptionResolver.setOrder(2);

        return soapFaultAnnotationExceptionResolver;
    }

正如您所看到的,它的顺序是2,因为我已经有了一个自定义解析器来捕获所有其他异常(这个带有注解的解析器也没有命中第一个)
我还尝试将此异常添加到第一个自定义解析器中的错误Map中,但我无法仅为这一个异常设置不同的faultstring

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题