eclipse-ee4j / eclipse-ee4j/jersey
PATCH fails on https url, SET_METHOD_WORKAROUND seems to be ignored
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Our application uses Jersey client version 2.33. We create a javax.ws.rs.client.Client object and execute the following logic on the Client whenever the method to execute is PATCH.
if (HttpMethod.PATCH.equals(method)) {
client.property(org.glassfish.jersey.client.HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
}
This works fine in general, but fails when the server URL is a https one. In the failing case, we see that the outgoing method is converted to POST. The inference is that the setting of SET_METHOD_WORKAROUND is somehow overridden for https scenario.
In the failing case, we see additional trace statements as below.
2021-06-24 21:03:14.190+0000 | xxxx | :PostmanRuntime/7.28.0:test:FAB-d9674795-dee7-40e5-8b6a-6a5c50c4611c | helidon-3 | | TRACE | sun.net.www.protocol.http.HttpURLConnection | Looking for HttpClient for URL https:// and proxy value of DIRECT
2021-06-24 21:03:14.190+0000 | PATCH | :PostmanRuntime/7.28.0:test:FAB-d9674795-dee7-40e5-8b6a-6a5c50c4611c | helidon-3 | | TRACE | sun.net.www.protocol.http.HttpURLConnection | Creating new HttpsClient with url:https:// and proxy:DIRECT with connect timeout:0
It appears that creation of a new HttpsClient results in loss of the SET_METHOD_WORKAROUND.
Subsequent to the above trace statements, there is a debug statement that shows POST in the failing case (in the working non-https case, it correctly shows PATCH).
2021-06-24 21:03:14.219+0000 | xxxx | :PostmanRuntime/7.28.0:test:FAB-d9674795-dee7-40e5-8b6a-6a5c50c4611c | helidon-3 | | DEBUG | sun.net.www.protocol.http.HttpURLConnection | sun.net.www.MessageHeader@7f50222b153028 pairs: {**POST ** HTTP/1.1: null}{Cookie: …………………………………………
Has this problem been encountered before and is there a remedy/workaround?
We tried passing the property as a -D switch as below.
**java -Djersey.config.client.httpUrlConnection.setMethodWorkaround=true -jar application.jar**
To a bit of my surprise, this solved the problem (the last debug statement correctly showed PATCH).
Since we generate a native image for Production, we tried setting the property programmatically at startup (instead of passing on the command line).
System.setProperty("jersey.config.client.httpUrlConnection.setMethodWorkaround", "true”);
Strangely, I get the following runtime error when executing the PATCH operation.
Caused by: java.lang.NullPointerException
**at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:322)**
at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:265)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:297)
... 77 more
Looking at the Jersey client code, line 322 is the following.
if (request.resolveProperty(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, setMethodWorkaround)) {
It would appear that ‘request’ is NULL, resulting in exception. If that is true, it should have crashed on the previous line (321) that is as below.
final String httpMethod = request.getMethod();
Any idea what the problem is or any other suggested solution for the overall issue? Also, it is strange that there is a difference in behavior when the property is set programmatically, as opposed to on the command line.
Contributor guide
Assessment
This issue has not been assessed yet.