Skip to content

Commit ebb8e61

Browse files
committed
♻️ refactor to programatic route registration
1 parent a3e81cd commit ebb8e61

File tree

1 file changed

+28
-10
lines changed
  • runtime/src/main/java/io/quarkiverse/githubapp/runtime

1 file changed

+28
-10
lines changed

runtime/src/main/java/io/quarkiverse/githubapp/runtime/Routes.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static io.quarkiverse.githubapp.runtime.Headers.X_REQUEST_ID;
88

99
import java.io.IOException;
10+
import java.io.UncheckedIOException;
1011
import java.nio.charset.StandardCharsets;
1112
import java.nio.file.Files;
1213
import java.nio.file.Path;
@@ -28,14 +29,13 @@
2829
import io.quarkus.runtime.LaunchMode;
2930
import io.quarkus.runtime.StartupEvent;
3031
import io.quarkus.vertx.http.runtime.HttpConfiguration;
31-
import io.quarkus.vertx.web.Header;
32-
import io.quarkus.vertx.web.Route;
33-
import io.quarkus.vertx.web.Route.HandlerType;
34-
import io.quarkus.vertx.web.Route.HttpMethod;
3532
import io.quarkus.vertx.web.RoutingExchange;
33+
import io.quarkus.vertx.web.runtime.RoutingExchangeImpl;
3634
import io.vertx.core.json.Json;
3735
import io.vertx.core.json.JsonObject;
36+
import io.vertx.ext.web.Router;
3837
import io.vertx.ext.web.RoutingContext;
38+
import io.vertx.ext.web.handler.BodyHandler;
3939

4040
@Singleton
4141
public class Routes {
@@ -72,14 +72,32 @@ public void init(@Observes StartupEvent startupEvent) throws IOException {
7272
}
7373
}
7474

75-
@Route(path = "/", type = HandlerType.BLOCKING, methods = HttpMethod.POST, consumes = "application/json", produces = "application/json")
75+
public void init(@Observes Router router) {
76+
router.post("/")
77+
.handler(BodyHandler.create()) // this is required so that the body to be read by subsequent handlers
78+
.blockingHandler(routingContext -> {
79+
try {
80+
handleRequest(
81+
routingContext,
82+
new RoutingExchangeImpl(routingContext),
83+
routingContext.request().getHeader(X_REQUEST_ID),
84+
routingContext.request().getHeader(X_HUB_SIGNATURE_256),
85+
routingContext.request().getHeader(X_GITHUB_DELIVERY),
86+
routingContext.request().getHeader(X_GITHUB_EVENT),
87+
routingContext.request().getHeader(X_QUARKIVERSE_GITHUB_APP_REPLAYED));
88+
} catch (IOException e) {
89+
throw new UncheckedIOException(e);
90+
}
91+
});
92+
}
93+
7694
public void handleRequest(RoutingContext routingContext,
7795
RoutingExchange routingExchange,
78-
@Header(X_REQUEST_ID) String requestId,
79-
@Header(X_HUB_SIGNATURE_256) String hubSignature,
80-
@Header(X_GITHUB_DELIVERY) String deliveryId,
81-
@Header(X_GITHUB_EVENT) String event,
82-
@Header(X_QUARKIVERSE_GITHUB_APP_REPLAYED) String replayed) throws IOException {
96+
String requestId,
97+
String hubSignature,
98+
String deliveryId,
99+
String event,
100+
String replayed) throws IOException {
83101

84102
if (!launchMode.isDevOrTest() && (isBlank(deliveryId) || isBlank(hubSignature))) {
85103
routingExchange.response().setStatusCode(400).end();

0 commit comments

Comments
 (0)