311.4. 使用 Java DSL


以下示例使用名为 DataFormat of soap,它使用软件包 com.example.customerservice 初始化 JAXBContext。第二个参数是 ElementNameStrategy。路由能够汇总普通对象和异常。(请注意,下面只发送 SOAP Envelope 到队列。Web 服务提供商实际上需要侦听 SOAP 调用的队列,在这种情况下,它会是一个 SOAP 请求的一种方式。如果您需要请求回复,您应该查看下一个示例。)

SoapJaxbDataFormat soap = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
from("direct:start")
  .marshal(soap)
  .to("jms:myQueue");
Copy to Clipboard Toggle word wrap
提示

另请参阅,因为 SOAP 数据格式从 JAXB 数据格式大多数设置中继承。

311.4.1. 使用 SOAP 1.2

可从 Camel 2.11 开始

SoapJaxbDataFormat soap = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
soap.setVersion("1.2");
from("direct:start")
  .marshal(soap)
  .to("jms:myQueue");
Copy to Clipboard Toggle word wrap

当使用 XML DSL 时,您可以在 <soapjaxb> 元素上设置 version 属性。

    <!-- Defining a ServiceInterfaceStrategy for retrieving the element name when marshalling -->
    <bean id="myNameStrategy" class="org.apache.camel.dataformat.soap.name.ServiceInterfaceStrategy">
        <constructor-arg value="com.example.customerservice.CustomerService"/>
    <constructor-arg value="true"/>
    </bean>
Copy to Clipboard Toggle word wrap

以及 Camel 路由中的

<route>
  <from uri="direct:start"/>
  <marshal>
    <soapjaxb contentPath="com.example.customerservice" version="1.2" elementNameStrategyRef="myNameStrategy"/>
  </marshal>
  <to uri="jms:myQueue"/>
</route>
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat