Issue
We are using our implementation of the javax.servlet.http.HttpServlet class as an error page(defined in the web.xml) in our Spring Web application in order to filter error information, sent to users of our API for security reasons.
As of recently we also have to handle PATCH requests to our API. As the HttpServlet was implemented with HTTP version 1.1 in mind, it does not support PATCH request("PATCH" string as a request method name). If we were to add the functionality, we have to override the whole HttpServlet implementation, which also has negative security connotations for us.
Is there an out of the box way to achieve what we are trying or do we have to switch to another implementation(also viable)?
Solution
Try overriding the HttpServlet.service
method.
For "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT", and "TRACE" pass the request to the super
implementation of service.
For "PATCH" call a doPatch
method that you define in the overriding class.
Implement doPatch
in the actual class.
More info about message body:
Checkout an HTTP reference to see which methods support a method body and which do not.
There is a nice table on the HTTP Wikipedia Page
Answered By - DwB
Answer Checked By - Clifford M. (JavaFixing Volunteer)