有人在使用与quarkus的vert.x web api合同吗?我正在尝试使用它,但是,我相信我有一个配置问题。以下是我尝试过的:
由于没有关于如何配置的直接指南,我把vert.x指南弄混了(https://vertx.io/docs/3.9.6/vertx-web-api-contract/java/#_openapi_3)与quarkusReact路线一(https://quarkus.io/guides/reactive-routes#using-网络路由器)。其想法是将来自openapi3routerfactory的路由器作为quarkus创建的主路由器的子例程安装。
不幸的是,当我尝试访问我的终结点时,出现以下错误:
2021-04-22 21:14:58,696 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-4) HTTP Request to /api/tasks failed, error id: 0e695191-ed81-4938-bc0f-3beb2d874a34-4: java.lang.IllegalStateException: Request has already been read
at io.vertx.core.http.impl.HttpServerRequestImpl.checkEnded(HttpServerRequestImpl.java:596)
at io.vertx.core.http.impl.HttpServerRequestImpl.handler(HttpServerRequestImpl.java:306)
at io.quarkus.vertx.http.runtime.ResumingRequestWrapper.handler(ResumingRequestWrapper.java:18)
at io.vertx.ext.web.impl.HttpServerRequestWrapper.handler(HttpServerRequestWrapper.java:82)
at io.vertx.ext.web.handler.impl.BodyHandlerImpl.handle(BodyHandlerImpl.java:86)
at io.vertx.ext.web.handler.impl.BodyHandlerImpl.handle(BodyHandlerImpl.java:42)
at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
at io.vertx.ext.web.impl.RoutingContextWrapper.next(RoutingContextWrapper.java:176)
at io.vertx.ext.web.impl.RouterImpl.handleContext(RouterImpl.java:235)
at io.vertx.ext.web.impl.RouteImpl$$Lambda$556/0x0000000065531848.handle(Unknown Source)
at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
at io.quarkus.vertx.http.runtime.VertxHttpRecorder$4.handle(VertxHttpRecorder.java:338)
at io.quarkus.vertx.http.runtime.VertxHttpRecorder$4.handle(VertxHttpRecorder.java:316)
at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup$3.handle(VertxHttpHotReplacementSetup.java:86)
at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup$3.handle(VertxHttpHotReplacementSetup.java:75)
at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:327)
at io.vertx.core.impl.ContextImpl$$Lambda$642/0x00000000659026f0.handle(Unknown Source)
at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
at io.vertx.core.impl.EventLoopContext$$Lambda$569/0x0000000065689a48.run(Unknown Source)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
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:853)
有人知道什么地方可能出错吗?这是我的密码:
package systems.lil.infra.gateway.config;
import io.swagger.v3.oas.models.Operation;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.api.contract.RouterFactoryOptions;
import io.vertx.ext.web.api.contract.openapi3.OpenAPI3RouterFactory;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ApplicationScoped
public class OpenApi3Server {
private static final Logger logger = LoggerFactory.getLogger(OpenApi3Server.class);
private Vertx vertx;
@Inject
public OpenApi3Server(Vertx vertx) {
this.vertx = vertx;
}
public void init(@Observes Router mainRouter) {
OpenAPI3RouterFactory.create(vertx, "/api/api.yaml", ar -> {
if (ar.succeeded()) {
logger.info("Building OpenAPI Router Factory...");
OpenAPI3RouterFactory routerFactory = ar.result();
RouterFactoryOptions options = new RouterFactoryOptions();
options
.setOperationModelKey("operationPOJO")
.setRequireSecurityHandlers(false);
routerFactory.setOptions(options);
routerFactory.addHandlerByOperationId("getTasks", routingContext -> {
routingContext.request().pause();
Operation operation = routingContext.get("operationPOJO");
logger.info("Handling operation {}", operation.getOperationId());
JsonObject object = new JsonObject("{\"operation\":\"getTasks\"}");
routingContext.response().setStatusCode(200).setStatusMessage("OK").end(object.encodePrettily());
logger.info("Route called");
});
Router router = routerFactory.getRouter();
mainRouter.mountSubRouter("/api", router);
logger.info("SubRouter Mounted...");
}
});
}
}
1条答案
按热度按时间oxf4rvwz1#
从日志来看,你有两个
BodyHandlers
设置。openapi文档对此提供了支持:
路由器工厂自动装载bodyhandler来管理请求主体。您可以使用setbodyhandler配置bodyhandler的示例(例如更改上载目录)。
https://vertx.io/docs/3.9.6/vertx-web-api-contract/java/#_body_handler
您可以尝试将body处理程序从openapi设置为dummy处理程序: