In Jersey this will work just fine, but when using Jersey Client to test your resource class, you will get exceptions:
java.net.ProtocolException: Invalid HTTP method: PATCH
There is a workaround for this, by setting client property
HttpUrlConnectorProvider.SET_METHOD_WORKAROUND
But wait, then you will end up with the following exception:
javax.ws.rs.ProcessingException: java.net.ProtocolException: HTTP method PATCH doesn't support output
So there is no other way than changing to the Apache HTTP client library, using Jersey version 2.10, its easy to configure to use Apache HTTP client, you only need to override the client config method in your test class that extends JerseyTest
.
@Override
protected void configureClient(ClientConfig config) {
config.register(CustomJacksonJsonProvider.class);
ConnectorProvider connectorProvider = new ApacheConnectorProvider();
config.connectorProvider(connectorProvider);
}
And you need to also add another Maven dependency, jersey-apache-connector
and jersey-test-framework-provider-external
, see Jersey doc
@PATCH
out-of-the-box. – Payola