I used Java CompletableFuture, like this one
CompletableFuture.runAsync(() -> {//Some code here });
When I try to use Restaasy Client inside this block of code, I get
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 a client outside of completablefuture, it works. Restaasy 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 ran the resteasy outisde of completablefuture code to “fix” the problem, but would like to understand why this is happening.
The resteasy code inside CompletableFuture is as follows:
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 of CompletableFuture works
m1416 source
share