Spring Web Services - Exception Skipping ExceptionResolver

前端 未结 8 976
别那么骄傲
别那么骄傲 2020-12-19 04:33

I have a SOAP service, the request and responses work as expected with good input, if I specify bad input for an XML element

in request body:

...
<         


        
8条回答
  •  眼角桃花
    2020-12-19 05:23

    The solution I could come up with is to override the doService method in the MessageDispatcherServlet and capture the exception, then render a custom response. This might not be the best solution for you, but it works for me, hope this helps!

    public class CustomMessageDispatcherServlet extends MessageDispatcherServlet {
    
    protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
        try {
            super.doService(request, response);
        } catch (Exception e) {
            String error = e.getMessage();
            String errorXml = "" +
                                    "" +
                                        "" +
                                            "" +
                                                "SOAP-ENV:Client" +
                                                "" + error +
                                            "" +
                                        "" +
                                    "";
            response.setStatus(HttpServletResponse.SC_OK);
            response.setContentType("text/xml");
            response.getWriter().write(errorXml);
            response.getWriter().flush();
        }
    }
    

    }

    You might want to catch only the exceptions you want to handle.

    Replace org.springframework.ws.transport.http.MessageDispatcherServlet with your CustomMessageDispatcherServlet in the web.xml file.

    
        web-services
        CustomMessageDispatcherServlet
    
    

提交回复
热议问题