This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch cxfjbang in repository https://gitbox.apache.org/repos/asf/camel.git
commit 87bdd44e15009ddf9370cc4132698b5fa24e1cd0 Author: Claus Ibsen <[email protected]> AuthorDate: Fri Nov 7 12:28:54 2025 +0100 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 | 17 ++++++++ .../main/download/CamelDependenciesHelper.java | 51 ++++++++++++++++++++++ .../resources/auto-configure/camel-cxf-soap.java | 47 ++++++++++++++++++++ 3 files changed, 115 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..a3bd1573c3ce 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,22 @@ public class CxfEndpoint extends DefaultEndpoint implements AsyncEndpoint, Heade sfb.setBus(getBus()); sfb.setStart(false); + + Class c = getCamelContext().getClassResolver().resolveClass("org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngineFactory"); + Object o = getCamelContext().getInjector().newInstance(c); + + c.getConstructor(Bus.class).newInstance() + + org.apache.camel.support.ObjectHelper.invokeMethodSafe("setBus", o, bus); + + + + // 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
