Jersey Client Issue

197 views
Skip to first unread message

Thord Setsaas

unread,
Jun 1, 2015, 9:24:15 AM6/1/15
to dropwiz...@googlegroups.com
I am currently experiencing an issue with Dropwizard and using the Jersey HTTP client.

I have code similar to the following that executes a HTTP GET request against a given URL, and it works just as I want it to in most cases.

Client client = ClientBuilder.newBuilder()
.property(ClientProperties.CONNECT_TIMEOUT, 20000)
.property(ClientProperties.READ_TIMEOUT, 20000)
.build();

WebTarget target = client.target(url);
AsyncInvoker request = target
.request(MediaType.APPLICATION_JSON_TYPE)
.headers(headers)
.async();
request.get(new InvocationCallback<Response>() {
@Override
public void completed(Response response) {
System.out.println(response.readEntity(String.class));
}

@Override
public void failed(Throwable throwable) {
throwable.printStackTrace();
}
});

But if my URL contains a underscore character I end up with the following exception:

javax.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Invalid characters in hostname
at org.glassfish.jersey.client.ClientRuntime.processFailure(ClientRuntime.java:192)
at org.glassfish.jersey.client.ClientRuntime.access$400(ClientRuntime.java:74)
at org.glassfish.jersey.client.ClientRuntime$1.run(ClientRuntime.java:172)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:340)
at org.glassfish.jersey.client.ClientRuntime$2.run(ClientRuntime.java:200)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Invalid characters in hostname
at java.net.HostPortrange.toLowerCase(HostPortrange.java:189)
at java.net.HostPortrange.<init>(HostPortrange.java:150)
at java.net.URLPermission$Authority.<init>(URLPermission.java:481)
at java.net.URLPermission.parseURI(URLPermission.java:449)
at java.net.URLPermission.init(URLPermission.java:170)
at java.net.URLPermission.<init>(URLPermission.java:166)
at sun.net.www.protocol.http.HttpURLConnection.URLtoSocketPermission(HttpURLConnection.java:1032)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1425)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:2978)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:489)
at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:335)
at org.glassfish.jersey.client.HttpUrlConnector.access$000(HttpUrlConnector.java:91)
at org.glassfish.jersey.client.HttpUrlConnector$3.run(HttpUrlConnector.java:254)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at jersey.repackaged.com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:293)
at jersey.repackaged.com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:49)
at jersey.repackaged.com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:45)
at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:250)
at org.glassfish.jersey.client.ClientRuntime$1.run(ClientRuntime.java:168)
... 12 more

After some searching it seems to be the exact same bug as the one described here https://bugs.openjdk.java.net/browse/JDK-8072064 and https://bugs.openjdk.java.net/browse/JDK-8029354, but I am not able to get it to work.
They say this has been fixed in Java8u5, and I have tried with multiple version without getting it to work. Including the Java8u60ea version.
$ java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

What is also strange is that if I try to execute the same code before I execute the run() method in Dropwizard it work as expected, even with the underscore.
So my issue seems to somehow be related to dropwizard, (and I suspect maybe some auto configuration or dependency imports ?) but I cannot seem to figure out what it is that is affecting it, and making it not work. 

Does anyone have any suggestions as to how to make this work or what it is that is causing these issues?






Reply all
Reply to author
Forward
0 new messages