erp erp - 2 months ago 14x
Java Question

Jersey client with null put method

I am working on a Jersey service client for one of my services and am having trouble determining the best way to pass a null entity through the client's put. On the service side of things this is my endpoint:

public Response disableRuleByKey(@PathParam("key") String key)
throws Exception {
try {
return Response.ok().build();
} catch (BlahException bla) {
throw de;

Basically all the method does in the backend is flip a toggle for other parts of the application to use. I'm not sure if put is the correct call to use here (but this was written by a teammate). I know it doesn't even have a JSON payload.

Anyways, on the client side I have this generic
code for all of my clients to use via

public static <T> boolean putItem(Client client, String uri, T item)
throws InterruptedException,
ExecutionException {
Invocation putConfig =
.buildPut(Entity.entity(item, MediaType.APPLICATION_JSON));
Future<Response> asyncResponse = putConfig.submit();
Response response = asyncResponse.get();

return response.getStatus() == Status.OK.getStatusCode();

s into the database fine with a JSON payload, but since the method above doesn't specifically have a payload I was wondering what the best course of action would be. Would modifying the Invocation's
to have
in it be okay since I am not passing in a payload.

I am open to modifying the endpoint too but this is what I currently have and can't figure out the best way to send this value to the backend. Should I just modify the endpoint to consume a JSON object rather than passing the key as a


When replacing the state of a resource with a PUT request, you should send the new representation in the request payload.

Have a look the the RFC 7231, the current reference for semantics and content in HTTP/1.1:

4.3.4. PUT

The PUT method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload. [...]