简体   繁体   中英

Handling PATCH requests with javax.servlet.http.HttpServlet?

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)?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM