diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java index 1f268a6f530d..142ae07c659b 100644 --- a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java +++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java @@ -102,6 +102,28 @@ CamelContextBuildItem context( RuntimeValue context = recorder.createContext(registry.getRegistry(), beanContainer.getValue(), buildTimeConfig); return new CamelContextBuildItem(context); } + + @Record(ExecutionTime.RUNTIME_INIT) + @BuildStep + CamelRuntimeRegistryBuildItem bindRuntimeBeransToRegistry( + CamelRecorder recorder, + CamelRegistryBuildItem registry, + List registryItems) { + + + for (CamelRuntimeBeanBuildItem item : registryItems) { + LOGGER.debug("Binding runtime bean with name: {}, type {}", item.getName(), item.getType()); + + recorder.bind( + registry.getRegistry(), + item.getName(), + item.getType(), + item.getValue() + ); + } + + return new CamelRuntimeRegistryBuildItem(registry.getRegistry()); + } } /* @@ -151,6 +173,9 @@ CamelMainBuildItem main( void start( CamelMainRecorder recorder, CamelMainBuildItem main, + // TODO: keep this as placeholder to ensure the registry is fully configured + // befire startuing the camel context + CamelRuntimeRegistryBuildItem registry, ShutdownContextBuildItem shutdown, // TODO: keep this list as placeholder to ensure the ArC container is fully // started before starting main diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeanBuildItem.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeanBuildItem.java index 84a578a33621..d6ab449fec81 100644 --- a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeanBuildItem.java +++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeanBuildItem.java @@ -19,6 +19,7 @@ import java.util.Objects; import io.quarkus.builder.item.MultiBuildItem; +import io.quarkus.runtime.RuntimeValue; /** * A {@link MultiBuildItem} holding beans to add to {@link org.apache.camel.spi.Registry} during @@ -28,15 +29,9 @@ public final class CamelBeanBuildItem extends MultiBuildItem { private final String name; private final Class type; - private final Object value; + private final RuntimeValue value; - public CamelBeanBuildItem(String name, Object value) { - this.name = Objects.requireNonNull(name); - this.value = Objects.requireNonNull(value); - this.type = Objects.requireNonNull(value).getClass(); - } - - public CamelBeanBuildItem(String name, Class type, Object value) { + public CamelBeanBuildItem(String name, Class type, RuntimeValue value) { this.name = Objects.requireNonNull(name); this.type = Objects.requireNonNull(type); this.value = Objects.requireNonNull(value); @@ -50,7 +45,7 @@ public Class getType() { return type; } - public Object getValue() { + public RuntimeValue getValue() { return value; } } diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeBeanBuildItem.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeBeanBuildItem.java new file mode 100644 index 000000000000..1dda3883bda5 --- /dev/null +++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeBeanBuildItem.java @@ -0,0 +1,51 @@ +/* + * 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.quarkus.core.deployment; + +import java.util.Objects; + +import io.quarkus.builder.item.MultiBuildItem; +import io.quarkus.runtime.RuntimeValue; + +/** + * A {@link MultiBuildItem} holding beans to add to {@link org.apache.camel.spi.Registry} during + * runtime initialization phase. Note that the field type should refer to the most specialized + * class to avoid the issue described in https://issues.apache.org/jira/browse/CAMEL-13948. + */ +public final class CamelRuntimeBeanBuildItem extends MultiBuildItem { + private final String name; + private final Class type; + private final RuntimeValue value; + + public CamelRuntimeBeanBuildItem(String name, Class type, RuntimeValue value) { + this.name = Objects.requireNonNull(name); + this.type = Objects.requireNonNull(type); + this.value = Objects.requireNonNull(value); + } + + public String getName() { + return name; + } + + public Class getType() { + return type; + } + + public RuntimeValue getValue() { + return value; + } +} diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeRegistryBuildItem.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeRegistryBuildItem.java new file mode 100644 index 000000000000..7a045c74696e --- /dev/null +++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeRegistryBuildItem.java @@ -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. + */ +package org.apache.camel.quarkus.core.deployment; + +import io.quarkus.builder.item.SimpleBuildItem; +import io.quarkus.runtime.RuntimeValue; +import org.apache.camel.spi.Registry; + +/** + * Holds the {@link Registry} {@link RuntimeValue}. + */ +public final class CamelRuntimeRegistryBuildItem extends SimpleBuildItem { + private final RuntimeValue value; + + public CamelRuntimeRegistryBuildItem(RuntimeValue value) { + this.value = value; + } + + public RuntimeValue getRegistry() { + return value; + } +} diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java index c18c94a3f003..fb160bad2d2f 100644 --- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java +++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java @@ -73,6 +73,15 @@ public void bind( runtime.getValue().bind(name, type, instance); } + public void bind( + RuntimeValue runtime, + String name, + Class type, + RuntimeValue instance) { + + runtime.getValue().bind(name, type, instance.getValue()); + } + public void bind( RuntimeValue runtime, String name, diff --git a/extensions/microprofile-metrics/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsProcessor.java b/extensions/microprofile-metrics/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsProcessor.java index 1f76a1d05c44..560ed5a7d525 100644 --- a/extensions/microprofile-metrics/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsProcessor.java +++ b/extensions/microprofile-metrics/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsProcessor.java @@ -21,12 +21,11 @@ import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.FeatureBuildItem; - +import org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants; import org.apache.camel.quarkus.component.microprofile.metrics.runtime.CamelMicroProfileMetricsConfig; import org.apache.camel.quarkus.component.microprofile.metrics.runtime.CamelMicroProfileMetricsRecorder; import org.apache.camel.quarkus.core.deployment.CamelBeanBuildItem; import org.eclipse.microprofile.metrics.MetricRegistry; -import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.METRIC_REGISTRY_NAME; class MicroProfileMetricsProcessor { @@ -41,7 +40,7 @@ FeatureBuildItem feature() { @BuildStep CamelBeanBuildItem metricRegistry(CamelMicroProfileMetricsRecorder recorder) { return new CamelBeanBuildItem( - METRIC_REGISTRY_NAME, + MicroProfileMetricsConstants.METRIC_REGISTRY_NAME, MetricRegistry.class, recorder.createApplicationRegistry() ); diff --git a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java index 5ad76e5a7b0f..7546cc974891 100644 --- a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java +++ b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java @@ -17,6 +17,7 @@ package org.apache.camel.quarkus.component.microprofile.metrics.runtime; import io.quarkus.arc.runtime.BeanContainer; +import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.annotations.Recorder; import io.smallrye.metrics.MetricRegistries; @@ -31,8 +32,8 @@ @Recorder public class CamelMicroProfileMetricsRecorder { - public MetricRegistry createApplicationRegistry() { - return MetricRegistries.get(MetricRegistry.Type.APPLICATION); + public RuntimeValue createApplicationRegistry() { + return new RuntimeValue(MetricRegistries.get(MetricRegistry.Type.APPLICATION)); } public void configureCamelContext(CamelMicroProfileMetricsConfig config, BeanContainer beanContainer) { diff --git a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java b/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java index f2bec3166b16..6ecfc0aa1b64 100644 --- a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java +++ b/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java @@ -20,6 +20,8 @@ import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; +import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; +import org.apache.camel.spi.Metadata; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.DefaultComponent; @@ -28,6 +30,8 @@ */ @Component("platform-http") public class PlatformHttpComponent extends DefaultComponent { + @Metadata(label = "advanced") + private PlatformHttpEngine engine; public PlatformHttpComponent() { super(); @@ -39,7 +43,21 @@ public PlatformHttpComponent(CamelContext context) { @Override protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { - return new PlatformHttpEndpoint(uri, remaining, this); + PlatformHttpEndpoint endpoint = new PlatformHttpEndpoint(uri, remaining, this); + endpoint.setPlatformHttpEngine(engine); + + return endpoint; + } + + public PlatformHttpEngine getEngine() { + return engine; } + /** + * Sets the {@link PlatformHttpEngine} to use. + */ + public PlatformHttpComponent setEngine(PlatformHttpEngine engine) { + this.engine = engine; + return this; + } } diff --git a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java b/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java index 3fba42b1e77b..de5a74d693a9 100644 --- a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java +++ b/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java @@ -19,7 +19,7 @@ public final class PlatformHttpConstants { public static final String PLATFORM_HTTP_COMPONENT_NAME = "platform-http"; - public static final String PLATFORM_HTTP_ENGINE_NAME = "platformHttpEngine"; + public static final String PLATFORM_HTTP_ENGINE_NAME = "platform-http-engine"; private PlatformHttpConstants() { } diff --git a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java b/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java index b394b189517a..d79b97ebd401 100644 --- a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java +++ b/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java @@ -24,13 +24,20 @@ import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; import org.apache.camel.spi.HeaderFilterStrategy; import org.apache.camel.spi.HeaderFilterStrategyAware; +import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; import org.apache.camel.support.DefaultEndpoint; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -@UriEndpoint(/* firstVersion = "3.?.0", */ scheme = "platform-http", title = "Platform HTTP", syntax = "platform-http:[methods:]path", label = "http") +@UriEndpoint(/* firstVersion = "3.?.0", */ scheme = "platform-http", title = "Platform HTTP", syntax = "platform-http:path", label = "http", consumerOnly = true) public class PlatformHttpEndpoint extends DefaultEndpoint implements AsyncEndpoint, HeaderFilterStrategyAware { + private static final Logger LOGGER = LoggerFactory.getLogger(PlatformHttpEndpoint.class); + @UriPath + @Metadata(required = true) private final String path; @UriParam(label = "consumer", description = "A comma separated list of HTTP methods to serve, e.g. GET,POST ." @@ -91,16 +98,17 @@ public void setHttpMethodRestrict(String httpMethodRestrict) { @Override protected void doStart() throws Exception { super.doStart(); + if (platformHttpEngine == null) { + LOGGER.debug("Lookup platform http engine from registry"); + platformHttpEngine = getCamelContext().getRegistry() .lookupByNameAndType(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME, PlatformHttpEngine.class); + if (platformHttpEngine == null) { throw new IllegalStateException(PlatformHttpEngine.class.getSimpleName() + " neither set on this " + PlatformHttpEndpoint.class.getSimpleName() + " neither found in Camel Registry."); } } } - - - } diff --git a/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpEngineBuildItem.java b/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpEngineBuildItem.java new file mode 100644 index 000000000000..584372faffd2 --- /dev/null +++ b/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpEngineBuildItem.java @@ -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. + */ +package org.apache.camel.quarkus.component.platform.http.deployment; + +import io.quarkus.builder.item.SimpleBuildItem; +import io.quarkus.runtime.RuntimeValue; +import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; + +/** + * Holds the {@link PlatformHttpEngine} {@link RuntimeValue}. + */ +public final class PlatformHttpEngineBuildItem extends SimpleBuildItem { + private final RuntimeValue instance; + + public PlatformHttpEngineBuildItem(RuntimeValue instance) { + this.instance = instance; + } + + public RuntimeValue getInstance() { + return instance; + } +} diff --git a/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpProcessor.java b/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpProcessor.java index 5c6553c53beb..8b16107f9a61 100644 --- a/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpProcessor.java +++ b/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpProcessor.java @@ -21,8 +21,11 @@ import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.vertx.http.deployment.VertxWebRouterBuildItem; +import org.apache.camel.component.platform.http.PlatformHttpComponent; +import org.apache.camel.component.platform.http.PlatformHttpConstants; import org.apache.camel.quarkus.component.platform.http.runtime.PlatformHttpRecorder; -import org.apache.camel.quarkus.core.deployment.CamelContextBuildItem; +import org.apache.camel.quarkus.component.platform.http.runtime.QuarkusPlatformHttpEngine; +import org.apache.camel.quarkus.core.deployment.CamelRuntimeBeanBuildItem; class PlatformHttpProcessor { @@ -35,8 +38,30 @@ FeatureBuildItem feature() { @Record(ExecutionTime.RUNTIME_INIT) @BuildStep - void platformHttpComponent(PlatformHttpRecorder recorder, CamelContextBuildItem context, VertxWebRouterBuildItem router) { - recorder.registerPlatformHttpComponent(context.getCamelContext(), router.getRouter()); + PlatformHttpEngineBuildItem platformHttpEngine(PlatformHttpRecorder recorder, VertxWebRouterBuildItem router) { + return new PlatformHttpEngineBuildItem( + recorder.engine(router.getRouter()) + ); } + @Record(ExecutionTime.RUNTIME_INIT) + @BuildStep + CamelRuntimeBeanBuildItem platformHttpEngineBean(PlatformHttpRecorder recorder, PlatformHttpEngineBuildItem engine) { + return new CamelRuntimeBeanBuildItem( + PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME, + QuarkusPlatformHttpEngine.class, + engine.getInstance() + ); + } + + + @Record(ExecutionTime.RUNTIME_INIT) + @BuildStep + CamelRuntimeBeanBuildItem platformHttpComponentBean(PlatformHttpRecorder recorder, PlatformHttpEngineBuildItem engine) { + return new CamelRuntimeBeanBuildItem( + PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME, + PlatformHttpComponent.class, + recorder.component(engine.getInstance()) + ); + } } diff --git a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/PlatformHttpRecorder.java b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/PlatformHttpRecorder.java index cdd68df0e028..f710debd3016 100644 --- a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/PlatformHttpRecorder.java +++ b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/PlatformHttpRecorder.java @@ -19,20 +19,19 @@ import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.annotations.Recorder; import io.vertx.ext.web.Router; -import org.apache.camel.CamelContext; import org.apache.camel.component.platform.http.PlatformHttpComponent; -import org.apache.camel.component.platform.http.PlatformHttpConstants; import org.apache.camel.component.platform.http.spi.PlatformHttpEngine; @Recorder public class PlatformHttpRecorder { + public RuntimeValue engine(RuntimeValue router) { + return new RuntimeValue<>(new QuarkusPlatformHttpEngine(router.getValue())); + } - public void registerPlatformHttpComponent(RuntimeValue context, RuntimeValue router) { - final PlatformHttpEngine engine = new QuarkusPlatformHttpEngine(router.getValue()); - context.getValue().getRegistry().bind(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME, PlatformHttpEngine.class, engine); + public RuntimeValue component(RuntimeValue engine) { + PlatformHttpComponent component = new PlatformHttpComponent(); + component.setEngine(engine.getValue()); - final PlatformHttpComponent component = new PlatformHttpComponent(context.getValue()); - context.getValue().getRegistry().bind(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME, PlatformHttpComponent.class, component); + return new RuntimeValue<>(component); } - } diff --git a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java index f1e53d6cfa0a..ce4656c191d8 100644 --- a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java +++ b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpConsumer.java @@ -144,7 +144,7 @@ protected void doResume() throws Exception { super.doResume(); } - Object toHttpResponse(HttpServerResponse response, Message message, HeaderFilterStrategy headerFilterStrategy) { + static Object toHttpResponse(HttpServerResponse response, Message message, HeaderFilterStrategy headerFilterStrategy) { final Exchange exchange = message.getExchange(); final boolean failed = exchange.isFailed(); final int defaultCode = failed ? 500 : 200; @@ -214,7 +214,7 @@ Object toHttpResponse(HttpServerResponse response, Message message, HeaderFilter return body; } - void writeResponse(RoutingContext ctx, Exchange camelExchange, HeaderFilterStrategy headerFilterStrategy) { + static void writeResponse(RoutingContext ctx, Exchange camelExchange, HeaderFilterStrategy headerFilterStrategy) { final Object body = toHttpResponse(ctx.response(), camelExchange.getMessage(), headerFilterStrategy); final HttpServerResponse response = ctx.response(); @@ -254,7 +254,7 @@ void writeResponse(RoutingContext ctx, Exchange camelExchange, HeaderFilterStrat } - Exchange toExchange(RoutingContext ctx, Exchange exchange, HeaderFilterStrategy headerFilterStrategy) { + static Exchange toExchange(RoutingContext ctx, Exchange exchange, HeaderFilterStrategy headerFilterStrategy) { Message in = toCamelMessage(ctx, exchange, headerFilterStrategy); final String charset = ctx.parsedHeaders().contentType().parameter("charset"); @@ -267,7 +267,7 @@ Exchange toExchange(RoutingContext ctx, Exchange exchange, HeaderFilterStrategy return exchange; } - void populateCamelHeaders(RoutingContext ctx, Map headersMap, Exchange exchange, + static void populateCamelHeaders(RoutingContext ctx, Map headersMap, Exchange exchange, HeaderFilterStrategy headerFilterStrategy) { final HttpServerRequest request = ctx.request(); @@ -327,7 +327,7 @@ void populateCamelHeaders(RoutingContext ctx, Map headersMap, Ex headersMap.put(Exchange.HTTP_RAW_QUERY, request.query()); } - Message toCamelMessage(RoutingContext ctx, Exchange exchange, HeaderFilterStrategy headerFilterStrategy) { + static Message toCamelMessage(RoutingContext ctx, Exchange exchange, HeaderFilterStrategy headerFilterStrategy) { Message result = new DefaultMessage(exchange); populateCamelHeaders(ctx, result.getHeaders(), exchange, headerFilterStrategy); diff --git a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpEngine.java b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpEngine.java index 244f7664b877..969c3d1f2f25 100644 --- a/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpEngine.java +++ b/extensions/platform-http/runtime/src/main/java/org/apache/camel/quarkus/component/platform/http/runtime/QuarkusPlatformHttpEngine.java @@ -17,22 +17,16 @@ package org.apache.camel.quarkus.component.platform.http.runtime; import io.vertx.ext.web.Router; - 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 org.jboss.logging.Logger; public class QuarkusPlatformHttpEngine implements PlatformHttpEngine { - - static final Logger LOG = Logger.getLogger(QuarkusPlatformHttpEngine.class); - private final Router router; public QuarkusPlatformHttpEngine(Router router) { - super(); this.router = router; } diff --git a/integration-tests/core/runtime/src/main/java/org/apache/camel/quarkus/core/support/SupportRecorder.java b/integration-tests/core/runtime/src/main/java/org/apache/camel/quarkus/core/support/SupportRecorder.java index 7925f96ad842..06508e5bc26a 100644 --- a/integration-tests/core/runtime/src/main/java/org/apache/camel/quarkus/core/support/SupportRecorder.java +++ b/integration-tests/core/runtime/src/main/java/org/apache/camel/quarkus/core/support/SupportRecorder.java @@ -16,6 +16,7 @@ */ package org.apache.camel.quarkus.core.support; +import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.annotations.Recorder; import org.apache.camel.Component; import org.apache.camel.component.log.LogComponent; @@ -23,7 +24,7 @@ @Recorder public class SupportRecorder { - public Component logComponent() { + public RuntimeValue logComponent() { DefaultExchangeFormatter def = new DefaultExchangeFormatter(); def.setShowAll(true); def.setMultiline(true); @@ -31,6 +32,6 @@ public Component logComponent() { LogComponent component = new LogComponent(); component.setExchangeFormatter(def); - return component; + return new RuntimeValue<>(component); } } diff --git a/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpResource.java b/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpResource.java new file mode 100644 index 000000000000..b16d6164a7b8 --- /dev/null +++ b/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpResource.java @@ -0,0 +1,47 @@ +/* + * 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.quarkus.component.platform.http.it; + +// TODO: investigate why adding resteasy break the platform http component +//@Path("/test") +//@ApplicationScoped +public class PlatformHttpResource { + /* + @Inject + Registry registry; + + @Path("/registry/inspect") + @GET + @Produces(MediaType.TEXT_PLAIN) + public JsonObject inspectRegistry() { + JsonObjectBuilder builder = Json.createObjectBuilder(); + + Object engine = registry.lookupByName(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME); + Object component = registry.lookupByName(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME); + + if (engine != null) { + builder.add(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME, engine.getClass().getName()); + + }if (component != null) { + builder.add(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME, component.getClass().getName()); + + } + + return builder.build(); + } + */ +} diff --git a/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java b/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java index 26147af7296d..943745ff237b 100644 --- a/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java +++ b/integration-tests/platform-http/src/main/java/org/apache/camel/quarkus/component/platform/http/it/PlatformHttpRouteBuilder.java @@ -17,6 +17,8 @@ package org.apache.camel.quarkus.component.platform.http.it; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.platform.http.PlatformHttpConstants; +import org.apache.camel.spi.Registry; public class PlatformHttpRouteBuilder extends RouteBuilder { @@ -25,5 +27,23 @@ public void configure() { from("platform-http:/platform-http/hello?httpMethodRestrict=GET").setBody(simple("Hello ${header.name}")); from("platform-http:/platform-http/get-post?httpMethodRestrict=GET,POST").setBody(simple("Hello ${body}")); from("platform-http:/platform-http/multipart?httpMethodRestrict=POST").setBody(simple("Hello ${body}")); + + fromF("platform-http:/platform-http/registry/%s", PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME).process().message(m -> { + Registry registry = m.getExchange().getContext().getRegistry(); + Object answer = registry.lookupByName(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME); + + if (answer != null) { + m.setBody(answer.getClass().getName()); + } + }); + + fromF("platform-http:/platform-http/registry/%s", PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME).process().message(m -> { + Registry registry = m.getExchange().getContext().getRegistry(); + Object answer = registry.lookupByName(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME); + + if (answer != null) { + m.setBody(answer.getClass().getName()); + } + }); } } diff --git a/integration-tests/platform-http/src/main/resources/application.properties b/integration-tests/platform-http/src/main/resources/application.properties index b3214ac95697..e6407f2a768a 100644 --- a/integration-tests/platform-http/src/main/resources/application.properties +++ b/integration-tests/platform-http/src/main/resources/application.properties @@ -19,8 +19,8 @@ # quarkus.ssl.native=true quarkus.log.file.enable = false +quarkus.log.category."org.apache.camel.quarkus.core.deployment".level = DEBUG quarkus.log.category."org.apache.camel.quarkus.component.platform.http".level = DEBUG - # # Quarkus :: Camel # diff --git a/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java b/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java index b12bf7efcf7a..56bd8ef72b12 100644 --- a/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java +++ b/integration-tests/platform-http/src/test/java/org/apache/camel/quarkus/component/http/server/it/PlatformHttpTest.java @@ -18,20 +18,63 @@ import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; - +import io.restassured.path.json.JsonPath; +import org.apache.camel.component.platform.http.PlatformHttpComponent; +import org.apache.camel.component.platform.http.PlatformHttpConstants; +import org.apache.camel.quarkus.component.platform.http.runtime.QuarkusPlatformHttpEngine; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import static org.hamcrest.core.IsEqual.equalTo; +import static org.hamcrest.CoreMatchers.equalTo; @QuarkusTest class PlatformHttpTest { + @Disabled("looks like adding resteasy break the component") + @Test + public void testRegistrySetUp() { + + JsonPath p = RestAssured.given() + .get("/test/registry/inspect") + .then() + .statusCode(200) + .extract() + .body() + .jsonPath(); + + //assertThat(p.getString(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME)).isEqualTo(QuarkusPlatformHttpEngine.class.getName()); + //assertThat(p.getString(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME)).isEqualTo(PlatformHttpComponent.class.getName()); + } @Test public void basic() { - RestAssured.given().param("name", "Kermit").get("/platform-http/hello").then().statusCode(200).body(equalTo("Hello Kermit")); + RestAssured.given() + .param("name", "Kermit") + .get("/platform-http/hello") + .then() + .statusCode(200) + .body(equalTo("Hello Kermit")); + RestAssured.post("/platform-http/hello").then().statusCode(405); - RestAssured.given().body("Camel").post("/platform-http/get-post").then().statusCode(200).body(equalTo("Hello Camel")); - RestAssured.given().get("/platform-http/get-post").then().statusCode(200).body(equalTo("Hello ")); // there is no body for get - } + RestAssured.given() + .body("Camel") + .post("/platform-http/get-post") + .then() + .statusCode(200) + .body(equalTo("Hello Camel")); + RestAssured.given() + .get("/platform-http/get-post") + .then() + .statusCode(200) + .body(equalTo("Hello ")); // there is no body for get + + RestAssured.given().get("/platform-http/registry/" + PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME) + .then() + .statusCode(200) + .body(equalTo(QuarkusPlatformHttpEngine.class.getName())); + RestAssured.given().get("/platform-http/registry/" + PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME) + .then() + .statusCode(200) + .body(equalTo(PlatformHttpComponent.class.getName())); + } }