From 017a5d58b684d261cf6eca9d93be52d08da4a541 Mon Sep 17 00:00:00 2001 From: Jose Carranza Date: Wed, 15 Nov 2023 15:11:57 +0100 Subject: [PATCH] remove unecessary specific Router because @Observe Router router already do the magic remove @ApplicationScope not need this class as a bean and remove @Inject over a resource(bean) not needed either convert shoppingList as static field and improve the get method to avoid lazily initialization --- .../quarkus/ts/vertx/web/validation/ShopResource.java | 7 ++----- .../web/validation/ValidationHandlerOnRoutes.java | 11 +---------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ShopResource.java b/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ShopResource.java index d02040b597..73ee3bca3f 100644 --- a/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ShopResource.java +++ b/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ShopResource.java @@ -14,9 +14,9 @@ @Produces(MediaType.APPLICATION_JSON) public class ShopResource { - private List shoppingList; + private static List shoppingList = createSampleProductList(); - private List createSampleProductList() { + private static List createSampleProductList() { shoppingList = new ArrayList<>(); shoppingList.add(new ShoppingList(UUID.randomUUID(), "ListName1", 25, new ArrayList<>(Arrays.asList("Carrots", "Water", "Cheese", "Beer")))); @@ -27,9 +27,6 @@ private List createSampleProductList() { @GET public List get() { - if (shoppingList == null) { - createSampleProductList(); - } return shoppingList; } diff --git a/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ValidationHandlerOnRoutes.java b/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ValidationHandlerOnRoutes.java index a512a9f7dc..4502206469 100644 --- a/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ValidationHandlerOnRoutes.java +++ b/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ValidationHandlerOnRoutes.java @@ -12,7 +12,6 @@ import java.util.stream.Collectors; import jakarta.annotation.PostConstruct; -import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.event.Observes; import jakarta.inject.Inject; import jakarta.ws.rs.core.HttpHeaders; @@ -23,7 +22,6 @@ import io.vertx.core.json.Json; import io.vertx.core.json.JsonArray; import io.vertx.ext.web.Router; -import io.vertx.ext.web.handler.BodyHandler; import io.vertx.ext.web.validation.BadRequestException; import io.vertx.ext.web.validation.BodyProcessorException; import io.vertx.ext.web.validation.ParameterProcessorException; @@ -39,7 +37,6 @@ import io.vertx.json.schema.SchemaRouterOptions; import io.vertx.json.schema.common.dsl.ObjectSchemaBuilder; -@ApplicationScoped public class ValidationHandlerOnRoutes { //TODO when Quarkus use vert.x version 4.4.6 we can use SchemaRepository instead of SchemaParser with SchemaRouter //private SchemaRepository schemaRepository =SchemaRepository.create(new JsonSchemaOptions().setDraft(Draft.DRAFT7).setBaseUri(BASEURI)); @@ -49,20 +46,14 @@ public class ValidationHandlerOnRoutes { @Inject Vertx vertx; - private Router router; - - @Inject - ShopResource shopResource; + private static ShopResource shopResource = new ShopResource(); private static final String ERROR_MESSAGE = "{\"error\": \"%s\"}"; private static final String SHOPPINGLIST_NOT_FOUND = "Shopping list not found in the list or does not exist with that name or price"; @PostConstruct void initialize() { - router = Router.router(vertx); - router.route().handler(BodyHandler.create()); schemaParser = createSchema(); - validateHandlerSoppingList(router); } private SchemaParser createSchema() {