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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 14931283b30d CAMEL-22670: camel-jbang - Using CXF should automatic 
download HTTP transport if needed. This makes it easier when using camel-jbang. 
(#19849)
14931283b30d is described below

commit 14931283b30d6e01773386969cd00a9ffed60eb7
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Nov 7 13:16:48 2025 +0100

    CAMEL-22670: camel-jbang - Using CXF should automatic download HTTP 
transport if needed. This makes it easier when using camel-jbang. (#19849)
    
    * CAMEL-22670: camel-jbang - Using CXF should automatic download HTTP 
transport if needed. This makes it easier when using camel-jbang.
---
 .../camel/component/cxf/jaxws/CxfEndpoint.java     |  8 ++++
 .../main/download/CamelDependenciesHelper.java     | 51 ++++++++++++++++++++++
 .../resources/auto-configure/camel-cxf-soap.java   | 47 ++++++++++++++++++++
 3 files changed, 106 insertions(+)

diff --git 
a/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfEndpoint.java
 
b/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfEndpoint.java
index b71f44d5e07b..c8cb74bd785d 100644
--- 
a/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfEndpoint.java
+++ 
b/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfEndpoint.java
@@ -118,6 +118,7 @@ import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.staxutils.StaxSource;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.transport.http.HttpDestinationFactory;
 import org.apache.cxf.wsdl.WSDLManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -357,6 +358,13 @@ public class CxfEndpoint extends DefaultEndpoint 
implements AsyncEndpoint, Heade
 
         sfb.setBus(getBus());
         sfb.setStart(false);
+
+        // add custom http destination factories
+        var factories = 
getCamelContext().getRegistry().findByType(HttpDestinationFactory.class);
+        for (var factory : factories) {
+            sfb.getBus().setExtension(factory, HttpDestinationFactory.class);
+        }
+
         getNullSafeCxfConfigurer().configure(sfb);
     }
 
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/CamelDependenciesHelper.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/CamelDependenciesHelper.java
new file mode 100644
index 000000000000..bfdb82d76e03
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/CamelDependenciesHelper.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.main.download;
+
+import java.io.FileInputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.tooling.maven.MavenArtifact;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.StringHelper;
+
+public class CamelDependenciesHelper {
+
+    /**
+     * Resolve the version of a given dependency defined in the 
camel-dependencies POM file, which has a list of all the
+     * 3rd-party dependencies used by Camel components.
+     */
+    public static String dependencyVersion(CamelContext context, String key) {
+        MavenDependencyDownloader downloader = 
context.hasService(MavenDependencyDownloader.class);
+        if (downloader != null) {
+            MavenArtifact ma = downloader.downloadArtifact("org.apache.camel", 
"camel-dependencies:pom", context.getVersion());
+            if (ma != null && ma.getFile() != null) {
+                FileInputStream fis = null;
+                try {
+                    fis = new FileInputStream(ma.getFile());
+                    String text = IOHelper.loadText(fis);
+                    return StringHelper.between(text, "<" + key + ">", "</" + 
key + ">");
+                } catch (Exception e) {
+                    // ignore
+                } finally {
+                    IOHelper.close(fis);
+                }
+            }
+        }
+        return null;
+    }
+}
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
new file mode 100644
index 000000000000..15d413f216fe
--- /dev/null
+++ 
b/dsl/camel-kamelet-main/src/main/resources/auto-configure/camel-cxf-soap.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.
+ */
+
+// check if we already have CXF transport on classpath
+org.apache.camel.main.download.MavenDependencyDownloader downloader = 
context.hasService(org.apache.camel.main.download.MavenDependencyDownloader.class);
+final var cxfVersion = 
org.apache.camel.main.download.CamelDependenciesHelper.dependencyVersion(context,
 "cxf-version");
+if (cxfVersion == null) {
+    return null;
+}
+boolean jetty = downloader.alreadyOnClasspath("org.apache.cxf", 
"cxf-rt-transports-http-jetty", cxfVersion);
+boolean undertow = downloader.alreadyOnClasspath("org.apache.cxf", 
"cxf-rt-transports-http-undertow", cxfVersion);
+if (jetty || undertow){
+    return null;
+}
+
+// automatic download cxf transport for undertow and register this with CXF
+context.getRegistry().bind("camelCxfUndertowHttpTransportDownloader", new 
org.apache.cxf.transport.http.HttpDestinationFactory() {
+    public org.apache.cxf.transport.http.AbstractHTTPDestination 
createDestination(org.apache.cxf.service.model.EndpointInfo endpointInfo, 
org.apache.cxf.Bus bus, org.apache.cxf.transport.http.DestinationRegistry 
registry) throws java.io.IOException {
+        downloader.downloadDependency("org.apache.cxf", 
"cxf-rt-transports-http-undertow", cxfVersion);
+        try {
+            Class c = 
context.getClassResolver().resolveClass("org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngineFactory");
+            Object o = 
c.getConstructor(org.apache.cxf.Bus.class).newInstance(bus);
+            Class c2 = 
context.getClassResolver().resolveClass("org.apache.cxf.transport.http_undertow.UndertowHTTPDestination");
+            Object o2 = c2.getConstructor(org.apache.cxf.Bus.class, 
org.apache.cxf.transport.http.DestinationRegistry.class, 
org.apache.cxf.service.model.EndpointInfo.class, c)
+                    .newInstance(bus, registry, endpointInfo, o);
+            return (org.apache.cxf.transport.http.AbstractHTTPDestination) o2;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+});
+
+return "Camel JBang will automatic download 
org.apache.cxf:cxf-rt-transports-http-undertow:" + cxfVersion + " if needed by 
camel-cxf-soap";
\ No newline at end of file

Reply via email to