With the following code, using jersey
:
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client4</artifactId>
<version>1.13-b01</version>
I have issues using custom request methods, like FOOBAR, PATCH, SEARCH, etc. Those which do not exist in httpUrlConnection
.
DefaultClientConfig config = new DefaultClientConfig();
config.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
Client c = Client.create(config);
Form f = new Form();
f.add("id", "foobar");
WebResource r = c.resource("http://127.0.0.1/foo");
String methodName = "foobar";
String response = r.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept(MediaType.APPLICATION_JSON_TYPE).header("USER-AGENT", "my-java-sdk /1.1").method(methodName.toUpperCase(), String.class, f);
The result is the following exception:
com.sun.jersey.api.client.ClientHandlerException: java.net.ProtocolException: Invalid HTTP method: FOOBAR
I have tried various ways to try and resolve this, without success.
config.getProperties()
line. Still receiving the errorLong story short, I want to implement similar functionality as is available in via Java:
Thank you in advance for your feedback
With Jersey 2.x Client
, we would set the property
HttpUrlConnectorProvider.SET_METHOD_WORKAROUND
to true
Client client = ClientBuilder.newClient();
client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
String response = client.target(url).request().method("PATCH", entity, String.class);
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