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:
...
<
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