I have been using Java's CompletableFuture like this
CompletableFuture.runAsync(() -> {//Some code here });
When I try to use a Resteasy Client inside this block of code I get a
javax.ws.rs.ProcessingException: Unable to find a MessageBodyReader of content-type application/json;charset=utf-8 and type class java.lang.String
If i use the client outside of the completablefuture it works. The Resteasy code looks something like this
ResteasyClient client = new ResteasyClientBuilder().build();
client.register(new AcceptEncodingFilter("gzip"));
ResteasyWebTarget target = client.target(exampleURL);
target = target.queryParam("1", 1)
.queryParam("2", "1")
.queryParam("3", 3)
.queryParam("4", 4)
.queryParam("5", "5");
Response response = target.request().get();
resultString = response.readEntity(String.class);
I will run the resteasy code outisde of the completablefuture to "fix" the problem but would like to understand why this happens.
The resteasy code inside the CompletableFuture looks like this:
CompletableFuture.runAsync(() -> {
try {
ResteasyClient client = new ResteasyClientBuilder().build();
client.register(new AcceptEncodingFilter("gzip"));
ResteasyWebTarget target = client.target("http://test.com");
target = target.queryParam("1", "1")
.queryParam("2", "2")
.queryParam("3", "3")
.queryParam("4", "4")
.queryParam("5", "5");
Response response = target.request().get();
String resultString = response.readEntity(String.class);
response.close();
client.close();
} catch (Exception e){
e.printStackTrace();
}
});
the same code outside the CompletableFuture works
CompleteableFuture
uses the common ForkJoinPool for selecting threads to ansychronously work in. Maybe there is some Context missing within those threads. I don't know the play framework/netty, but if one of them provides a ThreadFactory or a Threadpool with Threads in its context, you may try the runAsync(Runnable, Executor) method with those to provide the context. – AeroscopeAcceptEncodingGZIPFilter
– Nert