Skip to content

Commit

Permalink
Use RouteBuildItem instead of DefaultRouteBuildItem
Browse files Browse the repository at this point in the history
  • Loading branch information
matejvasek authored and gsmet committed Oct 13, 2020
1 parent 20e6bdb commit b7f5bd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

import org.jboss.logging.Logger;

Expand All @@ -26,8 +25,10 @@
import io.quarkus.funqy.runtime.bindings.knative.events.KnativeEventsBindingRecorder;
import io.quarkus.jackson.ObjectMapperProducer;
import io.quarkus.vertx.core.deployment.CoreVertxBuildItem;
import io.quarkus.vertx.http.deployment.DefaultRouteBuildItem;
import io.vertx.ext.web.Route;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import io.quarkus.vertx.http.runtime.HttpBuildTimeConfig;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;

public class FunqyKnativeEventsBuildStep {
private static final Logger log = Logger.getLogger(FunqyKnativeEventsBuildStep.class);
Expand Down Expand Up @@ -60,20 +61,35 @@ public void boot(ShutdownContextBuildItem shutdown,
FunqyKnativeEventsConfig eventsConfig,
KnativeEventsBindingRecorder binding,
Optional<FunctionInitializedBuildItem> hasFunctions,
List<FunctionBuildItem> functions,
BuildProducer<FeatureBuildItem> feature,
BuildProducer<DefaultRouteBuildItem> defaultRoutes,
BuildProducer<RouteBuildItem> routes,
CoreVertxBuildItem vertx,
BeanContainerBuildItem beanContainer,
HttpBuildTimeConfig httpConfig,
ExecutorBuildItem executorBuildItem) throws Exception {
if (!hasFunctions.isPresent() || hasFunctions.get() == null)
return;

feature.produce(new FeatureBuildItem(FUNQY_KNATIVE_FEATURE));
Consumer<Route> ut = binding.start(funqyConfig, eventsConfig, vertx.getVertx(),
Handler<RoutingContext> handler = binding.start(funqyConfig, eventsConfig, vertx.getVertx(),
shutdown,
beanContainer.getValue(),
executorBuildItem.getExecutorProxy());

defaultRoutes.produce(new DefaultRouteBuildItem(ut));
String rootPath = httpConfig.rootPath;
if (rootPath == null) {
rootPath = "/";
} else if (!rootPath.endsWith("/")) {
rootPath += "/";
}

routes.produce(new RouteBuildItem(rootPath, handler, false));

for (FunctionBuildItem function : functions) {
String name = function.getFunctionName() == null ? function.getMethodName() : function.getFunctionName();
String path = rootPath + name;
routes.produce(new RouteBuildItem(path, handler, false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.jboss.logging.Logger;
Expand All @@ -29,7 +28,6 @@
import io.quarkus.runtime.annotations.Recorder;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;

/**
Expand Down Expand Up @@ -94,7 +92,7 @@ private ObjectMapper getObjectMapper() {
return new ObjectMapper();
}

public Consumer<Route> start(
public Handler<RoutingContext> start(
FunqyConfig funqyConfig,
FunqyKnativeEventsConfig eventsConfig,
Supplier<Vertx> vertx,
Expand Down Expand Up @@ -150,12 +148,6 @@ public void run() {
Handler<RoutingContext> handler = new VertxRequestHandler(vertx.get(), beanContainer, objectMapper, eventsConfig,
defaultInvoker, typeTriggers, executor);

return new Consumer<Route>() {

@Override
public void accept(Route route) {
route.handler(handler);
}
};
return handler;
}
}

0 comments on commit b7f5bd3

Please sign in to comment.