|
7 | 7 | import static io.quarkiverse.githubapp.runtime.Headers.X_REQUEST_ID; |
8 | 8 |
|
9 | 9 | import java.io.IOException; |
| 10 | +import java.io.UncheckedIOException; |
10 | 11 | import java.nio.charset.StandardCharsets; |
11 | 12 | import java.nio.file.Files; |
12 | 13 | import java.nio.file.Path; |
|
28 | 29 | import io.quarkus.runtime.LaunchMode; |
29 | 30 | import io.quarkus.runtime.StartupEvent; |
30 | 31 | 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; |
35 | 32 | import io.quarkus.vertx.web.RoutingExchange; |
| 33 | +import io.quarkus.vertx.web.runtime.RoutingExchangeImpl; |
36 | 34 | import io.vertx.core.json.Json; |
37 | 35 | import io.vertx.core.json.JsonObject; |
| 36 | +import io.vertx.ext.web.Router; |
38 | 37 | import io.vertx.ext.web.RoutingContext; |
| 38 | +import io.vertx.ext.web.handler.BodyHandler; |
39 | 39 |
|
40 | 40 | @Singleton |
41 | 41 | public class Routes { |
@@ -72,14 +72,32 @@ public void init(@Observes StartupEvent startupEvent) throws IOException { |
72 | 72 | } |
73 | 73 | } |
74 | 74 |
|
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 | + |
76 | 94 | public void handleRequest(RoutingContext routingContext, |
77 | 95 | 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 { |
83 | 101 |
|
84 | 102 | if (!launchMode.isDevOrTest() && (isBlank(deliveryId) || isBlank(hubSignature))) { |
85 | 103 | routingExchange.response().setStatusCode(400).end(); |
|
0 commit comments