The org.glassfish.jersey.server.filter.HttpMethodOverrideFilter I mentioned
is a bit more elaborate than that, but accomplishes the same basic thing on
the server side. But it's really more a problem on the client side than
the server side, for two reasons:
* The verb restrictions in HttpURLConnection makes it not possible to use
the default Jersey Client configuration without a hack, or using something
like Apache's HttpClient instead.
* In JAX-RS's client API, there's no direct support for PATCH in things
like Invocation, so you have to get down into the guts to know what you are
doing.
Hopefully the next versions of Java and JAX-RS will recognize that PATCH is
a standard (
http://tools.ietf.org/html/rfc5789), and has been for just over
five years now.
Craig
On Fri, Apr 10, 2015 at 1:48 AM, Markus Karg <karg_at_quipsy.de> wrote:
> Craig,
>
>
>
> Let me chime in again.
>
>
>
> You can make this solution portable by simply writing your own HTTP Method
> Override Filter (Paraphrasing Arun Gupta’s recent advice: “if there is a
> standard solution, don’t use the proprietary alternative”). (NB this would
> be a perfect start for a library of portable JAX-RS extensions!).
>
>
>
> An example how to do this is shown in this article of Adam Bien on the
> Oracle web site (
> http://www.oracle.com/technetwork/articles/java/jaxrs20-1929352.html):
>
>
>
> @Provider
>
> @PreMatching
>
> public class HttpMethodOverrideEnabler implements ContainerRequestFilter {
>
> public void filter(ContainerRequestContext requestContext) throws
> IOException {
>
> String override =
> requestContext.getHeaders().getFirst("X-HTTP-Method-Override");
>
> if (override != null) {
>
> requestContext.setMethod(override);
>
> }
>
> }
>
> }
>
>
>
> Regards
>
> -Markus
>
>
>
> *Von:* Craig McClanahan [mailto:craigmcc_at_gmail.com]
> *Gesendet:* Donnerstag, 9. April 2015 21:50
> *An:* users_at_jersey.java.net
> *Betreff:* [Jersey] Re: Sending a PATCH request from JAX-RS client?
>
>
>
> When I had a similar problem recently, I chose to have my server implement
> HttpMethodOverrideFilter (from Jersey) so that lame (non-PATCH-capable)
> clients could send an X-HTTP-Method-Override header and do a POST. Clients
> that do understand how to PATCH can still do it.
>
>
>
> Craig
>
>
>
>
>
> On Thu, Apr 9, 2015 at 10:13 AM, Simon Roberts <
> simon_at_dancingcloudphotography.com> wrote:
>
> Thanks Markus,
>
>
>
> That pushed my search a little further, and eventually I found that Jersey
> has a (seemingly undocumented?) feature for this:
>
>
>
> client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
>
>
>
> Seems to solve this adequately. Weird that it doens't appear to show up in
> the docs. Perhaps PATCH isn't all that common?
>
>
>
> Cheers,
>
> Simon
>
>
>
>
>
> Subject: [Jersey] Re: Sending a PATCH request from JAX-RS client?
>
> See
> https://blogs.oracle.com/PavelBucek/entry/jersey_client_making_requests_with
> but AFAIK the name of the property was changed meanwhile.
>
>
>
> Regards
>
> -Markus
>
>
>
>
>