2
WebTarget webTarget = httpClient.target(url);
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON)
                .header(HttpUtils.AUTHORISATION_HEADER_NAME, "Bearer " + theAccessToken);
response = invocationBuilder.put(Entity.json(objectMapper.writeValueAsString(payload)));

httpClient is of type javax.ws.rs.client.Client and gets injected.

invocatioBuilder implements javax.ws.rs.client.Invocation.Builder, but is defined in package org.glassfish.jersey.client

invocationBuilder.put, invocationBuilder.post, invocationBuilder.get all exist and work, but here is no invocationBuilder.patch - it's missing.

Any suggestions on how to patch?

==== UPDATE ====

After some googling, it seems that jersey client has no support for patch. As all our apps API calls are made using jersey client, this is a bit of a problem. I assume Ill need to find an alternative library, method and code to call patch, but it needs to support OATH 2.0 also. Any ideas if such a library exists, and, ideally has some examples?

FYI, using Java 1.8.0_131-b11

John Little
  • 7,993
  • 14
  • 62
  • 108
  • `method("PATCH")` – Paul Samsotha Apr 21 '19 at 06:36
  • Hi, in my IDE, I only have post, get and put, no patch. – John Little Apr 21 '19 at 06:51
  • 1
    [`method()`](https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/SyncInvoker.html#method-java.lang.String-). https://stackoverflow.com/a/26341128/2587435 – Paul Samsotha Apr 21 '19 at 09:53
  • Nice, I didnt know method() was a direct substitue for put(), post() etc. I tried it, and now get "javax.ws.rs.ProcessingException: java.net.ProtocolException: Invalid HTTP method: PATCH" on the line with "response = invocationBuilder.method("PATCH", Entity.json(...)". Googling this error, some suggest "Client jerseyClient = ClientBuilder.newClient() .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true)" but I dont have a Client object, only a WebTarget and a Invocation.Builder object. – John Little Apr 21 '19 at 10:48

1 Answers1

8

Thanks to @Paul Samsotha, the working solution is this:

WebTarget webTarget = httpClient.target(url);
webTarget.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);

Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON)
                .header(HttpUtils.AUTHORISATION_HEADER_NAME, "Bearer " + theAccessToken);
response = invocationBuilder.method("PATCH", Entity.json(objectMapper.writeValueAsString(payload)));
John Little
  • 7,993
  • 14
  • 62
  • 108