@@ -59,11 +59,11 @@ public ModelAndView handle(HttpServletRequest httpServletRequest,
5959 handleConnection (connection , (WebServiceMessageReceiver ) handler );
6060 }
6161 catch (InvalidXmlException ex ) {
62- httpServletResponse . setStatus ( HttpServletResponse . SC_BAD_REQUEST );
62+ handleInvalidXmlException ( httpServletRequest , httpServletResponse , handler , ex );
6363 }
6464 }
6565 else {
66- httpServletResponse . setStatus ( HttpServletResponse . SC_METHOD_NOT_ALLOWED );
66+ handleNonPostMethod ( httpServletRequest , httpServletResponse , handler );
6767 }
6868 return null ;
6969 }
@@ -72,4 +72,38 @@ public boolean supports(Object handler) {
7272 return handler instanceof WebServiceMessageReceiver ;
7373 }
7474
75+ /**
76+ * Template method that is invoked when the request method is not {@code POST}. Called from {@link
77+ * #handle(HttpServletRequest, HttpServletResponse, Object)}.
78+ * <p/>
79+ * Default implementation set the response status to 405: Method Not Allowed. Can be overridden in subclasses.
80+ *
81+ * @param httpServletRequest current HTTP request
82+ * @param httpServletResponse current HTTP response
83+ * @param handler current handler
84+ */
85+ protected void handleNonPostMethod (HttpServletRequest httpServletRequest ,
86+ HttpServletResponse httpServletResponse ,
87+ Object handler ) throws Exception {
88+ httpServletResponse .setStatus (HttpServletResponse .SC_METHOD_NOT_ALLOWED );
89+ }
90+
91+ /**
92+ * Template method that is invoked when parsing the request results in a {@link InvalidXmlException}. Called from
93+ * {@link #handle(HttpServletRequest, HttpServletResponse, Object)}.
94+ * <p/>
95+ * Default implementation set the response status to 400: Bad Request. Can be overridden in subclasses.
96+ *
97+ * @param httpServletRequest current HTTP request
98+ * @param httpServletResponse current HTTP response
99+ * @param handler current handler
100+ * @param ex the invalid XML exception that resulted in this method being called
101+ */
102+ protected void handleInvalidXmlException (HttpServletRequest httpServletRequest ,
103+ HttpServletResponse httpServletResponse ,
104+ Object handler ,
105+ InvalidXmlException ex ) throws Exception {
106+ httpServletResponse .setStatus (HttpServletResponse .SC_BAD_REQUEST );
107+ }
108+
75109}
0 commit comments