0

I have a rest endpoint which reads the request body and is mapped to Java POJO.

The issue I am facing is I get the below exception when I send the request as a GET. But the exception is not thrown when I change the type to POST and request succeed.

@Path("/test")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Uni<List<String>> getData(ReqeustBody requestBody) {
//app code
}

My thought is that jackson library that does the mapping of request body to pojo is causing the exception. But why it fails only for GET and not for POST.

Any leads will be of help.

Below is the stack trace.

{
    "details": "Error id c307388f-26ed-4108-bb1c-12032de09243-1, org.jboss.resteasy.reactive.common.core.BlockingNotAllowedException: Attempting a blocking read on io thread",
    "stack": "org.jboss.resteasy.reactive.common.core.BlockingNotAllowedException: Attempting a blocking read on io thread\r\n\tat org.jboss.resteasy.reactive.server.vertx.VertxInputStream$VertxBlockingInput.readBlocking(VertxInputStream.java:242)\r\n\tat org.jboss.resteasy.reactive.server.vertx.VertxInputStream.readIntoBuffer(VertxInputStream.java:120)\r\n\tat org.jboss.resteasy.reactive.server.vertx.VertxInputStream.read(VertxInputStream.java:82)\r\n\tat com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.ensureLoaded(ByteSourceJsonBootstrapper.java:539)\r\n\tat com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.detectEncoding(ByteSourceJsonBootstrapper.java:133)\r\n\tat com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.constructParser(ByteSourceJsonBootstrapper.java:256)\r\n\tat com.fasterxml.jackson.core.JsonFactory._createParser(JsonFactory.java:1655)\r\n\tat com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:1083)\r\n\tat com.fasterxml.jackson.databind.ObjectReader.createParser(ObjectReader.java:1049)\r\n\tat com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1427)\r\n\tat io.quarkus.resteasy.reactive.jackson.runtime.serialisers.ServerJacksonMessageBodyReader.doReadFrom(ServerJacksonMessageBodyReader.java:62)\r\n\tat io.quarkus.resteasy.reactive.jackson.runtime.serialisers.ServerJacksonMessageBodyReader.readFrom(ServerJacksonMessageBodyReader.java:53)\r\n\tat org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.readFrom(RequestDeserializeHandler.java:108)\r\n\tat org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.handle(RequestDeserializeHandler.java:68)\r\n\tat org.jboss.resteasy.reactive.server.handlers.RequestDeserializeHandler.handle(RequestDeserializeHandler.java:25)\r\n\tat org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)\r\n\tat org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:49)\r\n\tat org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:17)\r\n\tat org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:7)\r\n\tat io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1212)\r\n\tat io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:163)\r\n\tat io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:141)\r\n\tat io.quarkus.vertx.http.runtime.StaticResourcesRecorder$2.handle(StaticResourcesRecorder.java:83)\r\n\tat io.quarkus.vertx.http.runtime.StaticResourcesRecorder$2.handle(StaticResourcesRecorder.java:67)\r\n\tat io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1212)\r\n\tat io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:126)\r\n\tat io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:141)\r\n\tat io.vertx.ext.web.handler.impl.StaticHandlerImpl.lambda$sendStatic$1(StaticHandlerImpl.java:274)\r\n\tat io.vertx.core.impl.future.FutureImpl$3.onSuccess(FutureImpl.java:141)\r\n\tat io.vertx.core.impl.future.FutureBase.lambda$emitSuccess$0(FutureBase.java:54)\r\n\tat io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)\r\n\tat io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)\r\n\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:503)\r\n\tat io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)\r\n\tat io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)\r\n\tat io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)\r\n\tat java.base/java.lang.Thread.run(Thread.java:834)"
}
Jaiprasad
  • 149
  • 11
  • See even with GET request body can be mapped to pojo class , the problem is it is not able to do it in non-blocking way , whereas it is able to do it for POST – Jaiprasad Jul 26 '22 at 09:16
  • could you add your dependencies from pom.xml please ? – Jacouille Jul 26 '22 at 09:18
  • Quarkus version 2.9.0.Final io.quarkus quarkus-arc io.quarkus quarkus-reactive-pg-client io.quarkus quarkus-resteasy-reactive-jackson – Jaiprasad Jul 26 '22 at 10:04

1 Answers1

2

It looks like resteasy-jaxrs doesn't allow to invoke the HTTP get method with the body. Similar question with an alternative solution: Can RestEasy serialize a POJO for a @GET method?

pholak
  • 158
  • 1
  • 8
  • thank you , let me try this. – Jaiprasad Jul 25 '22 at 18:58
  • The post talks about converting query params to a pojo class , but say if the request body is like ``` { "id": " 1, "values" : [ "x" , "y" , "z"] } and Java Pojo like public class RequestBody { long id; List values; } ``` how can we do it in this case. – Jaiprasad Jul 26 '22 at 06:46