野蝇上的骆驼 cxf

camel cxf on wildfly

我已经创建了一个 SOAP 网络服务,我想在 wildfly 上使用 camel-cxf 公开它。

当我想部署它时,出现以下错误:

Apache CXF library (cxf-core-3.2.0.jar) detected in ws endpoint deployment; either provide a proper deployment replacing embedded libraries with container module dependencies or disable the webservices subsystem for the current deployment adding a proper jboss-deployment-structure.xml descriptor to it. The former approach is recommended, as the latter approach causes most of the webservices Java EE and any JBossWS specific functionality to be disabled.

尝试了 建议的方法,但没有奏效。试图从我的 pom.xml:

中包含的 caml-cxf 中排除 cxf 依赖项
<dependency>
   <groupId>org.apache.camel</groupId>
   <artifactId>camel-cxf</artifactId>
   <version>2.20.0</version>
   <exclusions>
     <exclusion>
         <groupId>org.apache.cxf</groupId>
          <artifactId>*</artifactId>
     </exclusion>
   </exclusions>
</dependency>

解决了错误但产生了新错误:

Failed to define class org.apache.camel.component.cxf.spring.AbstractCxfBeanDefinitionParser in Module "deployment.CamelCXF-1.0.war" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link org/apache/camel/component/cxf/spring/AbstractCxfBeanDefinitionParser

Failed to define class org.apache.camel.component.cxf.spring.CxfEndpointBeanDefinitionParser in Module "deployment.CamelCXF-1.0.war" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser

Context initialization failed: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/camel.xml]; nested exception is org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class [org.apache.camel.component.cxf.spring.NamespaceHandler] for namespace [http://camel.apache.org/schema/cxf]: problem with handler class file or dependent class; nested exception is java.lang.NoClassDefFoundError: Failed to link org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser

你能帮我解决这些错误或提供一个我可以在 wildfly 上部署和扩展的小示例吗?非常感激。

在我的 pom.xml 中定义了这些依赖项:

<dependencies>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.20.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-cxf</artifactId>
        <version>2.20.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.cxf</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>5.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>8.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

这是我的 camel.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:camel="http://camel.apache.org/schema/spring"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:cxf="http://camel.apache.org/schema/cxf"
   xsi:schemaLocation="
   http://camel.apache.org/schema/spring 
    http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd">

<cxf:cxfEndpoint id="customerEndpoint"
                 address="http://localhost:8080/TestService/"
                 serviceClass="my.package.TestService"
                 wsdlURL="WEB-INF/CustomerService.wsdl"/>

<bean id="logBean" class="my.package.LogBean"/>

<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="cxf:bean:customerEndpoint" /> 
        <to uri="bean:logBean" />
    </route>
</camel:camelContext>

后续问题

我可以使用@Tadayoshi Sato 提供的链接设置网络服务。然而,这些示例仅使用一个处理器的一个简单函数。当我在端口定义中有多个操作时,我如何知道调用了哪个函数? 是否可以让骆驼调用所提供接口的实现,或者我必须自己映射它?

正如 Claus 所指出的,在 WildFly 上使用 Camel 的最推荐方法是使用 WildFly Camel。您可以在下面的 link 中找到如何将 WildFly Camel 子系统安装到 WildFly:
http://wildfly-extras.github.io/wildfly-camel/index.html

安装 WildFly Camel 后,让我们看看这个 link,您可以在其中找到如何在 WildFly 上使用 camel-cxf 开发代码:
http://wildfly-extras.github.io/wildfly-camel/index.html#_jax_ws

重点是WildFly已经有自己的CXF库作为一个子系统,你需要尽可能使用内置的库;否则,您可能会遇到问题中的尴尬问题。 WildFly Camel 子系统让您可以为您的 Camel 应用程序使用底层的 WildFly 子系统。

更新:

对于 camel-cxf 消费者,调用的操作名称可通过 CxfConstants.OPERATION_NAME 消息头获得。根据:
https://github.com/apache/camel/blob/master/components/camel-cxf/src/main/docs/cxf-component.adoc

The camel-cxf endpoint consumer POJO data format is based on the CXF invoker, so the message header has a property with the name of CxfConstants.OPERATION_NAME and the message body is a list of the SEI method parameters.

您可以 route a message based on this message header 并相应地更改实现。