Skip to content

Commit

Permalink
Leverage platform http service in camel-knative apache#264
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Mar 19, 2020
1 parent 0448459 commit fffb9c1
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.apache.camel.impl.health.ContextHealthCheck;
import org.apache.camel.impl.health.RoutesHealthCheckRepository;
import org.apache.camel.k.ContextCustomizer;
import org.apache.camel.k.http.PlatformHttpRouter;
import org.apache.camel.k.http.PlatformHttp;

public class HealthContextCustomizer implements ContextCustomizer {
public static final String DEFAULT_PATH = "/health";
Expand Down Expand Up @@ -110,7 +110,7 @@ public void apply(CamelContext camelContext) {
// add health route
addRoute(
camelContext,
PlatformHttpRouter.lookup(camelContext).get()
PlatformHttp.lookup(camelContext).router()
);
}

Expand Down
1 change: 0 additions & 1 deletion camel-k-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<modules>
<module>camel-k-runtime-main</module>
<module>camel-k-runtime-health</module>
<module>camel-k-runtime-http</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
public class KnativeRecorder {
public RuntimeValue<KnativeComponent> createKnativeComponent(Supplier<Vertx> vertx) {
KnativeHttpTransport transport = new KnativeHttpTransport();
transport.setVertx(vertx.get());

KnativeComponent component = new KnativeComponent();
component.setTransport(transport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-main</artifactId>
<artifactId>camel-k-runtime-parent</artifactId>
<version>1.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,28 @@
*/
package org.apache.camel.k.http;

import io.vertx.core.Vertx;
import io.vertx.ext.web.Router;
import org.apache.camel.CamelContext;
import org.apache.camel.component.platform.http.PlatformHttpConstants;
import org.apache.camel.support.CamelContextHelper;

public class PlatformHttpRouter {
public class PlatformHttp {
public static final String PLATFORM_HTTP_ROUTER_NAME = PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME + "-router";

private final Vertx vertx;
private final Router router;

public PlatformHttpRouter(Router router) {
public PlatformHttp(Vertx vertx, Router router) {
this.vertx = vertx;
this.router = router;
}

public Router get() {
public Vertx vertx() {
return vertx;
}

public Router router() {
return router;
}

Expand All @@ -40,11 +47,11 @@ public Router get() {
//
// **********************

public static PlatformHttpRouter lookup(CamelContext camelContext) {
public static PlatformHttp lookup(CamelContext camelContext) {
return CamelContextHelper.mandatoryLookup(
camelContext,
PlatformHttpRouter.PLATFORM_HTTP_ROUTER_NAME,
PlatformHttpRouter.class
PlatformHttp.PLATFORM_HTTP_ROUTER_NAME,
PlatformHttp.class
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private CompletionStage<Void> startAsync() {

router.mountSubRouter(configuration.getPath(), subRouter);

context.getRegistry().bind(PlatformHttpRouter.PLATFORM_HTTP_ROUTER_NAME, new PlatformHttpRouter(subRouter));
context.getRegistry().bind(PlatformHttp.PLATFORM_HTTP_ROUTER_NAME, new PlatformHttp(subRouter));

//HttpServerOptions options = new HttpServerOptions();
if (configuration.getSslContextParameters() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.apache.camel.TypeConverter;
import org.apache.camel.component.platform.http.PlatformHttpEndpoint;
import org.apache.camel.component.platform.http.spi.Method;
import org.apache.camel.k.http.PlatformHttpRouter;
import org.apache.camel.k.http.PlatformHttp;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.support.DefaultConsumer;
import org.apache.camel.support.DefaultMessage;
Expand Down Expand Up @@ -75,10 +75,10 @@ protected void doStart() throws Exception {
super.doStart();

final PlatformHttpEndpoint endpoint = getEndpoint();
final PlatformHttpRouter router = PlatformHttpRouter.lookup(endpoint.getCamelContext());
final PlatformHttp router = PlatformHttp.lookup(endpoint.getCamelContext());
final String path = endpoint.getPath();
final String vertxPathParamPath = PATH_PARAMETER_PATTERN.matcher(path).replaceAll(":$1");
final Route newRoute = router.get().route(vertxPathParamPath);
final Route newRoute = router.router().route(vertxPathParamPath);

final Set<Method> methods = Method.parseList(endpoint.getHttpMethodRestrict());
if (!methods.equals(Method.getAll())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testPlatformHttpServiceCustomizer(String path) throws Exception {

httpService.apply(runtime.getCamelContext());

PlatformHttpRouter.lookup(runtime.getCamelContext()).get().route(HttpMethod.GET, "/my/path")
PlatformHttp.lookup(runtime.getCamelContext()).router().route(HttpMethod.GET, "/my/path")
.handler(routingContext -> {
JsonObject response = new JsonObject();
response.put("status", "UP");
Expand Down
12 changes: 3 additions & 9 deletions camel-knative/camel-knative-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
<!-- -->
<!-- ****************************** -->

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core-engine</artifactId>
Expand All @@ -56,10 +50,10 @@
</dependency>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>${vertx.version}</version>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-runtime-http</artifactId>
</dependency>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,36 @@
public class KnativeHttpConsumer extends DefaultConsumer implements KnativeHttp.PredicatedHandler {
private final KnativeHttpTransport transport;
private final Predicate<HttpServerRequest> filter;
private final KnativeHttp.ServerKey key;
private final KnativeEnvironment.KnativeServiceDefinition serviceDefinition;
private final KnativeHttpConsumerDispatcher dispatcher;
private final HeaderFilterStrategy headerFilterStrategy;

public KnativeHttpConsumer(
KnativeHttpTransport transport,
Endpoint endpoint,
KnativeEnvironment.KnativeServiceDefinition serviceDefinition,
KnativeHttpConsumerDispatcher dispatcher,
Processor processor) {

super(endpoint, processor);

this.transport = transport;
this.serviceDefinition = serviceDefinition;
this.dispatcher = dispatcher;
this.headerFilterStrategy = new KnativeHttpHeaderFilterStrategy();
this.key = new KnativeHttp.ServerKey(serviceDefinition.getHost(), serviceDefinition.getPortOrDefault(KnativeHttp.DEFAULT_PORT));
this.filter = KnativeHttpSupport.createFilter(serviceDefinition);
}

@Override
protected void doStart() throws Exception {
this.transport.getDispatcher(key).bind(this);
this.dispatcher.bind(this);

super.doStart();
}

@Override
protected void doStop() throws Exception {
this.transport.getDispatcher(key).unbind(this);
this.dispatcher.unbind(this);

super.doStop();
}
Expand Down
Loading

0 comments on commit fffb9c1

Please sign in to comment.