I want to call some "upgrade" REST API through Jersy client, which is declared as PUT and does not require any body content.
But when I request this API as below:
webTarget.request().put(Entity.json(null));
It gives error as below:
Entity must not be null for http method PUT.
So need to know, is there any way in jersy client to call PUT method with null Entity.
I ran into the same error, and solved it by using an empty text entity:
Entity<?> empty = Entity.text("");
webTarget.request().put(empty);
You can use webTarget.request().put(Entity.json(""));
It works for me.
You can configure the client property
SUPPRESS_HTTP_COMPLIANCE_VALIDATION
By default, Jersey client runtime performs certain HTTP compliance checks (such as which HTTP methods can facilitate non-empty request entities etc.) in order to fail fast with an exception when user tries to establish a communication non-compliant with HTTP specification. Users who need to override these compliance checks and avoid the exceptions being thrown by Jersey client runtime for some reason, can set this property to true. As a result, the compliance issues will be merely reported in a log and no exceptions will be thrown.
[...]
Client client = ClientBuilder.newClient();
client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
WebTarget target = client.target("...");
Response response = target.request().put(Entity.json(null));
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