JRuby, Sinatra, Warbler app - HTTP PATCH request fails with 501 error

556 views Asked by At

I've created a simple web service using JRuby 1.7.4, Sinatra 1.4.4 and Rack 1.5.2. This web service responds to GET, POST, PATCH and DELETE requests with a simple message "Hello world using [request-type]".

I started Rack and tested all the request types. All four worked.

I used Warbler to create a war file of the application and deployed it to Tomcat 7.0.47. When I tested with Tomcat PATCH failed with a "HTTP Status 501 - Method PATCH is not is not implemented by this servlet for this URI". (Yes, 'is not' is repeated. But this is the response I get from Tomcat.) GET, POST and DELETE worked fine.

I then tried using Jetty 9.1.0. Same result. GET, POST and DELETE work but PATCH fails.

Why are PATCH requests failing and how do I get them to work with this set up?

1

There are 1 answers

1
Ivan Shamatov On

According to Tomcat documentation HttpServlet can handle only GET, POST, PUT, DELETE requests

public abstract class HttpServlet extends GenericServlet

Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A subclass of HttpServlet must override at least one method, usually one of these:

doGet, if the servlet supports HTTP GET requests doPost, for HTTP POST requests doPut, for HTTP PUT requests doDelete, for HTTP DELETE requests

But you can find this useful:

If you use an HTTP library that doesn't allow overriding or setting an arbitrary HTTP method name, you can send a POST request and provide an override to the HTTP method via the query string parameter _HttpMethod.

For example, to update an Account, this will work with an actual POST request:

.../services/data/v23.0/sobjects/Account/0016000000eEhmxAAC?_HttpMethod=PATCH