当数据格式为 MESSAGE 或 CXF_MESSAGE 时在 Apache Camel 中创建 SOAP 消息

Creating SOAP message in Apache Camel when dataFormat is MESSAGE or CXF_MESSAGE

我想通过 Apache Camel 调用 Web 服务,数据格式为 MESSAGE。我想构造以下 SOAP 消息:

<soapenv:Envelope`enter code here`
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <platformMsgs:documentInfo
            xmlns:platformMsgs="urn:messages_2015_1.platform.webservices.netsuite.com">
            <platformMsgs:nsId>WEBSERVICES_3479023</platformMsgs:nsId>
        </platformMsgs:documentInfo>
    </soapenv:Header>
    <soapenv:Body>
        <addListResponse
            xmlns="">
            <platformMsgs:writeResponseList
                xmlns:platformMsgs="urn:messages_2015_1.platform.webservices.netsuite.com">
                <platformCore:status isSuccess="true"
                    xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com"/>
                    <platformMsgs:writeResponse>
                        <platformCore:status isSuccess="false"
                            xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com">
                            <platformCore:statusDetail type="ERROR">
                                <platformCore:code>DUP_ENTITY</platformCore:code>
                                <platformCore:message>This entity already exists.</platformCore:message>
                            </platformCore:statusDetail>
                        </platformCore:status>
                    </platformMsgs:writeResponse>
                </platformMsgs:writeResponseList>
            </addListResponse>`enter code here`
        </soapenv:Body>
    </soapenv:Envelope>

任何人都可以帮我提供一些代码片段或示例来说明如何创建此 SOAP 消息吗?

我可以为您提供一些关于如何将 CXF POJO 格式与 Spring DSL 一起使用的想法。

Spring 上下文可能如下所示:

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

<!-- inbound Service endpoint -->

<camel-cxf:cxfEndpoint id="my-test-endpoint"
    address="/myTest" serviceName="mySrv:MyService"
    serviceClass="com.foo.myservice.MyServicePortPortType"
    endpointName="mySrv:MyServicePortPort"
    wsdlURL="classpath:myTest.wsdl"
    xmlns:mySrv="http://foo.com/myService/">
    <camel-cxf:properties>
        <spring:entry key="dataFormat" value="POJO" />
        ...
    </camel-cxf:properties>
</camel-cxf:cxfEndpoint>
...
<camel-spring:camelContext id="MyTestService_Ctx">
...
<camel-spring:route id="myTest-route">
   <camel-spring:from uri="cxf:bean:my-test-endpoint"
            id="inbound-myTest-service" />
   ...

很简单:

  1. 在 Spring 中,您将 cxf 端点定义为 {http://camel.apache.org/schema/cxf}cxfEndpoint bean,

  2. 然后您通过 uri 从 Camel 路由 fromto 组件引用它,看起来像:uri="cxf:bean:{endpoint bean id}"

那么你可能有两种情况: 情况 1。WSDL 将 Header 定义为消息的一部分。 Maven CXF 插件生成的服务后:

            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>

只需检查服务接口的外观。

情况 2:WSDL 没有自定义 Header 定义,您需要添加它。

两者都看我对另一个问题的回答: Unable to set SOAP Header while calling Web Service through Camel using dataFormat as POJO

P.S。如果您出于某些原因不需要显式 marshal/unmarshal JAXB POJO,则不需要其他任何东西。您不关心 SOAP 等。CXF 会根据您的 WSDL 定义为您完成。