BlockingNotAllowedException в приложении Quarkus при чтении из InputStreamJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 BlockingNotAllowedException в приложении Quarkus при чтении из InputStream

Сообщение Anonymous »

Я разрабатываю приложение Java с использованием Quarkus 3.8.6.redhat-00005. В одном из моих классов я пытаюсь прочитать входной поток ContainerRequestContext при фильтрации запросов. Вот код:

Код: Выделить всё

package br.com.bb.t99.rest;
import io.smallrye.common.annotation.Blocking;
import io.vertx.core.Future;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServerRequest;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerRequestFilter;
import jakarta.ws.rs.container.PreMatching;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.ext.Provider;
import java.io.IOException;
@Provider
@PreMatching
public class TesteFilter implements ContainerRequestFilter {
@Context
HttpServerRequest request;

@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
containerRequestContext.getEntityStream().readAllBytes();
//TODO: Edit the request body
}
}
Когда я пытаюсь запустить это, я получаю исключение BlockingNotAllowedException с сообщением «Попытка блокировки чтения в потоке io». Полное сообщение об ошибке:
org.jboss.resteasy.reactive.common.core.BlockingNotAllowedException: попытка блокировки чтения в потоке io

Код: Выделить всё

19:34:45 ERROR [br.co.bb.de.er.re.fi.ExceptionFilter] (vert.x-eventloop-thread-1)  Resp {statusCode=500, body={errors=[{code=ERRO_SISTEMA, message=Erro na execu??o da solicita??o., variaveisMonitoradas={ORIGEM-ERRO=br.com.bb.t99.rest.TesteFilter - linha: 25., MOTIVO-ERRO=org.jboss.resteasy.reactive.common.core.BlockingNotAllowedException: Attempting a blocking read on io thread, ID-REQUISICAO=347f2608-7f8e-447a-8b35-39d08c8a32f5}}]}}: org.jboss.resteasy.reactive.common.core.BlockingNotAllowedException:  A t t e m p t i n g   a   b l o c k i n g   r e a d   o n   i o   t h r e a d < b r   / >                 a t   o r g . j b o s s . r e s t e a s y . r e a c t i v e . s e r v e r . v e r t x . V e r t x I n p u t S t r e a m $ V e r t x B l o c k i n g I n p u t . r e a d B l o c k i n g ( V e r t x I n p u t S t r e a m . j a v a : 2 4 5 ) < b r   / >                 a t   o r g . j b o s s . r e s t e a s y . r e a c t i v e . s e r v e r . v e r t x . V e r t x I n p u t S t r e a m . r e a d I n t o B u f f e r ( V e r t x I n p u t S t r e a m . j a v a : 1 2 3 ) < b r   / >                 a t   o r g . j b o s s . r e s t e a s y . r e a c t i v e . s e r v er.vertx.VertxInputStream.read(VertxInputStream.java:85)
at java.base/java.io.InputStream.readNBytes(InputStream.java:412)
at java.base/java.io.InputStream.readAllBytes(InputStream.java:349)
at br.com.bb.t99.rest.TesteFilter.filter(TesteFilter.java:25)
at org.jboss.resteasy.reactive.server.handlers.ResourceRequestFilterHandler.handle(ResourceRequestFilterHandler.java:48)
at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:131)
at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:48)
at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:23)
at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:10)
at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1285)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:137)
at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:62)
at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:40)
at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1285)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:137)
at io.quarkus.resteasy.reactive.server.runtime.ResteasyReactiveRecorder$13.handle(ResteasyReactiveRecorder.java:339)
at io.quarkus.resteasy.reactive.server.runtime.ResteasyReactiveRecorder$13.handle(ResteasyReactiveRecorder.java:332)
at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1285)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:137)
at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup.handleHotReplacementRequest(VertxHttpHotReplacementSetup.java:133)
at io.quarkus.vertx.http.runtime.VertxHttpRecorder$5.handle(VertxHttpRecorder.java:415)
at io.quarkus.vertx.http.runtime.VertxHttpRecorder$5.handle(VertxHttpRecorder.java:411)
at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1285)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:137)
at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:68)
at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:37)
at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$2.handle(HttpServerCommonHandlers.java:86)
at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$2.handle(HttpServerCommonHandlers.java:69)
at io.quarkus.vertx.http.runtime.VertxHttpRecorder$1.handle(VertxHttpRecorder.java:147)
at io.quarkus.vertx.http.runtime.VertxHttpRecorder$1.handle(VertxHttpRecorder.java:123)
at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup$4.handle(VertxHttpHotReplacementSetup.java:190)
at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup$4.handle(VertxHttpHotReplacementSetup.java:181)
at io.vertx.core.impl.future.FutureImpl$4.onSuccess(FutureImpl.java:176)
at io.vertx.core.impl.future.FutureBase.lambda$emitSuccess$0(FutureBase.java:60)
at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:1583)

19:34:45 ERROR [or.jb.re.re.se.co.RuntimeExceptionMapper] (vert.x-eventloop-thread-1)   A blocking operation occurred on the IO thread. This likely means you need to use the @io.smallrye.common.annotation.Blocking annotation on the Resource method, class or jakarta.ws.rs.core.Application class.

--
2 tests failed (11 passing, 0 skipped), 2 tests were run in 1737078ms. Tests completed at 19:34:18 due to changes to TesteFilter.class.
Press [e] to edit command line args (currently ''), [r] to re-run, [o] Toggle test output, [:] for the terminal, [h] for more options>
Я не до конца понимаю, почему это происходит. Есть ли предпочтительный способ неблокирующего чтения и редактирования тела запроса в Quarkus? Как можно решить эту проблему? Буду очень признателен за любые рекомендации.
Я уже пробовал добавить аннотацию @io.smallrye.common.annotation.Blocking в конечную точку, класс, расширяющий jakarta.ws.rs.core. .Приложение, и сам фильтр. Однако все эти попытки решить проблему не увенчались успехом.

Подробнее здесь: https://stackoverflow.com/questions/790 ... nputstream
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»