This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
commit 00888b7d6af894c5f2684b002062cc13b8041923 Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Wed May 27 17:53:49 2020 +0200 Upgrade to Camel 3.3.0 and camel-quarkus 1.0.0.CR1 #338 --- .github/workflows/pr-build.yml | 1 + .../camel/k/loader/java/RoutesLoaderTest.java | 2 +- .../apache/camel/k/loader/js/RoutesLoaderTest.java | 2 +- .../org/apache/camel/k/loader/kotlin/LoaderTest.kt | 16 +- camel-k-loader-yaml/camel-k-loader-yaml/pom.xml | 1 + .../camel/k/health/HealthContextCustomizer.java | 13 +- .../apache/camel/k/main/ApplicationRuntime.java | 17 +- .../quarkus/deployment/DeploymentProcessor.java | 4 +- .../k/core/quarkus/RuntimeListenerAdapter.java | 20 +- .../knative/deployment/DeploymentProcessor.java | 35 +- camel-k-quarkus/camel-k-quarkus-knative/it/pom.xml | 155 ++++++++ .../k/quarkus/knative/deployment/Application.java | 71 ++++ .../it/src/main/resources/application.properties | 36 ++ .../it/src/main/resources/env.json | 13 + .../k/quarkus/knative/deployment/ExtensionIT.java | 16 +- .../quarkus/knative/deployment/ExtensionTest.java | 79 ++++ camel-k-quarkus/camel-k-quarkus-knative/pom.xml | 1 + .../camel-k-quarkus-knative/runtime/pom.xml | 1 + .../camel/k/quarkus/knative/KnativeRecorder.java | 14 +- .../quarkus/deployment/DeploymentProcessor.java | 2 +- .../quarkus/deployment/DeploymentProcessor.java | 2 +- camel-k-runtime-bom/pom.xml | 2 +- camel-k-runtime-http/pom.xml | 5 +- .../java/org/apache/camel/k/http/PlatformHttp.java | 75 ---- .../apache/camel/k/http/PlatformHttpServer.java | 282 -------------- .../k/http/PlatformHttpServiceConfiguration.java | 209 ----------- .../http/PlatformHttpServiceContextCustomizer.java | 46 +-- .../camel/k/http/PlatformHttpServiceEndpoint.java | 123 ------- .../k/http/engine/RuntimePlatformHttpConsumer.java | 408 --------------------- .../apache/camel/k/http/support/CorsHandler.java | 136 ------- .../k/http/PlatformHttpServiceCustomizerTest.java | 18 +- camel-knative/camel-knative-api/pom.xml | 14 +- camel-knative/camel-knative-http/pom.xml | 17 + .../knative/http/KnativeHttpConsumer.java | 15 +- .../knative/http/KnativeHttpProducer.java | 10 +- .../knative/http/KnativeHttpTransport.java | 20 +- camel-knative/camel-knative/pom.xml | 13 + .../apache/camel/component/knative/knative.json | 21 +- .../camel/component/knative/KnativeComponent.java | 6 +- .../camel/component/knative/KnativeConstants.java | 14 +- pom.xml | 30 +- 41 files changed, 575 insertions(+), 1390 deletions(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 31262d8..1c2417f 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -62,6 +62,7 @@ jobs: native-image-project: - :camel-k-quarkus-core-it - :camel-k-quarkus-cron-it + - :camel-k-quarkus-knative-it - :camel-k-quarkus-loader-xml-it - :camel-k-quarkus-loader-yaml-it - :camel-k-runtime-example-quarkus-xml diff --git a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java b/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java index 2125f92..a576933 100644 --- a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java +++ b/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/RoutesLoaderTest.java @@ -126,7 +126,7 @@ public class RoutesLoaderTest { List<RouteDefinition> routes = builder.getRouteCollection().getRoutes(); assertThat(routes).hasSize(1); - assertThat(routes.get(0).getInput().getEndpointUri()).isEqualTo("timer:tick"); + assertThat(routes.get(0).getInput().getEndpointUri()).matches("timer:/*tick"); assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class); } diff --git a/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/RoutesLoaderTest.java b/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/RoutesLoaderTest.java index fba429b..846daad 100644 --- a/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/RoutesLoaderTest.java +++ b/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/RoutesLoaderTest.java @@ -56,7 +56,7 @@ public class RoutesLoaderTest { List<RouteDefinition> routes = builder.getRouteCollection().getRoutes(); assertThat(routes).hasSize(1); - assertThat(routes.get(0).getInput().getEndpointUri()).isEqualTo("timer:tick"); + assertThat(routes.get(0).getInput().getEndpointUri()).matches("timer:/*tick"); assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class); } diff --git a/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt b/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt index b4b84ea..d6840fa 100644 --- a/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt +++ b/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt @@ -33,15 +33,15 @@ class LoaderTest { @Test fun `load routes`() { - var runtime = TestRuntime() - var source = Sources.fromURI("classpath:routes.kts") + val runtime = TestRuntime() + val source = Sources.fromURI("classpath:routes.kts") val loader = RoutesConfigurer.load(runtime, source) assertThat(loader).isInstanceOf(KotlinSourceLoader::class.java) assertThat(runtime.builders).hasSize(1) assertThat(runtime.builders[0]).isInstanceOf(RouteBuilder::class.java) - var builder = runtime.builders[0] as RouteBuilder + val builder = runtime.builders[0] as RouteBuilder builder.context = runtime.camelContext builder.configure() @@ -54,23 +54,23 @@ class LoaderTest { @Test fun `load routes with endpoint dsl`() { - var runtime = TestRuntime() - var source = Sources.fromURI("classpath:routes-with-endpoint-dsl.kts") + val runtime = TestRuntime() + val source = Sources.fromURI("classpath:routes-with-endpoint-dsl.kts") val loader = RoutesConfigurer.load(runtime, source) assertThat(loader).isInstanceOf(KotlinSourceLoader::class.java) assertThat(runtime.builders).hasSize(1) assertThat(runtime.builders[0]).isInstanceOf(RouteBuilder::class.java) - var builder = runtime.builders[0] as RouteBuilder + val builder = runtime.builders[0] as RouteBuilder builder.context = runtime.camelContext builder.configure() val routes = builder.routeCollection.routes assertThat(routes).hasSize(1) - assertThat(routes[0].input.endpointUri).isEqualTo("timer:tick?period=1s") + assertThat(routes[0].input.endpointUri).isEqualTo("timer://tick?period=1s") assertThat(routes[0].outputs[0]).isInstanceOfSatisfying(ToDefinition::class.java) { - assertThat(it.endpointUri).isEqualTo("log:info") + assertThat(it.endpointUri).isEqualTo("log://info") } } diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml b/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml index 199a2d7..f1ef7b6 100644 --- a/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml +++ b/camel-k-loader-yaml/camel-k-loader-yaml/pom.xml @@ -149,6 +149,7 @@ <blacklistedDefinitions> <blacklistedDefinition>org.apache.camel.model.Resilience4jConfigurationDefinition</blacklistedDefinition> <blacklistedDefinition>org.apache.camel.model.HystrixConfigurationDefinition</blacklistedDefinition> + <blacklistedDefinition>org.apache.camel.model.FaultToleranceConfigurationDefinition</blacklistedDefinition> <blacklistedDefinition>org.apache.camel.model.OnFallbackDefinition</blacklistedDefinition> <blacklistedDefinition>org.apache.camel.model.InOnlyDefinition</blacklistedDefinition> <blacklistedDefinition>org.apache.camel.model.InOutDefinition</blacklistedDefinition> diff --git a/camel-k-main/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthContextCustomizer.java b/camel-k-main/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthContextCustomizer.java index 3b88f97..b143c90 100644 --- a/camel-k-main/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthContextCustomizer.java +++ b/camel-k-main/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthContextCustomizer.java @@ -26,6 +26,7 @@ import io.vertx.core.json.JsonObject; import io.vertx.ext.web.Route; import org.apache.camel.CamelContext; import org.apache.camel.Ordered; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpRouter; import org.apache.camel.health.HealthCheck; import org.apache.camel.health.HealthCheckFilter; import org.apache.camel.health.HealthCheckHelper; @@ -35,7 +36,6 @@ 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.annotation.Customizer; -import org.apache.camel.k.http.PlatformHttp; @Customizer("health") public class HealthContextCustomizer implements ContextCustomizer { @@ -111,16 +111,17 @@ public class HealthContextCustomizer implements ContextCustomizer { // add health route addRoute( camelContext, - PlatformHttp.lookup(camelContext) + VertxPlatformHttpRouter.lookup(camelContext) ); } - private Route addRoute(CamelContext camelContext, PlatformHttp platformHttp) { - Route route = platformHttp.router().route(HttpMethod.GET, path); + private Route addRoute(CamelContext camelContext, VertxPlatformHttpRouter router) { + Route route = router.route(HttpMethod.GET, path); - // add global handlers first i.e. body handler - platformHttp.handlers().forEach(route::handler); + // add body handler + route.handler(router.bodyHandler()); + // add health endpoint handler route.handler(routingContext -> { int code = 200; diff --git a/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java b/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java index b3f3578..ab58fb9 100644 --- a/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java +++ b/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java @@ -56,6 +56,7 @@ public final class ApplicationRuntime implements Runtime { this.main = new MainAdapter(); this.main.configure().setXmlRoutes("false"); this.main.configure().setXmlRests("false"); + this.main.setDefaultPropertyPlaceholderLocation("false"); this.main.setRoutesCollector(new NoRoutesCollector()); this.main.addMainListener(new MainListenerAdapter()); } @@ -76,12 +77,12 @@ public final class ApplicationRuntime implements Runtime { @Override public void addRoutes(RoutesBuilder builder) { - this.main.addRoutesBuilder(builder); + this.main.configure().addRoutesBuilder(builder); } @Override public void addConfiguration(Object configuration) { - this.main.addConfiguration(configuration); + this.main.configure().addConfiguration(configuration); } @Override @@ -130,17 +131,25 @@ public final class ApplicationRuntime implements Runtime { private final class MainListenerAdapter implements org.apache.camel.main.MainListener { @Override - public void beforeConfigure(BaseMainSupport main) { + public void beforeInitialize(BaseMainSupport main) { invokeListeners(Phase.ConfigureProperties); + } + + @Override + public void beforeConfigure(BaseMainSupport main) { invokeListeners(Phase.ConfigureRoutes); } @Override - public void configure(CamelContext context) { + public void afterConfigure(BaseMainSupport main) { invokeListeners(Phase.ConfigureContext); } @Override + public void configure(CamelContext context) { + } + + @Override public void beforeStart(BaseMainSupport main) { invokeListeners(Phase.Starting); } diff --git a/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentProcessor.java b/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentProcessor.java index 167daca..63f9f6f 100644 --- a/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentProcessor.java +++ b/camel-k-quarkus/camel-k-quarkus-core/deployment/src/main/java/org/apache/camel/k/core/quarkus/deployment/DeploymentProcessor.java @@ -30,8 +30,8 @@ import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import org.apache.camel.k.Constants; import org.apache.camel.k.Runtime; import org.apache.camel.k.core.quarkus.RuntimeRecorder; -import org.apache.camel.quarkus.core.deployment.CamelMainListenerBuildItem; -import org.apache.camel.quarkus.core.deployment.CamelServicePatternBuildItem; +import org.apache.camel.quarkus.core.deployment.spi.CamelMainListenerBuildItem; +import org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem; import org.apache.camel.spi.HasId; import org.apache.camel.spi.StreamCachingStrategy; import org.jboss.jandex.IndexView; diff --git a/camel-k-quarkus/camel-k-quarkus-core/runtime/src/main/java/org/apache/camel/k/core/quarkus/RuntimeListenerAdapter.java b/camel-k-quarkus/camel-k-quarkus-core/runtime/src/main/java/org/apache/camel/k/core/quarkus/RuntimeListenerAdapter.java index 72a5116..20445f1 100644 --- a/camel-k-quarkus/camel-k-quarkus-core/runtime/src/main/java/org/apache/camel/k/core/quarkus/RuntimeListenerAdapter.java +++ b/camel-k-quarkus/camel-k-quarkus-core/runtime/src/main/java/org/apache/camel/k/core/quarkus/RuntimeListenerAdapter.java @@ -49,14 +49,22 @@ public class RuntimeListenerAdapter implements MainListener { } @Override - public void beforeConfigure(BaseMainSupport main) { + public void beforeInitialize(BaseMainSupport main) { invokeListeners(listeners, on(main), Runtime.Phase.ConfigureProperties); + } + + @Override + public void beforeConfigure(BaseMainSupport main) { invokeListeners(listeners, on(main), Runtime.Phase.ConfigureRoutes); } @Override + public void afterConfigure(BaseMainSupport main) { + invokeListeners(listeners, on(main), Runtime.Phase.ConfigureContext); + } + + @Override public void configure(CamelContext context) { - invokeListeners(listeners, on(context), Runtime.Phase.ConfigureContext); } @Override @@ -118,22 +126,22 @@ public class RuntimeListenerAdapter implements MainListener { @Override public void addRoutes(RoutesBuilder builder) { - main.addRoutesBuilder(builder); + main.configure().addRoutesBuilder(builder); } @Override public void addConfiguration(Object configuration) { - main.addConfiguration(configuration); + main.configure().addConfiguration(configuration); } @Override public void setInitialProperties(Properties properties) { - main.getCamelContext().getPropertiesComponent().setInitialProperties(properties); + main.setInitialProperties(properties); } @Override public void setProperties(Properties properties) { - main.getCamelContext().getPropertiesComponent().setOverrideProperties(properties); + main.setOverrideProperties(properties); } @Override diff --git a/camel-k-quarkus/camel-k-quarkus-knative/deployment/src/main/java/org/apache/camel/k/quarkus/knative/deployment/DeploymentProcessor.java b/camel-k-quarkus/camel-k-quarkus-knative/deployment/src/main/java/org/apache/camel/k/quarkus/knative/deployment/DeploymentProcessor.java index 159f946..6237a05 100644 --- a/camel-k-quarkus/camel-k-quarkus-knative/deployment/src/main/java/org/apache/camel/k/quarkus/knative/deployment/DeploymentProcessor.java +++ b/camel-k-quarkus/camel-k-quarkus-knative/deployment/src/main/java/org/apache/camel/k/quarkus/knative/deployment/DeploymentProcessor.java @@ -16,7 +16,8 @@ */ package org.apache.camel.k.quarkus.knative.deployment; -import io.quarkus.deployment.annotations.BuildProducer; +import java.util.List; + import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; @@ -24,19 +25,27 @@ import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.vertx.core.deployment.CoreVertxBuildItem; import io.quarkus.vertx.http.deployment.BodyHandlerBuildItem; import io.quarkus.vertx.http.deployment.VertxWebRouterBuildItem; +import org.apache.camel.component.knative.KnativeComponent; +import org.apache.camel.component.knative.KnativeConstants; import org.apache.camel.component.knative.spi.KnativeEnvironment; import org.apache.camel.k.quarkus.knative.KnativeRecorder; -import org.apache.camel.quarkus.core.deployment.CamelRuntimeBeanBuildItem; -import org.apache.camel.quarkus.core.deployment.CamelServiceFilter; -import org.apache.camel.quarkus.core.deployment.CamelServiceFilterBuildItem; +import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBeanBuildItem; +import org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilter; +import org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilterBuildItem; public class DeploymentProcessor { @BuildStep - void servicesFilters(BuildProducer<CamelServiceFilterBuildItem> serviceFilter) { - serviceFilter.produce( - new CamelServiceFilterBuildItem(CamelServiceFilter.forComponent("knative")) + List<ReflectiveClassBuildItem> reflectiveClasses() { + return List.of( + new ReflectiveClassBuildItem(true, false, KnativeEnvironment.class), + new ReflectiveClassBuildItem(true, false, KnativeEnvironment.KnativeServiceDefinition.class) ); - serviceFilter.produce( + } + + @BuildStep + List<CamelServiceFilterBuildItem> servicesFilters() { + return List.of( + new CamelServiceFilterBuildItem(CamelServiceFilter.forComponent(KnativeConstants.SCHEME)), new CamelServiceFilterBuildItem(CamelServiceFilter.forPathEndingWith(CamelServiceFilter.CAMEL_SERVICE_BASE_PATH + "/knative/transport/http")) ); } @@ -50,18 +59,12 @@ public class DeploymentProcessor { BodyHandlerBuildItem bodyHandlerBuildItem) { return new CamelRuntimeBeanBuildItem( - "knative", - "org.apache.camel.component.knative.KnativeComponent", + KnativeConstants.SCHEME, + KnativeComponent.class.getName(), recorder.createKnativeComponent( vertx.getVertx(), router.getRouter(), bodyHandlerBuildItem.getHandler()) ); } - - @BuildStep - void registerReflectiveClasses(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) { - reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, KnativeEnvironment.class)); - reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, KnativeEnvironment.KnativeServiceDefinition.class)); - } } diff --git a/camel-k-quarkus/camel-k-quarkus-knative/it/pom.xml b/camel-k-quarkus/camel-k-quarkus-knative/it/pom.xml new file mode 100644 index 0000000..b90339c --- /dev/null +++ b/camel-k-quarkus/camel-k-quarkus-knative/it/pom.xml @@ -0,0 +1,155 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<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-quarkus-knative-parent</artifactId> + <version>1.3.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>camel-k-quarkus-knative-it</artifactId> + + <dependencies> + <dependency> + <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-quarkus-knative</artifactId> + </dependency> + + <!-- quarkus dependencies --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy-jsonb</artifactId> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>${build-helper-maven-plugin.version}</version> + <executions> + <execution> + <id>reserve-network-port</id> + <goals> + <goal>reserve-network-port</goal> + </goals> + <phase>process-resources</phase> + <configuration> + <portNames> + <portName>test.http.port.jvm</portName> + <portName>test.http.port.native</portName> + </portNames> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-maven-plugin</artifactId> + <version>${quarkus.version}</version> + <executions> + <execution> + <goals> + <goal>build</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <systemProperties> + <quarkus.http.test-port>${test.http.port.jvm}</quarkus.http.test-port> + <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> + </systemProperties> + <environmentVariables> + <CAMEL_KNATIVE_CONFIGURATION>file:${project.basedir}/src/main/resources/env.json</CAMEL_KNATIVE_CONFIGURATION> + </environmentVariables> + </configuration> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemProperties> + <quarkus.http.test-port>${test.http.port.native}</quarkus.http.test-port> + <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> + </systemProperties> + <environmentVariables> + <CAMEL_KNATIVE_CONFIGURATION>file:${project.basedir}/src/main/resources/env.json</CAMEL_KNATIVE_CONFIGURATION> + </environmentVariables> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + + +</project> diff --git a/camel-k-quarkus/camel-k-quarkus-knative/it/src/main/java/org/apache/camel/k/quarkus/knative/deployment/Application.java b/camel-k-quarkus/camel-k-quarkus-knative/it/src/main/java/org/apache/camel/k/quarkus/knative/deployment/Application.java new file mode 100644 index 0000000..43f74bb --- /dev/null +++ b/camel-k-quarkus/camel-k-quarkus-knative/it/src/main/java/org/apache/camel/k/quarkus/knative/deployment/Application.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.k.quarkus.knative.deployment; + +import java.util.Map; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.json.Json; +import javax.json.JsonObject; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.knative.KnativeEndpoint; +import org.apache.camel.component.knative.spi.Knative; + + +@Path("/test") +@ApplicationScoped +public class Application { + @Inject + CamelContext context; + + @SuppressWarnings("unchecked") + @GET + @Path("/inspect") + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.APPLICATION_JSON) + public JsonObject inspect() { + var endpoint = context.getEndpoint("knative:endpoint/from", KnativeEndpoint.class); + var envMeta = endpoint.getConfiguration().getEnvironment().lookup(Knative.Type.endpoint, "from") + .filter(entry -> Knative.EndpointKind.source.name().equals(entry.getMetadata().get(Knative.CAMEL_ENDPOINT_KIND))) + .findFirst() + .map(def -> Json.createObjectBuilder((Map)def.getMetadata())) + .orElseThrow(IllegalArgumentException::new); + + return Json.createObjectBuilder() + .add("env-meta", envMeta) + .build(); + } + + @javax.enterprise.inject.Produces + public RouteBuilder routes() { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("knative:endpoint/from") + .transform().body(String.class, b -> b.toUpperCase()); + } + }; + } +} diff --git a/camel-k-quarkus/camel-k-quarkus-knative/it/src/main/resources/application.properties b/camel-k-quarkus/camel-k-quarkus-knative/it/src/main/resources/application.properties new file mode 100644 index 0000000..b4cc6d4 --- /dev/null +++ b/camel-k-quarkus/camel-k-quarkus-knative/it/src/main/resources/application.properties @@ -0,0 +1,36 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- +# +# Quarkus +# +quarkus.log.file.enable = false +quarkus.log.console.enable = false +quarkus.banner.enabled = false + +# +# Quarkus :: Camel +# +quarkus.camel.main.routes-discovery.enabled = false + +# +# Camel +# +camel.context.name = camel-k-quarkus-ctx + +# +# Integration +# diff --git a/camel-k-quarkus/camel-k-quarkus-knative/it/src/main/resources/env.json b/camel-k-quarkus/camel-k-quarkus-knative/it/src/main/resources/env.json new file mode 100644 index 0000000..1ba0ae6 --- /dev/null +++ b/camel-k-quarkus/camel-k-quarkus-knative/it/src/main/resources/env.json @@ -0,0 +1,13 @@ +{ + "services": [ + { + "type": "endpoint", + "name": "from", + "metadata": { + "service.path": "/knative", + "camel.endpoint.kind": "source", + "knative.event.type": "camel.k.evt" + } + } + ] +} \ No newline at end of file diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpEngine.java b/camel-k-quarkus/camel-k-quarkus-knative/it/src/test/java/org/apache/camel/k/quarkus/knative/deployment/ExtensionIT.java similarity index 60% copy from camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpEngine.java copy to camel-k-quarkus/camel-k-quarkus-knative/it/src/test/java/org/apache/camel/k/quarkus/knative/deployment/ExtensionIT.java index 05f8111..c8ad581 100644 --- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpEngine.java +++ b/camel-k-quarkus/camel-k-quarkus-knative/it/src/test/java/org/apache/camel/k/quarkus/knative/deployment/ExtensionIT.java @@ -14,16 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.k.http.engine; +package org.apache.camel.k.quarkus.knative.deployment; -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.component.platform.http.PlatformHttpEndpoint; -import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; +import io.quarkus.test.junit.NativeImageTest; -public class RuntimePlatformHttpEngine implements PlatformHttpEngine { - @Override - public Consumer createConsumer(PlatformHttpEndpoint platformHttpEndpoint, Processor processor) { - return new RuntimePlatformHttpConsumer(platformHttpEndpoint, processor); - } -} +@NativeImageTest +public class ExtensionIT extends ExtensionTest { +} \ No newline at end of file diff --git a/camel-k-quarkus/camel-k-quarkus-knative/it/src/test/java/org/apache/camel/k/quarkus/knative/deployment/ExtensionTest.java b/camel-k-quarkus/camel-k-quarkus-knative/it/src/test/java/org/apache/camel/k/quarkus/knative/deployment/ExtensionTest.java new file mode 100644 index 0000000..9dcb4c2 --- /dev/null +++ b/camel-k-quarkus/camel-k-quarkus-knative/it/src/test/java/org/apache/camel/k/quarkus/knative/deployment/ExtensionTest.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.k.quarkus.knative.deployment; + +import java.io.IOException; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +import javax.ws.rs.core.MediaType; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.path.json.JsonPath; +import org.apache.camel.Exchange; +import org.apache.camel.component.knative.spi.CloudEvent; +import org.apache.camel.component.knative.spi.CloudEvents; +import org.apache.camel.component.knative.spi.Knative; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; + +@QuarkusTest +public class ExtensionTest { + @Test + public void inspect() throws IOException { + JsonPath p = RestAssured.given() + .contentType(MediaType.TEXT_PLAIN) + .accept(MediaType.APPLICATION_JSON) + .get("/test/inspect") + .then() + .statusCode(200) + .extract() + .body() + .jsonPath(); + + assertThat(p.getMap("env-meta", String.class, String.class)) + .containsEntry(Knative.KNATIVE_EVENT_TYPE, "camel.k.evt") + .containsEntry(Knative.SERVICE_META_PATH, "/knative") + .containsEntry("camel.endpoint.kind", "source"); + } + + @Test + public void invoke() { + final CloudEvents ce = CloudEvents.v1_0; + final String payload = "test"; + + String result = given() + .body(payload) + .header(Exchange.CONTENT_TYPE, "text/plain") + .header(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_VERSION).http(), ce.v1_0.version()) + .header(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_TYPE).http(), "org.apache.camel.event") + .header(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_ID).http(), "myEventID") + .header(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_TIME).http(), DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now())) + .header(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE).http(), "/somewhere") + .when() + .post("/knative") + .then() + .statusCode(200) + .extract() + .asString(); + + assertThat(result).isEqualTo(payload.toUpperCase()); + } +} diff --git a/camel-k-quarkus/camel-k-quarkus-knative/pom.xml b/camel-k-quarkus/camel-k-quarkus-knative/pom.xml index a6b81b3..8f64b59 100644 --- a/camel-k-quarkus/camel-k-quarkus-knative/pom.xml +++ b/camel-k-quarkus/camel-k-quarkus-knative/pom.xml @@ -31,6 +31,7 @@ <modules> <module>runtime</module> <module>deployment</module> + <module>it</module> </modules> </project> diff --git a/camel-k-quarkus/camel-k-quarkus-knative/runtime/pom.xml b/camel-k-quarkus/camel-k-quarkus-knative/runtime/pom.xml index 6e2da3b..56e1fef 100644 --- a/camel-k-quarkus/camel-k-quarkus-knative/runtime/pom.xml +++ b/camel-k-quarkus/camel-k-quarkus-knative/runtime/pom.xml @@ -59,6 +59,7 @@ <dependency> <groupId>org.graalvm.nativeimage</groupId> <artifactId>svm</artifactId> + <scope>provided</scope> </dependency> </dependencies> diff --git a/camel-k-quarkus/camel-k-quarkus-knative/runtime/src/main/java/org/apache/camel/k/quarkus/knative/KnativeRecorder.java b/camel-k-quarkus/camel-k-quarkus-knative/runtime/src/main/java/org/apache/camel/k/quarkus/knative/KnativeRecorder.java index 2ce29c6..edabff7 100644 --- a/camel-k-quarkus/camel-k-quarkus-knative/runtime/src/main/java/org/apache/camel/k/quarkus/knative/KnativeRecorder.java +++ b/camel-k-quarkus/camel-k-quarkus-knative/runtime/src/main/java/org/apache/camel/k/quarkus/knative/KnativeRecorder.java @@ -16,7 +16,6 @@ */ package org.apache.camel.k.quarkus.knative; -import java.util.Collections; import java.util.function.Supplier; import io.quarkus.runtime.RuntimeValue; @@ -27,7 +26,7 @@ import io.vertx.ext.web.Router; import io.vertx.ext.web.RoutingContext; import org.apache.camel.component.knative.KnativeComponent; import org.apache.camel.component.knative.http.KnativeHttpTransport; -import org.apache.camel.k.http.PlatformHttp; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpRouter; @Recorder public class KnativeRecorder { @@ -37,11 +36,12 @@ public class KnativeRecorder { Handler<RoutingContext> bodyHandler) { KnativeHttpTransport transport = new KnativeHttpTransport(); - transport.setPlatformHttp(new PlatformHttp( - vertx.get(), - router.getValue(), - Collections.singletonList(bodyHandler) - )); + transport.setRouter(new VertxPlatformHttpRouter(vertx.get(), router.getValue()) { + @Override + public Handler<RoutingContext> bodyHandler() { + return bodyHandler; + } + }); KnativeComponent component = new KnativeComponent(); component.setTransport(transport); diff --git a/camel-k-quarkus/camel-k-quarkus-loader-xml/deployment/src/main/java/org/apache/camel/k/loader/xml/quarkus/deployment/DeploymentProcessor.java b/camel-k-quarkus/camel-k-quarkus-loader-xml/deployment/src/main/java/org/apache/camel/k/loader/xml/quarkus/deployment/DeploymentProcessor.java index 6d5a339..26b0389 100644 --- a/camel-k-quarkus/camel-k-quarkus-loader-xml/deployment/src/main/java/org/apache/camel/k/loader/xml/quarkus/deployment/DeploymentProcessor.java +++ b/camel-k-quarkus/camel-k-quarkus-loader-xml/deployment/src/main/java/org/apache/camel/k/loader/xml/quarkus/deployment/DeploymentProcessor.java @@ -20,7 +20,7 @@ import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; import org.apache.camel.k.loader.xml.quarkus.XmlLoaderRecorder; -import org.apache.camel.quarkus.core.deployment.CamelRoutesLoaderBuildItems; +import org.apache.camel.quarkus.core.deployment.spi.CamelRoutesLoaderBuildItems; public class DeploymentProcessor { @BuildStep diff --git a/camel-k-quarkus/camel-k-quarkus-loader-yaml/deployment/src/main/java/org/apache/camel/k/loader/yaml/quarkus/deployment/DeploymentProcessor.java b/camel-k-quarkus/camel-k-quarkus-loader-yaml/deployment/src/main/java/org/apache/camel/k/loader/yaml/quarkus/deployment/DeploymentProcessor.java index c49c1c4..0159a0a 100644 --- a/camel-k-quarkus/camel-k-quarkus-loader-yaml/deployment/src/main/java/org/apache/camel/k/loader/yaml/quarkus/deployment/DeploymentProcessor.java +++ b/camel-k-quarkus/camel-k-quarkus-loader-yaml/deployment/src/main/java/org/apache/camel/k/loader/yaml/quarkus/deployment/DeploymentProcessor.java @@ -28,7 +28,7 @@ import org.apache.camel.k.loader.yaml.spi.StepParser; import org.apache.camel.model.DataFormatDefinition; import org.apache.camel.model.ProcessorDefinition; import org.apache.camel.model.language.ExpressionDefinition; -import org.apache.camel.quarkus.core.deployment.CamelServicePatternBuildItem; +import org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; diff --git a/camel-k-runtime-bom/pom.xml b/camel-k-runtime-bom/pom.xml index 8051ed4..b03e63e 100644 --- a/camel-k-runtime-bom/pom.xml +++ b/camel-k-runtime-bom/pom.xml @@ -426,7 +426,7 @@ <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-buildtools</artifactId> - <version>3.1.0</version> + <version>3.3.0</version> </dependency> </dependencies> </plugin> diff --git a/camel-k-runtime-http/pom.xml b/camel-k-runtime-http/pom.xml index 59f86d1..bffab94 100644 --- a/camel-k-runtime-http/pom.xml +++ b/camel-k-runtime-http/pom.xml @@ -41,12 +41,9 @@ <artifactId>camel-core-engine</artifactId> </dependency> - <!-- - Replace this with camel-platform-http-vertx when migrating to camel 3.3 - --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-platform-http</artifactId> + <artifactId>camel-platform-http-vertx</artifactId> </dependency> <dependency> diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttp.java b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttp.java deleted file mode 100644 index 52ab74e..0000000 --- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttp.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.http; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import io.vertx.core.Handler; -import io.vertx.core.Vertx; -import io.vertx.ext.web.Router; -import io.vertx.ext.web.RoutingContext; -import org.apache.camel.CamelContext; -import org.apache.camel.component.platform.http.PlatformHttpConstants; -import org.apache.camel.support.CamelContextHelper; - -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; - private final List<Handler<RoutingContext>> handlers; - - public PlatformHttp(Vertx vertx, Router router) { - this.vertx = vertx; - this.router = router; - this.handlers = Collections.emptyList(); - } - - public PlatformHttp(Vertx vertx, Router router, List<Handler<RoutingContext>> handlers) { - this.vertx = vertx; - this.router = router; - this.handlers = Collections.unmodifiableList(new ArrayList<>(handlers)); - } - - public Vertx vertx() { - return vertx; - } - - public Router router() { - return router; - } - - public List<Handler<RoutingContext>> handlers() { - return handlers; - } - - // ********************** - // - // Helpers - // - // ********************** - - public static PlatformHttp lookup(CamelContext camelContext) { - return CamelContextHelper.mandatoryLookup( - camelContext, - PlatformHttp.PLATFORM_HTTP_ROUTER_NAME, - PlatformHttp.class - ); - } -} diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServer.java b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServer.java deleted file mode 100644 index 3710415..0000000 --- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServer.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.http; - -import java.io.IOException; -import java.security.GeneralSecurityException; -import java.security.KeyStore; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; - -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.TrustManagerFactory; - -import io.vertx.core.Handler; -import io.vertx.core.Vertx; -import io.vertx.core.http.HttpServer; -import io.vertx.core.http.HttpServerOptions; -import io.vertx.core.net.KeyCertOptions; -import io.vertx.core.net.TrustOptions; -import io.vertx.ext.web.Router; -import io.vertx.ext.web.RoutingContext; -import io.vertx.ext.web.handler.BodyHandler; -import org.apache.camel.CamelContext; -import org.apache.camel.component.platform.http.PlatformHttpConstants; -import org.apache.camel.support.jsse.KeyManagersParameters; -import org.apache.camel.support.jsse.SSLContextParameters; -import org.apache.camel.support.jsse.TrustManagersParameters; -import org.apache.camel.support.service.ServiceSupport; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class PlatformHttpServer extends ServiceSupport { - private static final Logger LOGGER = LoggerFactory.getLogger(PlatformHttpServer.class); - - private final CamelContext context; - private final PlatformHttpServiceConfiguration configuration; - private final Vertx vertx; - private final Router router; - private final ExecutorService executor; - - private HttpServer server; - - public PlatformHttpServer(CamelContext context, PlatformHttpServiceConfiguration configuration, Vertx vertx, ExecutorService executor) { - this.context = context; - this.configuration = configuration; - this.vertx = vertx; - this.router = Router.router(vertx); - this.executor = executor; - } - - @Override - protected void doInit() throws Exception { - final Router subRouter = Router.router(vertx); - - if (configuration.getCors().isEnabled()) { - subRouter.route().handler(new org.apache.camel.k.http.support.CorsHandler(configuration)); - } - - router.mountSubRouter(configuration.getPath(), subRouter); - - context.getRegistry().bind( - PlatformHttp.PLATFORM_HTTP_ROUTER_NAME, - new PlatformHttp(vertx, subRouter, Collections.singletonList(createBodyHandler())) - ); - - SSLContextParameters sslParameters = configuration.getSslContextParameters(); - if (sslParameters == null && configuration.isUseGlobalSslContextParameters()) { - sslParameters = context.getSSLContextParameters(); - } - - HttpServerOptions options = new HttpServerOptions(); - if (sslParameters != null) { - options.setSsl(true); - options.setKeyCertOptions(createKeyCertOptions(sslParameters)); - options.setTrustOptions(createTrustOptions(sslParameters)); - } - - server = vertx.createHttpServer(options); - } - - @Override - protected void doStart() throws Exception { - CompletableFuture.runAsync( - () -> { - CountDownLatch latch = new CountDownLatch(1); - server.requestHandler(router).listen(configuration.getBindPort(), configuration.getBindHost(), result -> { - try { - if (result.failed()) { - LOGGER.warn("Failed to start Vert.x HttpServer on {}:{}, reason: {}", - configuration.getBindHost(), - configuration.getBindPort(), - result.cause().getMessage() - ); - - throw new RuntimeException(result.cause()); - } - - LOGGER.info("Vert.x HttpServer started on {}:{}", configuration.getBindHost(), configuration.getBindPort()); - } finally { - latch.countDown(); - } - }); - - try { - latch.await(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - }, - executor - ).toCompletableFuture().join(); - } - - @Override - protected void doStop() throws Exception { - try { - if (server != null) { - CompletableFuture.runAsync( - () -> { - CountDownLatch latch = new CountDownLatch(1); - - // remove the platform-http component - context.removeComponent(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME); - - server.close(result -> { - try { - if (result.failed()) { - LOGGER.warn("Failed to close Vert.x HttpServer reason: {}", - result.cause().getMessage() - ); - - throw new RuntimeException(result.cause()); - } - - LOGGER.info("Vert.x HttpServer stopped"); - } finally { - latch.countDown(); - } - }); - - try { - latch.await(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - }, - executor - ).toCompletableFuture().join(); - } - } finally { - this.server = null; - } - } - - private Handler<RoutingContext> createBodyHandler() { - BodyHandler bodyHandler = BodyHandler.create(); - - if (configuration.getMaxBodySize() != null) { - bodyHandler.setBodyLimit(configuration.getMaxBodySize().longValueExact()); - } - - bodyHandler.setHandleFileUploads(configuration.getBodyHandler().isHandleFileUploads()); - bodyHandler.setUploadsDirectory(configuration.getBodyHandler().getUploadsDirectory()); - bodyHandler.setDeleteUploadedFilesOnEnd(configuration.getBodyHandler().isDeleteUploadedFilesOnEnd()); - bodyHandler.setMergeFormAttributes(configuration.getBodyHandler().isMergeFormAttributes()); - bodyHandler.setPreallocateBodyBuffer(configuration.getBodyHandler().isPreallocateBodyBuffer()); - - return new Handler<RoutingContext>() { - @Override - public void handle(RoutingContext event) { - event.request().resume(); - bodyHandler.handle(event); - } - }; - } - - // ***************************** - // - // SSL - // - // ***************************** - - private KeyCertOptions createKeyCertOptions(SSLContextParameters sslContextParameters) { - return new KeyCertOptions() { - @Override - public KeyManagerFactory getKeyManagerFactory(Vertx vertx) throws Exception { - return createKeyManagerFactory(sslContextParameters); - } - - @Override - public KeyCertOptions clone() { - return this; - } - }; - } - - private KeyManagerFactory createKeyManagerFactory(SSLContextParameters sslContextParameters) throws GeneralSecurityException, IOException { - final KeyManagersParameters keyManagers = sslContextParameters.getKeyManagers(); - if (keyManagers == null) { - return null; - } - - String kmfAlgorithm = context.resolvePropertyPlaceholders(keyManagers.getAlgorithm()); - if (kmfAlgorithm == null) { - kmfAlgorithm = KeyManagerFactory.getDefaultAlgorithm(); - } - - KeyManagerFactory kmf; - if (keyManagers.getProvider() == null) { - kmf = KeyManagerFactory.getInstance(kmfAlgorithm); - } else { - kmf = KeyManagerFactory.getInstance(kmfAlgorithm, context.resolvePropertyPlaceholders(keyManagers.getProvider())); - } - - char[] kmfPassword = null; - if (keyManagers.getKeyPassword() != null) { - kmfPassword = context.resolvePropertyPlaceholders(keyManagers.getKeyPassword()).toCharArray(); - } - - KeyStore ks = keyManagers.getKeyStore() == null ? null : keyManagers.getKeyStore().createKeyStore(); - - kmf.init(ks, kmfPassword); - return kmf; - } - - private TrustOptions createTrustOptions(SSLContextParameters sslContextParameters) { - return new TrustOptions() { - @Override - public TrustOptions clone() { - return this; - } - - @Override - public TrustManagerFactory getTrustManagerFactory(Vertx vertx) throws Exception { - return createTrustManagerFactory(sslContextParameters); - } - }; - } - - private TrustManagerFactory createTrustManagerFactory(SSLContextParameters sslContextParameters) throws GeneralSecurityException, IOException { - final TrustManagersParameters trustManagers = sslContextParameters.getTrustManagers(); - if (trustManagers == null) { - return null; - } - - TrustManagerFactory tmf = null; - - if (trustManagers.getKeyStore() != null) { - String tmfAlgorithm = context.resolvePropertyPlaceholders(trustManagers.getAlgorithm()); - if (tmfAlgorithm == null) { - tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm(); - } - - if (trustManagers.getProvider() == null) { - tmf = TrustManagerFactory.getInstance(tmfAlgorithm); - } else { - tmf = TrustManagerFactory.getInstance(tmfAlgorithm, context.resolvePropertyPlaceholders(trustManagers.getProvider())); - } - - KeyStore ks = trustManagers.getKeyStore() == null ? null : trustManagers.getKeyStore().createKeyStore(); - tmf.init(ks); - } - - return tmf; - } -} diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServiceConfiguration.java b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServiceConfiguration.java deleted file mode 100644 index 9001d2d..0000000 --- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServiceConfiguration.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.http; - -import java.math.BigInteger; -import java.time.Duration; -import java.util.List; - -import org.apache.camel.support.jsse.SSLContextParameters; - -public class PlatformHttpServiceConfiguration { - public static final String DEFAULT_BIND_HOST = "0.0.0.0"; - public static final int DEFAULT_BIND_PORT = 8081; - public static final String DEFAULT_PATH = "/"; - - private String bindHost = DEFAULT_BIND_HOST; - private int bindPort = DEFAULT_BIND_PORT; - private String path = DEFAULT_PATH; - private BigInteger maxBodySize; - - private SSLContextParameters sslContextParameters; - private boolean useGlobalSslContextParameters; - - private CorsConfiguration corsConfiguration = new CorsConfiguration(); - private BodyHandlerConfiguration bodyHandlerConfiguration = new BodyHandlerConfiguration(); - - public String getBindHost() { - return bindHost; - } - - public void setBindHost(String bindHost) { - this.bindHost = bindHost; - } - - public int getBindPort() { - return bindPort; - } - - public void setBindPort(int bindPort) { - this.bindPort = bindPort; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public BigInteger getMaxBodySize() { - return maxBodySize; - } - - public void setMaxBodySize(BigInteger maxBodySize) { - this.maxBodySize = maxBodySize; - } - - public SSLContextParameters getSslContextParameters() { - return sslContextParameters; - } - - public void setSslContextParameters(SSLContextParameters sslContextParameters) { - this.sslContextParameters = sslContextParameters; - } - - public boolean isUseGlobalSslContextParameters() { - return useGlobalSslContextParameters; - } - - public void setUseGlobalSslContextParameters(boolean useGlobalSslContextParameters) { - this.useGlobalSslContextParameters = useGlobalSslContextParameters; - } - - public CorsConfiguration getCors() { - return corsConfiguration; - } - - public void setCors(CorsConfiguration corsConfiguration) { - this.corsConfiguration = corsConfiguration; - } - - public BodyHandlerConfiguration getBodyHandler() { - return bodyHandlerConfiguration; - } - - public void setBodyHandler(BodyHandlerConfiguration bodyHandler) { - this.bodyHandlerConfiguration = bodyHandler; - } - - public static class CorsConfiguration { - private boolean enabled; - private List<String> origins; - private List<String> methods; - private List<String> headers; - private List<String> exposedHeaders; - private Duration accessControlMaxAge; - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public List<String> getOrigins() { - return origins; - } - - public void setOrigins(List<String> origins) { - this.origins = origins; - } - - public List<String> getMethods() { - return methods; - } - - public void setMethods(List<String> methods) { - this.methods = methods; - } - - public List<String> getHeaders() { - return headers; - } - - public List<String> getExposedHeaders() { - return exposedHeaders; - } - - public void setExposedHeaders(List<String> exposedHeaders) { - this.exposedHeaders = exposedHeaders; - } - - public void setHeaders(List<String> headers) { - this.headers = headers; - } - - public Duration getAccessControlMaxAge() { - return accessControlMaxAge; - } - - public void setAccessControlMaxAge(Duration accessControlMaxAge) { - this.accessControlMaxAge = accessControlMaxAge; - } - } - - public static class BodyHandlerConfiguration { - private boolean handleFileUploads = true; - private String uploadsDirectory = "file-uploads"; - private boolean mergeFormAttributes = true; - private boolean deleteUploadedFilesOnEnd; - private boolean preallocateBodyBuffer = true; - - public boolean isHandleFileUploads() { - return handleFileUploads; - } - - public void setHandleFileUploads(boolean handleFileUploads) { - this.handleFileUploads = handleFileUploads; - } - - public String getUploadsDirectory() { - return uploadsDirectory; - } - - public void setUploadsDirectory(String uploadsDirectory) { - this.uploadsDirectory = uploadsDirectory; - } - - public boolean isMergeFormAttributes() { - return mergeFormAttributes; - } - - public void setMergeFormAttributes(boolean mergeFormAttributes) { - this.mergeFormAttributes = mergeFormAttributes; - } - - public boolean isDeleteUploadedFilesOnEnd() { - return deleteUploadedFilesOnEnd; - } - - public void setDeleteUploadedFilesOnEnd(boolean deleteUploadedFilesOnEnd) { - this.deleteUploadedFilesOnEnd = deleteUploadedFilesOnEnd; - } - - public boolean isPreallocateBodyBuffer() { - return preallocateBodyBuffer; - } - - public void setPreallocateBodyBuffer(boolean preallocateBodyBuffer) { - this.preallocateBodyBuffer = preallocateBodyBuffer; - } - } -} diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServiceContextCustomizer.java b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServiceContextCustomizer.java index a74ff0e..d753c0e 100644 --- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServiceContextCustomizer.java +++ b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServiceContextCustomizer.java @@ -16,22 +16,19 @@ */ package org.apache.camel.k.http; -import java.util.Map; - import org.apache.camel.CamelContext; -import org.apache.camel.Endpoint; import org.apache.camel.Ordered; import org.apache.camel.component.platform.http.PlatformHttpComponent; import org.apache.camel.component.platform.http.PlatformHttpConstants; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpEngine; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServer; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServerConfiguration; import org.apache.camel.k.ContextCustomizer; import org.apache.camel.k.annotation.Customizer; -import org.apache.camel.k.http.engine.RuntimePlatformHttpEngine; @Customizer("platform-http") -public class PlatformHttpServiceContextCustomizer extends PlatformHttpServiceConfiguration implements ContextCustomizer { - private PlatformHttpServiceEndpoint endpoint; - +public class PlatformHttpServiceContextCustomizer extends VertxPlatformHttpServerConfiguration implements ContextCustomizer { public PlatformHttpServiceContextCustomizer() { } @@ -42,33 +39,24 @@ public class PlatformHttpServiceContextCustomizer extends PlatformHttpServiceCon @Override public void apply(CamelContext camelContext) { - endpoint = new PlatformHttpServiceEndpoint(camelContext, this); - //endpoint.init(); - try { - camelContext.addService(endpoint); + camelContext.addService(new VertxPlatformHttpServer(this) { + @Override + protected void doInit() throws Exception { + initializeServer(); + } + @Override + protected void doStart() throws Exception { + startServer(); + } + }); } catch (Exception e) { throw new RuntimeException(e); } - camelContext.addComponent(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME, new PlatformHttpComponentWrapper()); - } - - public static final class PlatformHttpComponentWrapper extends PlatformHttpComponent { - public PlatformHttpComponentWrapper() { - setEngine(new RuntimePlatformHttpEngine()); - } - - @Override - protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - // the PlatformHttpComponent set this value but it is not handled which cause the - // context to fail as the property cannot be bound to the enpoint. - // - // TODO: fix upstream - parameters.remove("optionsEnabled"); + PlatformHttpComponent component = new PlatformHttpComponent(camelContext); + component.setEngine(new VertxPlatformHttpEngine()); - // let the original component to create the endpoint - return super.createEndpoint(uri, remaining, parameters); - } + camelContext.getRegistry().bind(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME, component); } } diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServiceEndpoint.java b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServiceEndpoint.java deleted file mode 100644 index 9658753..0000000 --- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/PlatformHttpServiceEndpoint.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.http; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; - -import io.vertx.core.Vertx; -import io.vertx.core.VertxOptions; -import org.apache.camel.CamelContext; -import org.apache.camel.support.CamelContextHelper; -import org.apache.camel.support.service.ServiceSupport; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PlatformHttpServiceEndpoint extends ServiceSupport { - private static final Logger LOGGER = LoggerFactory.getLogger(PlatformHttpServiceEndpoint.class); - - private final CamelContext context; - private final PlatformHttpServiceConfiguration configuration; - - private Vertx vertx; - private boolean localVertx; - private PlatformHttpServer vertxHttpServer; - private ExecutorService executor; - - public PlatformHttpServiceEndpoint(CamelContext context, PlatformHttpServiceConfiguration configuration) { - this.context = context; - this.configuration = configuration; - } - - @Override - protected void doInit() throws Exception { - vertx = CamelContextHelper.findByType(context, Vertx.class); - executor = context.getExecutorServiceManager().newSingleThreadExecutor(this, "platform-http-service"); - - if (vertx != null) { - LOGGER.info("Found Vert.x instance in registry: {}", vertx); - } else { - VertxOptions options = CamelContextHelper.findByType(context, VertxOptions.class); - if (options == null) { - options = new VertxOptions(); - } - - LOGGER.info("Creating new Vert.x instance"); - - vertx = Vertx.vertx(options); - localVertx = true; - } - - vertxHttpServer = new PlatformHttpServer(context, configuration, vertx, executor); - vertxHttpServer.init(); - } - - @Override - protected void doStart() throws Exception { - vertxHttpServer.start(); - } - - @Override - protected void doStop() throws Exception { - if (vertxHttpServer != null) { - vertxHttpServer.stop(); - } - - if (vertx != null && localVertx) { - Future<?> future = executor.submit( - () -> { - CountDownLatch latch = new CountDownLatch(1); - - vertx.close(result -> { - try { - if (result.failed()) { - LOGGER.warn("Failed to close Vert.x reason: {}", - result.cause().getMessage() - ); - - throw new RuntimeException(result.cause()); - } - - LOGGER.info("Vert.x stopped"); - } finally { - latch.countDown(); - } - }); - - try { - latch.await(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - ); - - try { - future.get(); - } finally { - vertx = null; - localVertx = false; - } - } - - if (executor != null) { - context.getExecutorServiceManager().shutdown(executor); - executor = null; - } - } -} diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java deleted file mode 100644 index f325a91..0000000 --- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java +++ /dev/null @@ -1,408 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.http.engine; - -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.regex.Pattern; - -import io.vertx.core.MultiMap; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.http.HttpMethod; -import io.vertx.core.http.HttpServerRequest; -import io.vertx.core.http.HttpServerResponse; -import io.vertx.ext.web.Route; -import io.vertx.ext.web.RoutingContext; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.NoTypeConversionAvailableException; -import org.apache.camel.Processor; -import org.apache.camel.TypeConversionException; -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.PlatformHttp; -import org.apache.camel.spi.HeaderFilterStrategy; -import org.apache.camel.support.DefaultConsumer; -import org.apache.camel.support.DefaultMessage; -import org.apache.camel.support.ExchangeHelper; -import org.apache.camel.support.MessageHelper; -import org.apache.camel.support.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RuntimePlatformHttpConsumer extends DefaultConsumer { - private static final Logger LOG = LoggerFactory.getLogger(RuntimePlatformHttpConsumer.class); - private static final Pattern PATH_PARAMETER_PATTERN = Pattern.compile("\\{([^/}]+)\\}"); - - private Route route; - - public RuntimePlatformHttpConsumer(PlatformHttpEndpoint endpoint, Processor processor) { - super(endpoint, processor); - } - - @Override - public PlatformHttpEndpoint getEndpoint() { - return (PlatformHttpEndpoint) super.getEndpoint(); - } - - @Override - protected void doInit() throws Exception { - super.doStart(); - - final PlatformHttpEndpoint endpoint = getEndpoint(); - 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.router().route(vertxPathParamPath); - - router.handlers().forEach(newRoute::handler); - - final Set<Method> methods = Method.parseList(endpoint.getHttpMethodRestrict()); - if (!methods.equals(Method.getAll())) { - methods.stream().forEach(m -> newRoute.method(HttpMethod.valueOf(m.name()))); - } - if (endpoint.getConsumes() != null) { - newRoute.consumes(endpoint.getConsumes()); - } - if (endpoint.getProduces() != null) { - newRoute.produces(endpoint.getProduces()); - } - - newRoute.handler( - ctx -> { - Exchange exchg = null; - try { - final Exchange exchange = exchg = toExchange(ctx); - createUoW(exchange); - getAsyncProcessor().process( - exchange, - doneSync -> writeResponse(ctx, exchange, getEndpoint().getHeaderFilterStrategy())); - } catch (Exception e) { - ctx.fail(e); - getExceptionHandler().handleException("Failed handling platform-http endpoint " + path, exchg, e); - } finally { - if (exchg != null) { - doneUoW(exchg); - } - } - }); - - this.route = newRoute; - } - - @Override - protected void doStop() throws Exception { - if (route != null) { - route.remove(); - route = null; - } - super.doStop(); - } - - @Override - protected void doSuspend() throws Exception { - if (route != null) { - route.disable(); - } - super.doSuspend(); - } - - @Override - protected void doResume() throws Exception { - if (route != null) { - route.enable(); - } - super.doResume(); - } - - static Object toHttpResponse(HttpServerResponse response, Message message, HeaderFilterStrategy headerFilterStrategy) { - final Exchange exchange = message.getExchange(); - final TypeConverter tc = exchange.getContext().getTypeConverter(); - final int code = determineResponseCode(exchange, message.getBody()); - - response.setStatusCode(code); - - // copy headers from Message to Response - if (headerFilterStrategy != null) { - for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) { - final String key = entry.getKey(); - final Object value = entry.getValue(); - // use an iterator as there can be multiple values. (must not use a delimiter) - final Iterator<?> it = ObjectHelper.createIterator(value, null); - - String firstValue = null; - List<String> values = null; - - while (it.hasNext()) { - final String headerValue = tc.convertTo(String.class, it.next()); - if (headerValue != null - && !headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue, exchange)) { - if (firstValue == null) { - firstValue = headerValue; - } else { - if (values == null) { - values = new ArrayList<>(); - values.add(firstValue); - } - values.add(headerValue); - } - } - } - if (values != null) { - response.putHeader(key, values); - } else if (firstValue != null) { - response.putHeader(key, firstValue); - } - } - } - - Object body = message.getBody(); - final Exception exception = exchange.getException(); - - if (exception != null) { - // we failed due an exception so print it as plain text - final StringWriter sw = new StringWriter(); - final PrintWriter pw = new PrintWriter(sw); - - exception.printStackTrace(pw); - - // the body should then be the stacktrace - body = ByteBuffer.wrap(sw.toString().getBytes(StandardCharsets.UTF_8)); - // force content type to be text/plain as that is what the stacktrace is - message.setHeader(Exchange.CONTENT_TYPE, "text/plain; charset=utf-8"); - - // and mark the exception as failure handled, as we handled it by returning it as the response - ExchangeHelper.setFailureHandled(exchange); - } - - // set the content-length if it can be determined, or chunked encoding - final Integer length = determineContentLength(exchange, body); - if (length != null) { - response.putHeader("Content-Length", String.valueOf(length)); - } else { - response.setChunked(true); - } - - // set the content type in the response. - final String contentType = MessageHelper.getContentType(message); - if (contentType != null) { - // set content-type - response.putHeader("Content-Type", contentType); - } - return body; - } - - static Integer determineContentLength(Exchange camelExchange, Object body) { - if (body instanceof byte[]) { - return ((byte[]) body).length; - } else if (body instanceof ByteBuffer) { - return ((ByteBuffer) body).remaining(); - } - return null; - } - - /* - * Copied from org.apache.camel.http.common.DefaultHttpBinding.determineResponseCode(Exchange, Object) - * If DefaultHttpBinding.determineResponseCode(Exchange, Object) is moved to a module without the servlet-api - * dependency we could eventually consume it from there. - */ - static int determineResponseCode(Exchange camelExchange, Object body) { - boolean failed = camelExchange.isFailed(); - int defaultCode = failed ? 500 : 200; - - Message message = camelExchange.getMessage(); - Integer currentCode = message.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class); - int codeToUse = currentCode == null ? defaultCode : currentCode; - - if (codeToUse != 500) { - if ((body == null) || (body instanceof String && ((String) body).trim().isEmpty())) { - // no content - codeToUse = currentCode == null ? 204 : currentCode; - } - } - - return codeToUse; - } - - static void writeResponse(RoutingContext ctx, Exchange camelExchange, HeaderFilterStrategy headerFilterStrategy) { - final Object body = toHttpResponse(ctx.response(), camelExchange.getMessage(), headerFilterStrategy); - - final HttpServerResponse response = ctx.response(); - if (body == null) { - LOG.trace("No payload to send as reply for exchange: {}", camelExchange); - response.end(); - } else if (body instanceof String) { - response.end((String) body); - } else if (body instanceof InputStream) { - final byte[] bytes = new byte[4096]; - try (InputStream in = (InputStream) body) { - int len; - while ((len = in.read(bytes)) >= 0) { - response.write(Buffer.buffer(len).appendBytes(bytes, 0, len)); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - response.end(); - } else { - final TypeConverter tc = camelExchange.getContext().getTypeConverter(); - try { - final ByteBuffer bb = tc.mandatoryConvertTo(ByteBuffer.class, body); - response.end(Buffer.buffer(bb.capacity()).setBytes(0, bb)); - } catch (TypeConversionException | NoTypeConversionAvailableException e) { - throw new RuntimeException(e); - } - } - - } - - private Exchange toExchange(RoutingContext ctx) { - final Exchange exchange = getEndpoint().createExchange(); - Message in = toCamelMessage(ctx, exchange); - - final String charset = ctx.parsedHeaders().contentType().parameter("charset"); - if (charset != null) { - exchange.setProperty(Exchange.CHARSET_NAME, charset); - in.setHeader(Exchange.HTTP_CHARACTER_ENCODING, charset); - } - - exchange.setIn(in); - return exchange; - } - - private Message toCamelMessage(RoutingContext ctx, Exchange exchange) { - final Message result = new DefaultMessage(exchange); - - final HeaderFilterStrategy headerFilterStrategy = getEndpoint().getHeaderFilterStrategy(); - populateCamelHeaders(ctx, result.getHeaders(), exchange, headerFilterStrategy); - final String mimeType = ctx.parsedHeaders().contentType().value(); - final boolean isMultipartFormData = "multipart/form-data".equals(mimeType); - if ("application/x-www-form-urlencoded".equals(mimeType) || isMultipartFormData) { - final MultiMap formData = ctx.request().formAttributes(); - final Map<String, Object> body = new HashMap<>(); - for (String key : formData.names()) { - for (String value : formData.getAll(key)) { - if (headerFilterStrategy != null - && !headerFilterStrategy.applyFilterToExternalHeaders(key, value, exchange)) { - appendHeader(result.getHeaders(), key, value); - appendHeader(body, key, value); - } - } - } - result.setBody(body); - if (isMultipartFormData) { - //populateAttachments(ctx.fileUploads(), result); - } - } else { - // extract body by myself if undertow parser didn't handle and the method is allowed to have one - // body is extracted as byte[] then auto TypeConverter kicks in - Method m = Method.valueOf(ctx.request().method().name()); - if (m.canHaveBody()) { - final Buffer body = ctx.getBody(); - if (body != null) { - result.setBody(body.getBytes()); - } - } else { - result.setBody(null); - } - } - return result; - } - - static void populateCamelHeaders( - RoutingContext ctx, - Map<String, Object> headersMap, - Exchange exchange, - HeaderFilterStrategy headerFilterStrategy) { - - final HttpServerRequest request = ctx.request(); - headersMap.put(Exchange.HTTP_PATH, request.path()); - - if (headerFilterStrategy != null) { - final MultiMap requestHeaders = request.headers(); - final String authz = requestHeaders.get("authorization"); - // store a special header that this request was authenticated using HTTP Basic - if (authz != null && authz.trim().startsWith("Basic")) { - if (!headerFilterStrategy.applyFilterToExternalHeaders(Exchange.AUTHENTICATION, "Basic", exchange)) { - appendHeader(headersMap, Exchange.AUTHENTICATION, "Basic"); - } - } - for (String name : requestHeaders.names()) { - // add the headers one by one, and use the header filter strategy - for (String value : requestHeaders.getAll(name)) { - if (!headerFilterStrategy.applyFilterToExternalHeaders(name.toString(), value, exchange)) { - appendHeader(headersMap, name.toString(), value); - } - } - } - - // process uri parameters as headers - final MultiMap pathParameters = ctx.queryParams(); - // continue if the map is not empty, otherwise there are no params - if (!pathParameters.isEmpty()) { - for (String name : pathParameters.names()) { - for (String value : pathParameters.getAll(name)) { - if (!headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange)) { - appendHeader(headersMap, name, value); - } - } - } - } - } - - // Path parameters - ctx.pathParams().forEach((k, v) -> appendHeader(headersMap, k, v)); - - // NOTE: these headers is applied using the same logic as camel-http/camel-jetty to be consistent - headersMap.put(Exchange.HTTP_METHOD, request.method().toString()); - // strip query parameters from the uri - headersMap.put(Exchange.HTTP_URL, request.absoluteURI()); - // uri is without the host and port - headersMap.put(Exchange.HTTP_URI, request.uri()); - headersMap.put(Exchange.HTTP_QUERY, request.query()); - headersMap.put(Exchange.HTTP_RAW_QUERY, request.query()); - } - - @SuppressWarnings("unchecked") - static void appendHeader(Map<String, Object> headers, String key, Object value) { - if (headers.containsKey(key)) { - Object existing = headers.get(key); - List<Object> list; - if (existing instanceof List) { - list = (List<Object>) existing; - } else { - list = new ArrayList<>(); - list.add(existing); - } - list.add(value); - value = list; - } - - headers.put(key, value); - } -} diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/support/CorsHandler.java b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/support/CorsHandler.java deleted file mode 100644 index f206b3f..0000000 --- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/support/CorsHandler.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.http.support; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -import io.vertx.core.Handler; -import io.vertx.core.http.HttpHeaders; -import io.vertx.core.http.HttpMethod; -import io.vertx.core.http.HttpServerRequest; -import io.vertx.core.http.HttpServerResponse; -import io.vertx.ext.web.RoutingContext; -import org.apache.camel.k.http.PlatformHttpServiceConfiguration; -import org.apache.camel.util.ObjectHelper; - -public class CorsHandler implements Handler<RoutingContext> { - - private static final Pattern COMMA_SEPARATED_SPLIT_REGEX = Pattern.compile("\\s*,\\s*"); - - // This is set in the recorder at runtime. - // Must be static because the filter is created(deployed) at build time and runtime config is still not available - final PlatformHttpServiceConfiguration.CorsConfiguration corsConfig; - - public CorsHandler(PlatformHttpServiceConfiguration configuration) { - this.corsConfig = ObjectHelper.notNull(configuration.getCors(), "config"); - } - - private void processRequestedHeaders(HttpServerResponse response, String allowHeadersValue) { - if (ObjectHelper.isEmpty(corsConfig.getHeaders())) { - response.headers().set(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, allowHeadersValue); - } else { - List<String> requestedHeaders = new ArrayList<>(); - for (String requestedHeader : COMMA_SEPARATED_SPLIT_REGEX.split(allowHeadersValue)) { - requestedHeaders.add(requestedHeader.toLowerCase()); - } - - List<String> validRequestedHeaders = new ArrayList<>(); - for (String configHeader : corsConfig.getHeaders()) { - if (requestedHeaders.contains(configHeader.toLowerCase())) { - validRequestedHeaders.add(configHeader); - } - } - - if (!validRequestedHeaders.isEmpty()) { - response.headers().set(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, String.join(",", validRequestedHeaders)); - } - } - } - - private void processMethods(HttpServerResponse response, String allowMethodsValue) { - if (ObjectHelper.isEmpty(corsConfig.getMethods())) { - response.headers().set(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, allowMethodsValue); - } else { - List<String> requestedMethods = new ArrayList<>(); - for (String requestedMethod : COMMA_SEPARATED_SPLIT_REGEX.split(allowMethodsValue)) { - requestedMethods.add(requestedMethod.toLowerCase()); - } - - List<String> validRequestedMethods = new ArrayList<>(); - for (String configMethod : corsConfig.getMethods()) { - if (requestedMethods.contains(configMethod.toLowerCase())) { - validRequestedMethods.add(configMethod); - } - } - - if (!validRequestedMethods.isEmpty()) { - response.headers().set(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, String.join(",", validRequestedMethods)); - } - } - } - - @Override - public void handle(RoutingContext event) { - final HttpServerRequest request = event.request(); - final HttpServerResponse response = event.response(); - final String origin = request.getHeader(HttpHeaders.ORIGIN); - - if (origin == null) { - event.next(); - } else { - final String requestedMethods = request.getHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD); - - if (requestedMethods != null) { - processMethods(response, requestedMethods); - } - - final String requestedHeaders = request.getHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS); - - if (requestedHeaders != null) { - processRequestedHeaders(response, requestedHeaders); - } - - boolean allowsOrigin = ObjectHelper.isEmpty(corsConfig.getOrigins()) || corsConfig.getOrigins().contains(origin); - - if (allowsOrigin) { - response.headers().set(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, origin); - } - - response.headers().set(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); - - - if (ObjectHelper.isNotEmpty(corsConfig.getExposedHeaders())) { - response.headers().set( - HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, - String.join(",", corsConfig.getExposedHeaders())); - } - - if (request.method().equals(HttpMethod.OPTIONS)) { - if ((requestedHeaders != null || requestedMethods != null) && corsConfig.getAccessControlMaxAge() != null) { - response.putHeader( - HttpHeaders.ACCESS_CONTROL_MAX_AGE, - String.valueOf(corsConfig.getAccessControlMaxAge().getSeconds())); - } - response.end(); - } else { - event.next(); - } - } - } -} \ No newline at end of file diff --git a/camel-k-runtime-http/src/test/java/org/apache/camel/k/http/PlatformHttpServiceCustomizerTest.java b/camel-k-runtime-http/src/test/java/org/apache/camel/k/http/PlatformHttpServiceCustomizerTest.java index 460e44e..d8afd69 100644 --- a/camel-k-runtime-http/src/test/java/org/apache/camel/k/http/PlatformHttpServiceCustomizerTest.java +++ b/camel-k-runtime-http/src/test/java/org/apache/camel/k/http/PlatformHttpServiceCustomizerTest.java @@ -26,9 +26,10 @@ import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.platform.http.PlatformHttpComponent; import org.apache.camel.component.platform.http.PlatformHttpConstants; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpEngine; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpRouter; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.k.Runtime; -import org.apache.camel.k.http.engine.RuntimePlatformHttpEngine; import org.apache.camel.k.test.AvailablePortFinder; import org.apache.camel.support.jsse.KeyManagersParameters; import org.apache.camel.support.jsse.KeyStoreParameters; @@ -64,7 +65,7 @@ public class PlatformHttpServiceCustomizerTest { try { runtime.getCamelContext().start(); - PlatformHttp.lookup(runtime.getCamelContext()).router().route(HttpMethod.GET, "/my/path") + VertxPlatformHttpRouter.lookup(runtime.getCamelContext()).route(HttpMethod.GET, "/my/path") .handler(routingContext -> { JsonObject response = new JsonObject(); response.put("status", "UP"); @@ -106,7 +107,7 @@ public class PlatformHttpServiceCustomizerTest { PlatformHttpComponent c = runtime.getCamelContext().getComponent(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME, PlatformHttpComponent.class); assertThat(c).isNotNull(); - assertThat(c.getEngine()).isInstanceOf(RuntimePlatformHttpEngine.class); + assertThat(c.getEngine()).isInstanceOf(VertxPlatformHttpEngine.class); try { runtime.getCamelContext().start(); @@ -142,7 +143,7 @@ public class PlatformHttpServiceCustomizerTest { PlatformHttpComponent c = runtime.getCamelContext().getComponent(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME, PlatformHttpComponent.class); assertThat(c).isNotNull(); - assertThat(c.getEngine()).isInstanceOf(RuntimePlatformHttpEngine.class); + assertThat(c.getEngine()).isInstanceOf(VertxPlatformHttpEngine.class); try { runtime.getCamelContext().start(); @@ -168,17 +169,16 @@ public class PlatformHttpServiceCustomizerTest { httpService.setBindPort(AvailablePortFinder.getNextAvailable()); httpService.apply(runtime.getCamelContext()); - PlatformHttp.lookup(runtime.getCamelContext()) - .router() - .route(HttpMethod.GET, "/my/path") - .handler(routingContext -> routingContext.response().setStatusCode(200).end()); + //VertxPlatformHttpRouter.lookup(runtime.getCamelContext()) + // .route(HttpMethod.GET, "/my/path") + // .handler(routingContext -> routingContext.response().setStatusCode(200).end()); assertThatExceptionOfType(ConnectException.class).isThrownBy( () -> { given() .port(httpService.getBindPort()) .when() - .get("/my/path") + .get("/") .then() .extract(); } diff --git a/camel-knative/camel-knative-api/pom.xml b/camel-knative/camel-knative-api/pom.xml index 4ca5b01..93434ba 100644 --- a/camel-knative/camel-knative-api/pom.xml +++ b/camel-knative/camel-knative-api/pom.xml @@ -76,6 +76,18 @@ <build> <plugins> <plugin> + <groupId>org.jboss.jandex</groupId> + <artifactId>jandex-maven-plugin</artifactId> + <executions> + <execution> + <id>make-index</id> + <goals> + <goal>jandex</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> <groupId>org.apache.camel</groupId> <artifactId>camel-package-maven-plugin</artifactId> <version>${camel.version}</version> @@ -86,7 +98,7 @@ <execution> <id>generate</id> <goals> - <goal>generate-component</goal> + <goal>generate-configurer</goal> </goals> <phase>process-classes</phase> </execution> diff --git a/camel-knative/camel-knative-http/pom.xml b/camel-knative/camel-knative-http/pom.xml index 12f6b5d..087d432 100644 --- a/camel-knative/camel-knative-http/pom.xml +++ b/camel-knative/camel-knative-http/pom.xml @@ -114,6 +114,23 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-package-maven-plugin</artifactId> + <version>${camel.version}</version> + <configuration> + <failFast>false</failFast> + </configuration> + <executions> + <execution> + <id>generate</id> + <goals> + <goal>generate-configurer</goal> + </goals> + <phase>process-classes</phase> + </execution> + </executions> + </plugin> </plugins> </build> diff --git a/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumer.java b/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumer.java index 810abcc..4764e40 100644 --- a/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumer.java +++ b/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumer.java @@ -37,7 +37,7 @@ import org.apache.camel.NoTypeConversionAvailableException; import org.apache.camel.Processor; import org.apache.camel.TypeConverter; import org.apache.camel.component.knative.spi.KnativeEnvironment; -import org.apache.camel.k.http.PlatformHttp; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpRouter; import org.apache.camel.spi.HeaderFilterStrategy; import org.apache.camel.support.DefaultConsumer; import org.apache.camel.support.DefaultMessage; @@ -53,7 +53,7 @@ public class KnativeHttpConsumer extends DefaultConsumer { private final KnativeHttpTransport transport; private final Predicate<HttpServerRequest> filter; private final KnativeEnvironment.KnativeServiceDefinition serviceDefinition; - private final PlatformHttp platformHttp; + private final VertxPlatformHttpRouter router; private final HeaderFilterStrategy headerFilterStrategy; private String basePath; @@ -63,14 +63,14 @@ public class KnativeHttpConsumer extends DefaultConsumer { KnativeHttpTransport transport, Endpoint endpoint, KnativeEnvironment.KnativeServiceDefinition serviceDefinition, - PlatformHttp platformHttp, + VertxPlatformHttpRouter router, Processor processor) { super(endpoint, processor); this.transport = transport; this.serviceDefinition = serviceDefinition; - this.platformHttp = platformHttp; + this.router = router; this.headerFilterStrategy = new KnativeHttpHeaderFilterStrategy(); this.filter = KnativeHttpSupport.createFilter(serviceDefinition); } @@ -100,14 +100,15 @@ public class KnativeHttpConsumer extends DefaultConsumer { LOGGER.debug("Creating route for path: {}", path); - route = platformHttp.router().route( + route = router.route( HttpMethod.POST, path ); - // add common handlers - platformHttp.handlers().forEach(route::handler); + // add body handler + route.handler(router.bodyHandler()); + // add knative handler route.handler(routingContext -> { LOGGER.debug("Handling {}", routingContext); diff --git a/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java b/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java index d7e696e..d707a51 100644 --- a/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java +++ b/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java @@ -19,6 +19,7 @@ package org.apache.camel.component.knative.http; import java.util.Map; import io.vertx.core.MultiMap; +import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpHeaders; import io.vertx.ext.web.client.HttpResponse; @@ -31,7 +32,6 @@ import org.apache.camel.Exchange; import org.apache.camel.InvalidPayloadException; import org.apache.camel.Message; import org.apache.camel.component.knative.spi.KnativeEnvironment; -import org.apache.camel.k.http.PlatformHttp; import org.apache.camel.spi.HeaderFilterStrategy; import org.apache.camel.support.DefaultAsyncProducer; import org.apache.camel.support.DefaultMessage; @@ -46,7 +46,7 @@ public class KnativeHttpProducer extends DefaultAsyncProducer { private final KnativeHttpTransport transport; private final KnativeEnvironment.KnativeServiceDefinition serviceDefinition; - private final PlatformHttp platformHttp; + private final Vertx vertx; private final WebClientOptions clientOptions; private final HeaderFilterStrategy headerFilterStrategy; @@ -56,13 +56,13 @@ public class KnativeHttpProducer extends DefaultAsyncProducer { KnativeHttpTransport transport, Endpoint endpoint, KnativeEnvironment.KnativeServiceDefinition serviceDefinition, - PlatformHttp platformHttp, + Vertx vertx, WebClientOptions clientOptions) { super(endpoint); this.transport = transport; this.serviceDefinition = serviceDefinition; - this.platformHttp = ObjectHelper.notNull(platformHttp, "vertx"); + this.vertx = ObjectHelper.notNull(vertx, "vertx"); this.clientOptions = ObjectHelper.supplyIfEmpty(clientOptions, WebClientOptions::new); this.headerFilterStrategy = new KnativeHttpHeaderFilterStrategy(); } @@ -166,7 +166,7 @@ public class KnativeHttpProducer extends DefaultAsyncProducer { protected void doInit() throws Exception { super.doInit(); - this.client = WebClient.create(platformHttp.vertx(), clientOptions); + this.client = WebClient.create(vertx, clientOptions); } @Override diff --git a/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpTransport.java b/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpTransport.java index 039a719..1666d7a 100644 --- a/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpTransport.java +++ b/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpTransport.java @@ -26,26 +26,26 @@ import org.apache.camel.Producer; import org.apache.camel.component.knative.spi.KnativeEnvironment; import org.apache.camel.component.knative.spi.KnativeTransport; import org.apache.camel.component.knative.spi.KnativeTransportConfiguration; -import org.apache.camel.k.http.PlatformHttp; +import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpRouter; import org.apache.camel.support.service.ServiceSupport; public class KnativeHttpTransport extends ServiceSupport implements CamelContextAware, KnativeTransport { public static final int DEFAULT_PORT = 8080; public static final String DEFAULT_PATH = "/"; - private PlatformHttp platformHttp; + private VertxPlatformHttpRouter router; private WebClientOptions vertxHttpClientOptions; private CamelContext camelContext; public KnativeHttpTransport() { } - public PlatformHttp getPlatformHttp() { - return platformHttp; + public VertxPlatformHttpRouter getRouter() { + return router; } - public void setPlatformHttp(PlatformHttp platformHttp) { - this.platformHttp = platformHttp; + public void setRouter(VertxPlatformHttpRouter router) { + this.router = router; } public WebClientOptions getClientOptions() { @@ -74,8 +74,8 @@ public class KnativeHttpTransport extends ServiceSupport implements CamelContext @Override protected void doStart() throws Exception { - if (this.platformHttp == null) { - this.platformHttp = PlatformHttp.lookup(camelContext); + if (this.router == null) { + this.router = VertxPlatformHttpRouter.lookup(camelContext); } } @@ -91,7 +91,7 @@ public class KnativeHttpTransport extends ServiceSupport implements CamelContext @Override public Producer createProducer(Endpoint endpoint, KnativeTransportConfiguration config, KnativeEnvironment.KnativeServiceDefinition service) { - return new KnativeHttpProducer(this, endpoint, service, this.platformHttp, vertxHttpClientOptions); + return new KnativeHttpProducer(this, endpoint, service, this.router.vertx(), vertxHttpClientOptions); } @Override @@ -102,7 +102,7 @@ public class KnativeHttpTransport extends ServiceSupport implements CamelContext next = KnativeHttpSupport.withoutCloudEventHeaders(next, config.getCloudEvent()); } - return new KnativeHttpConsumer(this, endpoint, service, this.platformHttp, next); + return new KnativeHttpConsumer(this, endpoint, service, this.router, next); } } diff --git a/camel-knative/camel-knative/pom.xml b/camel-knative/camel-knative/pom.xml index f1d2301..03d56c8 100644 --- a/camel-knative/camel-knative/pom.xml +++ b/camel-knative/camel-knative/pom.xml @@ -80,6 +80,18 @@ <build> <plugins> <plugin> + <groupId>org.jboss.jandex</groupId> + <artifactId>jandex-maven-plugin</artifactId> + <executions> + <execution> + <id>make-index</id> + <goals> + <goal>jandex</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> <groupId>org.apache.camel</groupId> <artifactId>camel-package-maven-plugin</artifactId> <version>${camel.version}</version> @@ -91,6 +103,7 @@ <id>generate</id> <goals> <goal>generate-component</goal> + <goal>generate-configurer</goal> </goals> <phase>process-classes</phase> </execution> diff --git a/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json b/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json index 0a54039..a0cd44d 100644 --- a/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json +++ b/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json @@ -2,22 +2,23 @@ "component": { "kind": "component", "name": "knative", - "scheme": "knative", - "extendsScheme": "", - "syntax": "knative:type\/name", "title": "Knative", "description": "This component allows to interact with KNative events.", - "label": "cloud,eventing", "deprecated": false, - "async": false, - "consumerOnly": false, - "producerOnly": false, - "lenientProperties": false, - "javaType": "org.apache.camel.component.knative.KnativeComponent", "firstVersion": "3.0.0", + "label": "cloud,eventing", + "javaType": "org.apache.camel.component.knative.KnativeComponent", + "supportLevel": "Preview", "groupId": "org.apache.camel.k", "artifactId": "camel-knative", - "version": "1.3.0-SNAPSHOT" + "version": "1.3.0-SNAPSHOT", + "scheme": "knative", + "extendsScheme": "", + "syntax": "knative:type\/name", + "async": false, + "consumerOnly": false, + "producerOnly": false, + "lenientProperties": false }, "componentProperties": { "transport": { "kind": "property", "displayName": "Transport", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.knative.spi.KnativeTransport", "deprecated": false, "secret": false, "defaultValue": "http", "description": "The transport implementation." }, diff --git a/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java b/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java index 8b30ee6..63b8e8b 100644 --- a/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java +++ b/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeComponent.java @@ -37,10 +37,8 @@ import org.apache.camel.util.StringHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Component("knative") +@Component(KnativeConstants.SCHEME) public class KnativeComponent extends DefaultComponent { - public static final String CONFIGURATION_ENV_VARIABLE = "CAMEL_KNATIVE_CONFIGURATION"; - private static final Logger LOGGER = LoggerFactory.getLogger(KnativeComponent.class); private KnativeConfiguration configuration; @@ -259,7 +257,7 @@ public class KnativeComponent extends DefaultComponent { } if (conf.getEnvironment() == null) { - String envConfig = System.getenv(CONFIGURATION_ENV_VARIABLE); + String envConfig = System.getenv(KnativeConstants.CONFIGURATION_ENV_VARIABLE); if (environmentPath != null) { conf.setEnvironment( KnativeEnvironment.mandatoryLoadFromResource(getCamelContext(), this.environmentPath) diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpEngine.java b/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeConstants.java similarity index 61% rename from camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpEngine.java rename to camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeConstants.java index 05f8111..2d5e5ce 100644 --- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpEngine.java +++ b/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeConstants.java @@ -14,16 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.k.http.engine; +package org.apache.camel.component.knative; -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.component.platform.http.PlatformHttpEndpoint; -import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; +public final class KnativeConstants { + public static final String SCHEME = "knative"; + public static final String CONFIGURATION_ENV_VARIABLE = "CAMEL_KNATIVE_CONFIGURATION"; -public class RuntimePlatformHttpEngine implements PlatformHttpEngine { - @Override - public Consumer createConsumer(PlatformHttpEndpoint platformHttpEndpoint, Processor processor) { - return new RuntimePlatformHttpConsumer(platformHttpEndpoint, processor); + private KnativeConstants() { } } diff --git a/pom.xml b/pom.xml index 9f816a2..5d4f985 100644 --- a/pom.xml +++ b/pom.xml @@ -39,8 +39,8 @@ <maven.compiler.target>11</maven.compiler.target> <kotlin.compiler.target>1.8</kotlin.compiler.target> - <camel.version>3.2.0</camel.version> - <camel-quarkus.version>1.0.0-M7</camel-quarkus.version> + <camel.version>3.3.0</camel.version> + <camel-quarkus.version>1.0.0-CR1</camel-quarkus.version> <catalog.version>${camel.version}</catalog.version> <junit.version>5.6.2</junit.version> <joor.version>0.9.13</joor.version> @@ -60,9 +60,9 @@ <jaxb-core.version>2.3.0.1</jaxb-core.version> <immutables.version>2.8.8</immutables.version> <semver4j.version>3.1.0</semver4j.version> - <vertx.version>3.8.5</vertx.version> + <vertx.version>3.9.0</vertx.version> <graalvm.version>19.3.1</graalvm.version> - <quarkus.version>1.4.1.Final</quarkus.version> + <quarkus.version>1.5.0.Final</quarkus.version> <jandex.version>2.1.3.Final</jandex.version> <javapoet.version>1.11.1</javapoet.version> <rest-assured.version>4.3.0</rest-assured.version> @@ -271,6 +271,17 @@ <enabled>false</enabled> </releases> </repository> + <repository> + <id>apache.staging</id> + <url>https://repository.apache.org/content/repositories/orgapachecamel-1216</url> + <name>Apache Staging Repo</name> + <snapshots> + <enabled>false</enabled> + </snapshots> + <releases> + <enabled>true</enabled> + </releases> + </repository> </repositories> <pluginRepositories> @@ -284,6 +295,17 @@ <enabled>false</enabled> </releases> </pluginRepository> + <pluginRepository> + <id>apache.staging</id> + <url>https://repository.apache.org/content/repositories/orgapachecamel-1216</url> + <name>Apache Staging Repo</name> + <snapshots> + <enabled>false</enabled> + </snapshots> + <releases> + <enabled>true</enabled> + </releases> + </pluginRepository> </pluginRepositories> <dependencyManagement>