You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/10/06 19:04:06 UTC
[camel-quarkus] branch master updated: Ensure the
PlatformHttpComponent is registered before the routes are started #218
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new 5e9ea01 Ensure the PlatformHttpComponent is registered before the routes are started #218
new fcd8de3 Merge pull request #230 from lburgazzoli/github-218
5e9ea01 is described below
commit 5e9ea01781a3ee56060abd86f42b9542de65c76e
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sun Oct 6 16:05:27 2019 +0200
Ensure the PlatformHttpComponent is registered before the routes are started #218
---
.../quarkus/core/deployment/BuildProcessor.java | 25 ++++++++++
.../core/deployment/CamelBeanBuildItem.java | 13 ++---
...ildItem.java => CamelRuntimeBeanBuildItem.java} | 17 +++----
.../deployment/CamelRuntimeRegistryBuildItem.java} | 19 ++++++--
.../apache/camel/quarkus/core/CamelRecorder.java | 9 ++++
.../deployment/MicroProfileMetricsProcessor.java | 5 +-
.../runtime/CamelMicroProfileMetricsRecorder.java | 5 +-
.../platform/http/PlatformHttpComponent.java | 20 +++++++-
.../platform/http/PlatformHttpConstants.java | 2 +-
.../platform/http/PlatformHttpEndpoint.java | 16 +++++--
.../deployment/PlatformHttpEngineBuildItem.java} | 19 ++++++--
.../http/deployment/PlatformHttpProcessor.java | 31 ++++++++++--
.../http/runtime/PlatformHttpRecorder.java | 15 +++---
.../http/runtime/QuarkusPlatformHttpConsumer.java | 10 ++--
.../http/runtime/QuarkusPlatformHttpEngine.java | 6 ---
.../quarkus/core/support/SupportRecorder.java | 5 +-
.../platform/http/it/PlatformHttpResource.java | 47 ++++++++++++++++++
.../platform/http/it/PlatformHttpRouteBuilder.java | 20 ++++++++
.../src/main/resources/application.properties | 2 +-
.../component/http/server/it/PlatformHttpTest.java | 55 +++++++++++++++++++---
20 files changed, 269 insertions(+), 72 deletions(-)
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 1f268a6..142ae07 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 @@ class BuildProcessor {
RuntimeValue<CamelContext> context = recorder.createContext(registry.getRegistry(), beanContainer.getValue(), buildTimeConfig);
return new CamelContextBuildItem(context);
}
+
+ @Record(ExecutionTime.RUNTIME_INIT)
+ @BuildStep
+ CamelRuntimeRegistryBuildItem bindRuntimeBeransToRegistry(
+ CamelRecorder recorder,
+ CamelRegistryBuildItem registry,
+ List<CamelRuntimeBeanBuildItem> 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 @@ class BuildProcessor {
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 84a578a..d6ab449 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 @@ 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
@@ -28,15 +29,9 @@ import io.quarkus.builder.item.MultiBuildItem;
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 final class CamelBeanBuildItem extends MultiBuildItem {
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/CamelBeanBuildItem.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeBeanBuildItem.java
similarity index 74%
copy from extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeanBuildItem.java
copy to extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeBeanBuildItem.java
index 84a578a..1dda388 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/CamelRuntimeBeanBuildItem.java
@@ -19,24 +19,19 @@ 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
- * static initialization phase. Note that the field type should refer to the most specialized
+ * 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 CamelBeanBuildItem extends MultiBuildItem {
+public final class CamelRuntimeBeanBuildItem 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 CamelRuntimeBeanBuildItem(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 final class CamelBeanBuildItem extends MultiBuildItem {
return type;
}
- public Object getValue() {
+ public RuntimeValue<?> getValue() {
return value;
}
}
diff --git a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeRegistryBuildItem.java
similarity index 60%
copy from extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java
copy to extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeRegistryBuildItem.java
index 3fba42b..7a045c7 100644
--- a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeRegistryBuildItem.java
@@ -14,14 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.platform.http;
+package org.apache.camel.quarkus.core.deployment;
-public final class PlatformHttpConstants {
+import io.quarkus.builder.item.SimpleBuildItem;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.spi.Registry;
- public static final String PLATFORM_HTTP_COMPONENT_NAME = "platform-http";
- public static final String PLATFORM_HTTP_ENGINE_NAME = "platformHttpEngine";
+/**
+ * Holds the {@link Registry} {@link RuntimeValue}.
+ */
+public final class CamelRuntimeRegistryBuildItem extends SimpleBuildItem {
+ private final RuntimeValue<Registry> value;
- private PlatformHttpConstants() {
+ public CamelRuntimeRegistryBuildItem(RuntimeValue<Registry> value) {
+ this.value = value;
}
+ public RuntimeValue<Registry> 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 c18c94a..fb160ba 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
@@ -76,6 +76,15 @@ public class CamelRecorder {
public void bind(
RuntimeValue<Registry> runtime,
String name,
+ Class<?> type,
+ RuntimeValue<?> instance) {
+
+ runtime.getValue().bind(name, type, instance.getValue());
+ }
+
+ public void bind(
+ RuntimeValue<Registry> runtime,
+ String name,
Class<?> type) {
try {
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 1f76a1d..560ed5a 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.BuildStep;
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 @@ class MicroProfileMetricsProcessor {
@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 5ad76e5..7546cc9 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 @@ import org.eclipse.microprofile.metrics.MetricRegistry;
@Recorder
public class CamelMicroProfileMetricsRecorder {
- public MetricRegistry createApplicationRegistry() {
- return MetricRegistries.get(MetricRegistry.Type.APPLICATION);
+ public RuntimeValue<MetricRegistry> 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 f2bec31..6ecfc0a 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 java.util.Map;
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 @@ import org.apache.camel.support.DefaultComponent;
*/
@Component("platform-http")
public class PlatformHttpComponent extends DefaultComponent {
+ @Metadata(label = "advanced")
+ private PlatformHttpEngine engine;
public PlatformHttpComponent() {
super();
@@ -39,7 +43,21 @@ public class PlatformHttpComponent extends DefaultComponent {
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> 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 3fba42b..de5a74d 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 @@ package org.apache.camel.component.platform.http;
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 b394b18..d79b97e 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.Producer;
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 class PlatformHttpEndpoint extends DefaultEndpoint implements AsyncEndpoi
@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/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java b/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpEngineBuildItem.java
similarity index 55%
copy from extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java
copy to extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpEngineBuildItem.java
index 3fba42b..584372f 100644
--- a/extensions/platform-http/component/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConstants.java
+++ b/extensions/platform-http/deployment/src/main/java/org/apache/camel/quarkus/component/platform/http/deployment/PlatformHttpEngineBuildItem.java
@@ -14,14 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.platform.http;
+package org.apache.camel.quarkus.component.platform.http.deployment;
-public final class PlatformHttpConstants {
+import io.quarkus.builder.item.SimpleBuildItem;
+import io.quarkus.runtime.RuntimeValue;
+import org.apache.camel.component.platform.http.spi.PlatformHttpEngine;
- public static final String PLATFORM_HTTP_COMPONENT_NAME = "platform-http";
- public static final String PLATFORM_HTTP_ENGINE_NAME = "platformHttpEngine";
+/**
+ * Holds the {@link PlatformHttpEngine} {@link RuntimeValue}.
+ */
+public final class PlatformHttpEngineBuildItem extends SimpleBuildItem {
+ private final RuntimeValue<PlatformHttpEngine> instance;
- private PlatformHttpConstants() {
+ public PlatformHttpEngineBuildItem(RuntimeValue<PlatformHttpEngine> instance) {
+ this.instance = instance;
}
+ public RuntimeValue<PlatformHttpEngine> 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 5c6553c..986be50 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.ExecutionTime;
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 @@ class PlatformHttpProcessor {
@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.createEngine(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.createComponent(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 cdd68df..109a711 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 @@ package org.apache.camel.quarkus.component.platform.http.runtime;
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<PlatformHttpEngine> createEngine(RuntimeValue<Router> router) {
+ return new RuntimeValue<>(new QuarkusPlatformHttpEngine(router.getValue()));
+ }
- public void registerPlatformHttpComponent(RuntimeValue<CamelContext> context, RuntimeValue<Router> router) {
- final PlatformHttpEngine engine = new QuarkusPlatformHttpEngine(router.getValue());
- context.getValue().getRegistry().bind(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME, PlatformHttpEngine.class, engine);
+ public RuntimeValue<PlatformHttpComponent> createComponent(RuntimeValue<PlatformHttpEngine> 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 f1e53d6..ce4656c 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 @@ public class QuarkusPlatformHttpConsumer extends DefaultConsumer {
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 @@ public class QuarkusPlatformHttpConsumer extends DefaultConsumer {
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 @@ public class QuarkusPlatformHttpConsumer extends DefaultConsumer {
}
- 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 @@ public class QuarkusPlatformHttpConsumer extends DefaultConsumer {
return exchange;
}
- void populateCamelHeaders(RoutingContext ctx, Map<String, Object> headersMap, Exchange exchange,
+ static void populateCamelHeaders(RoutingContext ctx, Map<String, Object> headersMap, Exchange exchange,
HeaderFilterStrategy headerFilterStrategy) {
final HttpServerRequest request = ctx.request();
@@ -327,7 +327,7 @@ public class QuarkusPlatformHttpConsumer extends DefaultConsumer {
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 244f766..969c3d1 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 7925f96..06508e5 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 @@ import org.apache.camel.support.processor.DefaultExchangeFormatter;
@Recorder
public class SupportRecorder {
- public Component logComponent() {
+ public RuntimeValue<Component> logComponent() {
DefaultExchangeFormatter def = new DefaultExchangeFormatter();
def.setShowAll(true);
def.setMultiline(true);
@@ -31,6 +32,6 @@ public class SupportRecorder {
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 0000000..b16d616
--- /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 26147af..943745f 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 class PlatformHttpRouteBuilder extends RouteBuilder {
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 b3214ac..e6407f2 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 b12bf7e..56bd8ef 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 @@ package org.apache.camel.quarkus.component.http.server.it;
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()));
+ }
}