Java 如何修复';请求已被读取';Vert.x中的错误

Java 如何修复';请求已被读取';Vert.x中的错误,java,vert.x,Java,Vert.x,我正在设置一个api网关。我想在请求服务之前验证授权令牌。我得到非法状态异常:请求已被读取。请帮忙 我将测试项目代码上传到GitHub。 例外情况: java.lang.IllegalStateException: Request has already been read at io.vertx.core.http.impl.HttpServerRequestImpl.checkEnded(HttpServerRequestImpl.java:599) at io.vertx

我正在设置一个api网关。我想在请求服务之前验证授权令牌。我得到非法状态异常:请求已被读取。请帮忙

我将测试项目代码上传到GitHub。

例外情况:

java.lang.IllegalStateException: Request has already been read
    at io.vertx.core.http.impl.HttpServerRequestImpl.checkEnded(HttpServerRequestImpl.java:599)
    at io.vertx.core.http.impl.HttpServerRequestImpl.setExpectMultipart(HttpServerRequestImpl.java:431)
    at io.vertx.ext.web.impl.HttpServerRequestWrapper.setExpectMultipart(HttpServerRequestWrapper.java:208)
    at com.demo.HttpServerVerticle.lambda$start$8(HttpServerVerticle.java:62)
    at io.vertx.ext.web.impl.RouteImpl.handleContext(RouteImpl.java:232)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:121)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:134)
    at com.demo.HttpServerVerticle.authHandler(HttpServerVerticle.java:132)
    at com.demo.HttpServerVerticle.lambda$null$0(HttpServerVerticle.java:53)
    at io.vertx.ext.web.client.impl.HttpContext.handleDispatchResponse(HttpContext.java:285)
    at io.vertx.ext.web.client.impl.HttpContext.execute(HttpContext.java:272)
    at io.vertx.ext.web.client.impl.HttpContext.next(HttpContext.java:250)
    at io.vertx.ext.web.client.impl.predicate.PredicateInterceptor.handle(PredicateInterceptor.java:69)
    at io.vertx.ext.web.client.impl.predicate.PredicateInterceptor.handle(PredicateInterceptor.java:32)
    at io.vertx.ext.web.client.impl.HttpContext.next(HttpContext.java:247)
    at io.vertx.ext.web.client.impl.HttpContext.fire(HttpContext.java:257)
    at io.vertx.ext.web.client.impl.HttpContext.dispatchResponse(HttpContext.java:218)
    at io.vertx.ext.web.client.impl.HttpContext.lambda$null$2(HttpContext.java:341)
    at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
    at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:495)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:748)


我解决了这个问题。在调用auth api之前,我暂停原始请求,并在授权完成后恢复缓冲区处理

router.route().path("/user/admin").method(HttpMethod.POST)
        .handler(rct -> {

            HttpServerRequest request = rct.request().setExpectMultipart(true);

            request.pause(); // Here is to pasue the origin request.

            MultiMap headers = request.headers();

            JsonObject param = new JsonObject().put("requestUrl", "http://localhost:18080/authorize")
                    .put("httpMethod", "POST");

            webClient.postAbs("http://localhost:18080/authorize")
                    .timeout(6000)
                    .putHeader("Content-Type", "application/json")
                    .putHeader("Authorization", headers.get("Authorization"))
                    .as(BodyCodec.jsonObject())
                    .sendJsonObject(param, ar -> authHandler(rct, ar));

        });
router.route().path("/user/admin").method(HttpMethod.POST)
        .handler(rct -> {

            HttpServerRequest request = rct.request().setExpectMultipart(true);

            request.pause(); // Here is to pasue the origin request.

            MultiMap headers = request.headers();

            JsonObject param = new JsonObject().put("requestUrl", "http://localhost:18080/authorize")
                    .put("httpMethod", "POST");

            webClient.postAbs("http://localhost:18080/authorize")
                    .timeout(6000)
                    .putHeader("Content-Type", "application/json")
                    .putHeader("Authorization", headers.get("Authorization"))
                    .as(BodyCodec.jsonObject())
                    .sendJsonObject(param, ar -> authHandler(rct, ar));

        });