在Spring-Boot中为soap webservice抛出自定义异常?

时间:2014-09-08 07:30:58

标签: java spring web-services soap spring-boot

我正在使用soap webservice创建spring-boot

默认情况下,我将每个@WebMethod代码包装在try-catch中,这样当Exception个{I}}时,我可以将其转换为我自己的@WebFault

@Component
@WebService
public class MyService extends SpringBeanAutowiringSupport {

    @WebMethod
    public void test() {
        try {
            //connect to another soap service, which throws a java.net.SocketTimeoutException: Read timed out
        } catch (Exception e) {
            throw new MyException("my custom error msg");
        }
    }
}

@WebFault
public class MyException extends Exception {
    public MyException(String value) {  
        super(value);
    }
}

问题:例如,如果网络方法中出现java.net.SocketTimeoutException,则会调用spring-boot ErrorPageFilter而不是返回我的自定义@WebFault

但为什么呢?我可以禁用吗?如何返回错误错误消息?

[] 2014-09-08 09:20:51,251 ERROR org.springframework.boot.context.web.ErrorPageFilter: Forwarding to error page from request [/services/MyService] due to exception [null]
org.apache.catalina.connector.ClientAbortException
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:371) ~[catalina.jar:7.0.50]
    at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:333) ~[catalina.jar:7.0.50]
    at org.apache.catalina.connector.Response.flushBuffer(Response.java:570) ~[catalina.jar:7.0.50]
    at org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:307) ~[catalina.jar:7.0.50]
    at org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:115) [spring-boot-1.1.6.RELEASE.jar:1.1.6.RELEASE]
    at org.springframework.boot.context.web.ErrorPageFilter.access$000(ErrorPageFilter.java:58) [spring-boot-1.1.6.RELEASE.jar:1.1.6.RELEASE]
    at org.springframework.boot.context.web.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:87) [spring-boot-1.1.6.RELEASE.jar:1.1.6.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:100) [spring-boot-1.1.6.RELEASE.jar:1.1.6.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.50]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.50]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) [catalina.jar:7.0.50]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) [catalina.jar:7.0.50]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [catalina.jar:7.0.50]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) [catalina.jar:7.0.50]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) [catalina.jar:7.0.50]
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) [catalina.jar:7.0.50]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) [catalina.jar:7.0.50]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409) [catalina.jar:7.0.50]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044) [tomcat-coyote.jar:7.0.50]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) [tomcat-coyote.jar:7.0.50]
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315) [tomcat-coyote.jar:7.0.50]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_51]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_51]
    at java.lang.Thread.run(Thread.java:744) [?:1.7.0_51]

1 个答案:

答案 0 :(得分:3)

尝试禁用Spring的默认错误处理

@EnableAutoConfiguration(exclude={ErrorMvcAutoConfiguration.class})