【问题标题】:camel cxf on wildfly野蝇上的骆驼 cxf
【发布时间】:2024-01-03 22:26:01
【问题描述】:

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

当我想部署它时,我收到以下错误:

在 ws 端点部署中检测到 Apache CXF 库 (cxf-core-3.2.0.jar);要么提供一个适当的部署来替换具有容器模块依赖关系的嵌入式库,要么为当前部署禁用 webservices 子系统,为其添加适当的 jboss-deployment-structure.xml 描述符。建议使用前一种方法,因为后一种方法会导致大多数 Web 服务 Java EE 和任何 JBossWS 特定功能被禁用。

尝试了here 的建议,但没有奏效。试图从我的 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 提供的链接设置网络服务。然而,这些示例仅使用了一个带有一个处理器的简单功能。当我在端口定义中有多个操作时,我如何知道调用了哪个函数? 是否可以让骆驼调用被调用的提供接口的实现,还是我必须自己映射它?

【问题讨论】:

标签: java apache-camel cxf wildfly


【解决方案1】:

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

安装 WildFly Camel 后,请查看此链接,您可以在其中了解如何在 WildFly 上使用 camel-cxf 开发代码:
http://wildfly-extras.github.io/wildfly-camel/index.html#_jax_ws

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

更新:

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

camel-cxf端点消费者POJO数据格式基于CXF invoker,所以消息头有一个名为CxfConstants.OPERATION_NAME的属性,消息体是SEI方法参数的列表。

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

【讨论】:

  • 谢谢。这帮助我使用 camel-cxf 运行 Web 服务。你是否也知道我后续问题的答案?
  • 谢谢。它似乎有效 =) 因为我试图使用 XML 来定义我的骆驼路线,所以我不得不使用 ${header.soapAction|operationName}。我认为在 Java 代码中使用它时,您需要导入 camel-cxf-transport (至少这是我从here 推断出来的。另外有趣的是,当使用多个参数时,您想这样称呼你的豆子:&lt;to uri="bean:MyServiceImpl?method=myMethod&amp;amp;multiParameterArray=true"/&gt;
最近更新 更多