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.
invocationBuilder 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.
How can I patch this?
After some research, 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 I'll need to find an alternative library, method and code to call patch, but it needs to support OATH 2.0 also. Does such a library exist, and if so, are examples available?
I am using Java 1.8.0_131-b11.
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(HttpMethod.PATCH, Entity.json(objectMapper.writeValueAsString(payload)));
I found @Paul Samsotha, @John Little Accepted Answer to be correct.
If you don't find javax.ws.rs.client.Client to be directly injectable, a Bean method similar to this (if you have a Bean that extends extends Consumer<ClientBuilder>) may further help to access it:
import java.util.function.Consumer;
import javax.ws.rs.client.ClientBuilder;
@Bean
public Consumer<ClientBuilder> patchOverrideEnhancer() {
return (client) -> {
client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With