This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-27391-cxf-export-consumers
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 13290ce7c57e866d41e6dfcb8b4906b9b70f6671
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 19:12:08 2026 +0100

    CAMEL-27391: camel-jbang - camel-cxf-platform-http only for an integration 
with a cxf consumer
    
    Camel JBang adds camel-cxf-platform-http when a route with a cxf consumer is
    added (a route of the integration or of a Kamelet), as a dependency of the
    integration, instead of for any camel-cxf-soap. So camel export to Camel 
Main
    adds the module and camel-platform-http-main only for a cxf consumer, and an
    integration with only cxf producers (SOAP clients) gets no HTTP server, also
    not in camel run. The export to Spring Boot and Quarkus drops the module, as
    they serve a consumer with their CXF starter and extension.
    
    A ModelLifecycleStrategy in camel-kamelet-main replaces the auto-configure
    script of camel-cxf-soap, so no script is compiled at startup.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |   4 +-
 .../dsl/jbang/run/export/CamelMainExporter.java    |  11 +-
 .../dsl/jbang/run/export/QuarkusExporter.java      |   3 +
 .../dsl/jbang/run/export/SpringBootExporter.java   |   3 +
 .../dsl/jbang/run/export/ProjectExporterTest.java  |  31 ++++
 .../java/org/apache/camel/main/KameletMain.java    |   3 +
 .../main/download/DependencyDownloaderCxf.java     | 144 ++++++++++++++++
 .../resources/auto-configure/camel-cxf-soap.java   |  50 ------
 .../main/download/DependencyDownloaderCxfTest.java | 188 +++++++++++++++++++++
 9 files changed, 380 insertions(+), 57 deletions(-)

diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 13affde0c13c..5f08ebbb6ac6 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -1308,8 +1308,8 @@ service is then at 
`\http://localhost:8080/services/orders` (with `camel.server.
 scheme and a host fails when the route starts. The `cxf` producer (a SOAP 
client) is not changed and still takes a full
 URL.
 
-`camel export` to Camel Main adds `camel-cxf-platform-http` and 
`camel-platform-http-main` for an integration with
-`camel-cxf-soap`, and turns on the HTTP server. The export to Spring Boot and 
Quarkus uses their CXF starter and
+`camel export` to Camel Main adds `camel-cxf-platform-http` and 
`camel-platform-http-main` for an integration with a
+`cxf` consumer, and turns on the HTTP server; an integration with only `cxf` 
producers gets neither. The export to Spring Boot and Quarkus uses their CXF 
starter and
 extension, as before, with `camel.cxf.path` mapped to `cxf.path` and 
`quarkus.cxf.path`.
 
 A Camel Main application is not changed: it serves a cxf consumer with the 
transport it brings (Jetty or Undertow),
diff --git 
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/CamelMainExporter.java
 
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/CamelMainExporter.java
index 6c434510c1ac..56ea4c7c6ab8 100644
--- 
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/CamelMainExporter.java
+++ 
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/CamelMainExporter.java
@@ -342,11 +342,12 @@ class CamelMainExporter extends Exporter {
             answer.add("mvn:org.apache.camel:camel-platform-http-jolokia");
         }
 
-        // a cxf consumer is served on the platform-http server, as in camel 
run (since 4.24)
-        if (hasCamelArtifact(answer, "camel-cxf-soap") && 
!hasCamelArtifact(answer, "camel-cxf-platform-http")
-                && (request.camelVersion == null || 
VersionHelper.isGE(request.camelVersion, "4.24.0"))) {
-            answer.add("mvn:org.apache.camel:camel-cxf-platform-http");
-            if (!hasCamelArtifact(answer, "camel-platform-http-main")) {
+        // a cxf consumer is served on the platform-http server, as in camel 
run, which adds camel-cxf-platform-http
+        // (since 4.24) for an integration with a cxf consumer, not for cxf 
producers only
+        if (hasCamelArtifact(answer, "camel-cxf-platform-http")) {
+            if (request.camelVersion != null && 
!VersionHelper.isGE(request.camelVersion, "4.24.0")) {
+                removeCamelArtifact(answer, "camel-cxf-platform-http");
+            } else if (!hasCamelArtifact(answer, "camel-platform-http-main")) {
                 answer.add("mvn:org.apache.camel:camel-platform-http-main");
             }
         }
diff --git 
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/QuarkusExporter.java
 
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/QuarkusExporter.java
index 8530ad181e5d..555d7b0b5d63 100644
--- 
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/QuarkusExporter.java
+++ 
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/QuarkusExporter.java
@@ -587,6 +587,9 @@ class QuarkusExporter extends Exporter {
 
         // remove out of the box dependencies
         answer.removeIf(s -> s.contains("camel-core"));
+        // camel run serves a cxf consumer with camel-cxf-platform-http 
(camel-main); the runtime serves it with its
+        // CXF starter or extension
+        removeCamelArtifact(answer, "camel-cxf-platform-http");
 
         if (request.hawtio) {
             answer.add("mvn:org.apache.camel:camel-management");
diff --git 
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/SpringBootExporter.java
 
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/SpringBootExporter.java
index 5d2875d4533d..a9515c23abd5 100644
--- 
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/SpringBootExporter.java
+++ 
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/export/SpringBootExporter.java
@@ -515,6 +515,9 @@ class SpringBootExporter extends Exporter {
 
         // remove out of the box dependencies
         answer.removeIf(s -> s.contains("camel-core"));
+        // camel run serves a cxf consumer with camel-cxf-platform-http 
(camel-main); the runtime serves it with its
+        // CXF starter or extension
+        removeCamelArtifact(answer, "camel-cxf-platform-http");
 
         boolean http = hasCamelArtifact(answer, "camel-platform-http")
                 || hasCamelArtifact(answer, "camel-platform-http-vertx");
diff --git 
a/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/export/ProjectExporterTest.java
 
b/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/export/ProjectExporterTest.java
index 2e78f94c0fbc..51d1d3b8bfe6 100644
--- 
a/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/export/ProjectExporterTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/export/ProjectExporterTest.java
@@ -478,12 +478,14 @@ class ProjectExporterTest {
     @EnumSource(value = RuntimeType.class, names = { "main", "springBoot", 
"quarkus" })
     void cxfConsumerIsServedOnTheHttpServerOfTheRuntime(RuntimeType runtime) 
throws Exception {
         Path route = writeRoute("soap");
+        // camel run adds camel-cxf-platform-http for a route with a cxf 
consumer
         DependencyResolver cxf = r -> {
             Path settings = r.workDir.resolve(ExportHelper.RUN_SETTINGS_FILE);
             Files.createDirectories(settings.getParent());
             Files.writeString(settings, """
                     camel.main.routesIncludePattern=file:%s
                     dependency=camel:cxf-soap
+                    dependency=camel:cxf-platform-http
                     """.formatted(route));
             return 0;
         };
@@ -523,6 +525,35 @@ class ProjectExporterTest {
         }
     }
 
+    @Test
+    void cxfProducersOnlyNeedNoHttpServer() throws Exception {
+        // CAMEL-27391: camel run adds camel-cxf-platform-http only for a cxf 
consumer
+        Path route = writeRoute("soap");
+        DependencyResolver cxf = r -> {
+            Path settings = r.workDir.resolve(ExportHelper.RUN_SETTINGS_FILE);
+            Files.createDirectories(settings.getParent());
+            Files.writeString(settings, """
+                    camel.main.routesIncludePattern=file:%s
+                    dependency=camel:cxf-soap
+                    """.formatted(route));
+            return 0;
+        };
+        Path exportDir = dir.resolve("export");
+        ExportRequest request = request(route, exportDir);
+        request.runtime = RuntimeType.main;
+
+        StringPrinter printer = new StringPrinter();
+        int exit = new ProjectExporter(new 
ExportContext().withPrinter(printer).withDependencyResolver(cxf))
+                .export(request);
+
+        assertThat(exit).as(printer.getOutput()).isZero();
+        String pom = Files.readString(exportDir.resolve("pom.xml"));
+        assertThat(pom).contains("<artifactId>camel-cxf-soap</artifactId>")
+                .doesNotContain("camel-cxf-platform-http", 
"camel-platform-http-main");
+        
assertThat(exportDir.resolve("src/main/resources/application.properties")).content()
+                .doesNotContain("camel.server.enabled");
+    }
+
     @ParameterizedTest
     @EnumSource(value = RuntimeType.class, names = { "main", "springBoot", 
"quarkus" })
     void localJarsAreInTheLibDirectoryAsThePomRefersToThem(RuntimeType 
runtime) throws Exception {
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index b62d1648b4e3..849151eefc2a 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -49,6 +49,7 @@ import 
org.apache.camel.main.download.DependencyDownloadFactoryFinderResolver;
 import org.apache.camel.main.download.DependencyDownloaderClassLoader;
 import org.apache.camel.main.download.DependencyDownloaderClassResolver;
 import org.apache.camel.main.download.DependencyDownloaderComponentResolver;
+import org.apache.camel.main.download.DependencyDownloaderCxf;
 import org.apache.camel.main.download.DependencyDownloaderDataFormatResolver;
 import org.apache.camel.main.download.DependencyDownloaderKamelet;
 import org.apache.camel.main.download.DependencyDownloaderLanguageResolver;
@@ -769,6 +770,8 @@ public class KameletMain extends MainCommandLineSupport {
             Object kameletsVersion = 
getInitialProperties().get(getInstanceType() + ".kameletsVersion");
             answer.addService(new DependencyDownloaderKamelet(
                     answer, kameletsVersion != null ? 
kameletsVersion.toString() : null));
+            // a cxf consumer is served on the platform-http server
+            answer.addService(new DependencyDownloaderCxf(answer, silent));
             answer.addService(new 
DependencyDownloaderPropertiesComponent(answer, knownDeps, silent));
 
             // reloader
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderCxf.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderCxf.java
new file mode 100644
index 000000000000..7af9f1192ef0
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderCxf.java
@@ -0,0 +1,144 @@
+/*
+ * 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.main.download;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.ModelLifecycleStrategy;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.RouteTemplateDefinition;
+import org.apache.camel.support.service.ServiceSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Serves the cxf consumers on the platform-http server 
(camel-cxf-platform-http), as the CXF extension of Quarkus does
+ * on the Vert.x server of Quarkus.
+ * <p>
+ * When the first route with a cxf consumer is added (a route of the 
integration or of a Kamelet),
+ * camel-cxf-platform-http is downloaded, as a dependency of the integration, 
so camel export includes it, and its
+ * transport is bound with a starter of the platform-http server, which starts 
when the first cxf consumer starts. An
+ * integration with only cxf producers (SOAP clients) needs neither.
+ */
+public final class DependencyDownloaderCxf extends ServiceSupport
+        implements CamelContextAware, ModelLifecycleStrategy {
+
+    static final String TRANSPORT_BEAN_NAME = "camelCxfPlatformHttpTransport";
+    private static final String TRANSPORT_CLASS
+            = 
"org.apache.camel.component.cxf.platform.http.CxfPlatformHttpTransport";
+    private static final Logger LOG = 
LoggerFactory.getLogger(DependencyDownloaderCxf.class);
+
+    private CamelContext camelContext;
+    private final boolean silent;
+    private final AtomicBoolean done = new AtomicBoolean();
+
+    public DependencyDownloaderCxf(CamelContext camelContext, boolean silent) {
+        this.camelContext = camelContext;
+        this.silent = silent;
+    }
+
+    @Override
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    @Override
+    protected void doBuild() throws Exception {
+        if (camelContext instanceof ModelCamelContext mcc) {
+            mcc.addModelLifecycleStrategy(this);
+            // the routes that are added already
+            for (RouteDefinition route : mcc.getRouteDefinitions()) {
+                onAddRouteDefinition(route);
+            }
+        }
+    }
+
+    @Override
+    public void onAddRouteDefinition(RouteDefinition routeDefinition) {
+        if (!done.get() && routeDefinition.getInput() != null
+                && isCxfConsumer(camelContext, 
routeDefinition.getInput().getEndpointUri())
+                && done.compareAndSet(false, true)) {
+            LOG.debug("Route: {} has a cxf consumer, which is served on the 
platform-http server",
+                    routeDefinition.getRouteId());
+            servePlatformHttp();
+        }
+    }
+
+    @Override
+    public void onRemoveRouteDefinition(RouteDefinition routeDefinition) {
+        // noop
+    }
+
+    @Override
+    public void onAddRouteTemplateDefinition(RouteTemplateDefinition 
routeTemplateDefinition) {
+        // noop
+    }
+
+    @Override
+    public void onRemoveRouteTemplateDefinition(RouteTemplateDefinition 
routeTemplateDefinition) {
+        // noop
+    }
+
+    /**
+     * Whether the endpoint uri of the input of a route is cxf (a SOAP 
service); not cxfrs, which is another component.
+     */
+    static boolean isCxfConsumer(CamelContext camelContext, String uri) {
+        if (uri != null && uri.startsWith("{{")) {
+            // the uri is a property placeholder
+            try {
+                uri = camelContext.resolvePropertyPlaceholders(uri);
+            } catch (Exception e) {
+                return false;
+            }
+        }
+        return uri != null && uri.startsWith("cxf:");
+    }
+
+    private void servePlatformHttp() {
+        DependencyDownloader downloader = 
camelContext.hasService(DependencyDownloader.class);
+        if (downloader != null) {
+            downloader.downloadDependency("org.apache.camel", 
"camel-cxf-platform-http", camelContext.getVersion());
+        }
+        try {
+            Object transport = 
camelContext.getRegistry().lookupByName(TRANSPORT_BEAN_NAME);
+            if (transport == null) {
+                Class<?> type = 
camelContext.getClassResolver().resolveMandatoryClass(TRANSPORT_CLASS);
+                transport = type.getConstructor().newInstance();
+                CamelContextAware.trySetCamelContext(transport, camelContext);
+                camelContext.getRegistry().bind(TRANSPORT_BEAN_NAME, 
transport);
+            }
+            // start the platform-http server when the first cxf consumer 
starts
+            Runnable starter = () -> 
MainHttpServerFactory.setupHttpServer(camelContext, false);
+            transport.getClass().getMethod("setHttpServerStarter", 
Runnable.class).invoke(transport, starter);
+            if (!silent) {
+                LOG.info("Camel CLI serves cxf consumers on the platform-http 
server under {}",
+                        
camelContext.resolvePropertyPlaceholders("{{camel.cxf.path:/services}}"));
+            }
+        } catch (Exception e) {
+            throw RuntimeCamelException.wrapRuntimeException(e);
+        }
+    }
+}
diff --git 
a/dsl/camel-kamelet-main/src/main/resources/auto-configure/camel-cxf-soap.java 
b/dsl/camel-kamelet-main/src/main/resources/auto-configure/camel-cxf-soap.java
deleted file mode 100644
index 6563c5baffa1..000000000000
--- 
a/dsl/camel-kamelet-main/src/main/resources/auto-configure/camel-cxf-soap.java
+++ /dev/null
@@ -1,50 +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.
- */
-
-// a cxf consumer is served on the platform-http server 
(camel-cxf-platform-http), as the CXF extension of Quarkus does
-// on the Vert.x server of Quarkus; the address of a consumer is a path, 
served under /services (camel.cxf.path)
-//
-// only the Camel API is used directly: the classes of the Camel CLI are not 
visible to the compiler of this script
-// when it runs from the launcher, so they are called by reflection
-var resolver = context.getClassResolver();
-Class downloaderType = 
resolver.resolveMandatoryClass("org.apache.camel.main.download.DependencyDownloader");
-Object downloader = context.hasService(downloaderType);
-downloaderType.getMethod("downloadHiddenDependency", String.class, 
String.class, String.class)
-        .invoke(downloader, "org.apache.camel", "camel-cxf-platform-http", 
context.getVersion());
-
-Class transportType = 
resolver.resolveMandatoryClass("org.apache.camel.component.cxf.platform.http.CxfPlatformHttpTransport");
-Object transport = 
context.getRegistry().lookupByName("camelCxfPlatformHttpTransport");
-if (transport == null) {
-    transport = transportType.getConstructor().newInstance();
-    transportType.getMethod("setCamelContext", 
org.apache.camel.CamelContext.class).invoke(transport, context);
-    context.getRegistry().bind("camelCxfPlatformHttpTransport", transport);
-}
-
-// start the platform-http server when the first cxf consumer starts (not for 
a cxf producer only)
-java.lang.reflect.Method setup = 
resolver.resolveMandatoryClass("org.apache.camel.main.download.MainHttpServerFactory")
-        .getMethod("setupHttpServer", org.apache.camel.CamelContext.class, 
boolean.class);
-Runnable starter = () -> {
-    try {
-        setup.invoke(null, context, false);
-    } catch (Exception e) {
-        throw new IllegalStateException("Cannot start the platform-http server 
for the cxf consumers", e);
-    }
-};
-transportType.getMethod("setHttpServerStarter", 
Runnable.class).invoke(transport, starter);
-
-return "Camel CLI serves cxf consumers on the platform-http server under "
-       + context.resolvePropertyPlaceholders("{{camel.cxf.path:/services}}");
diff --git 
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderCxfTest.java
 
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderCxfTest.java
new file mode 100644
index 000000000000..b1dcc1c891bc
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderCxfTest.java
@@ -0,0 +1,188 @@
+/*
+ * 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.main.download;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class DependencyDownloaderCxfTest {
+
+    private static final String MODULE = 
"org.apache.camel:camel-cxf-platform-http";
+
+    @Test
+    void 
aRouteWithACxfConsumerDownloadsTheModuleAndSetsTheStarterOfTheHttpServer() 
throws Exception {
+        RecordingDownloader downloader = new RecordingDownloader();
+        FakeTransport transport = new FakeTransport();
+        try (CamelContext context = context(downloader, transport)) {
+            context.addService(new DependencyDownloaderCxf(context, true));
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    
from("cxf:/orders?serviceClass=org.example.Orders").to("log:orders");
+                    
from("cxf:/invoices?serviceClass=org.example.Invoices").to("log:invoices");
+                }
+            });
+
+            // a dependency of the integration (so camel export has it), 
downloaded once
+            assertEquals(List.of(MODULE), downloader.downloaded);
+            assertNotNull(transport.starter);
+        }
+    }
+
+    @Test
+    void cxfProducersOnlyNeedNeitherTheModuleNorTheHttpServer() throws 
Exception {
+        RecordingDownloader downloader = new RecordingDownloader();
+        FakeTransport transport = new FakeTransport();
+        try (CamelContext context = context(downloader, transport)) {
+            context.addService(new DependencyDownloaderCxf(context, true));
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    
from("direct:start").to("cxf:http://localhost:9000/orders?serviceClass=org.example.Orders";);
+                    // cxfrs is another component (camel-cxf-rest)
+                    
from("cxfrs:/customers?resourceClasses=org.example.Customers").to("log:customers");
+                }
+            });
+
+            assertTrue(downloader.downloaded.isEmpty(), 
downloader.downloaded.toString());
+            assertNull(transport.starter);
+        }
+    }
+
+    @Test
+    void theRoutesThatAreAddedBeforeAreChecked() throws Exception {
+        RecordingDownloader downloader = new RecordingDownloader();
+        FakeTransport transport = new FakeTransport();
+        try (CamelContext context = context(downloader, transport)) {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    
from("cxf:/orders?serviceClass=org.example.Orders").to("log:orders");
+                }
+            });
+            context.addService(new DependencyDownloaderCxf(context, true));
+
+            assertEquals(List.of(MODULE), downloader.downloaded);
+            assertNotNull(transport.starter);
+        }
+    }
+
+    @Test
+    void aRouteFromATemplateWithACxfConsumer() throws Exception {
+        // such as the route of a Kamelet, which is created from its template
+        RecordingDownloader downloader = new RecordingDownloader();
+        FakeTransport transport = new FakeTransport();
+        try (CamelContext context = context(downloader, transport)) {
+            context.addService(new DependencyDownloaderCxf(context, true));
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    routeTemplate("soap").templateParameter("address")
+                            
.from("cxf:{{address}}?serviceClass=org.example.Orders").to("log:orders");
+                }
+            });
+            assertTrue(downloader.downloaded.isEmpty(), 
downloader.downloaded.toString());
+
+            context.addRouteFromTemplate("orders", "soap", Map.of("address", 
"/orders"));
+
+            assertEquals(List.of(MODULE), downloader.downloaded);
+            assertNotNull(transport.starter);
+        }
+    }
+
+    @Test
+    void isCxfConsumer() throws Exception {
+        try (CamelContext context = new DefaultCamelContext()) {
+            Properties props = new Properties();
+            props.setProperty("soap.uri", "cxf:/orders");
+            props.setProperty("timer.uri", "timer:tick");
+            context.getPropertiesComponent().setInitialProperties(props);
+
+            assertTrue(DependencyDownloaderCxf.isCxfConsumer(context, 
"cxf:/orders"));
+            assertTrue(DependencyDownloaderCxf.isCxfConsumer(context, 
"cxf://http://0.0.0.0:9000/orders";));
+            assertTrue(DependencyDownloaderCxf.isCxfConsumer(context, 
"cxf:bean:ordersEndpoint"));
+            assertTrue(DependencyDownloaderCxf.isCxfConsumer(context, 
"{{soap.uri}}"));
+            assertFalse(DependencyDownloaderCxf.isCxfConsumer(context, 
"{{timer.uri}}"));
+            assertFalse(DependencyDownloaderCxf.isCxfConsumer(context, 
"{{not.there}}"));
+            assertFalse(DependencyDownloaderCxf.isCxfConsumer(context, 
"cxfrs:/customers"));
+            assertFalse(DependencyDownloaderCxf.isCxfConsumer(context, 
"direct:start"));
+            assertFalse(DependencyDownloaderCxf.isCxfConsumer(context, null));
+        }
+    }
+
+    private static CamelContext context(RecordingDownloader downloader, 
FakeTransport transport) throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        context.addService(downloader);
+        // camel-cxf-platform-http is not on the classpath of the test: its 
transport is bound already
+        
context.getRegistry().bind(DependencyDownloaderCxf.TRANSPORT_BEAN_NAME, 
transport);
+        return context;
+    }
+
+    /** The setter of CxfPlatformHttpTransport that the downloader calls. */
+    public static class FakeTransport {
+
+        private Runnable starter;
+
+        public void setHttpServerStarter(Runnable starter) {
+            this.starter = starter;
+        }
+    }
+
+    /** Records the downloads and downloads nothing. */
+    private static class RecordingDownloader extends MavenDependencyDownloader 
{
+
+        private final List<String> downloaded = new CopyOnWriteArrayList<>();
+
+        @Override
+        protected void doBuild() {
+            // noop
+        }
+
+        @Override
+        protected void doInit() {
+            // noop
+        }
+
+        @Override
+        protected void doStart() {
+            // noop
+        }
+
+        @Override
+        protected void doStop() {
+            // noop
+        }
+
+        @Override
+        public void downloadDependency(String groupId, String artifactId, 
String version) {
+            downloaded.add(groupId + ":" + artifactId);
+        }
+    }
+}

Reply via email to