Java 当dataFormat为message或CXF_message时,在Apache Camel中创建SOAP消息

Java 当dataFormat为message或CXF_message时,在Apache Camel中创建SOAP消息,java,web-services,soap,apache-camel,cxf,Java,Web Services,Soap,Apache Camel,Cxf,我想通过apachecamel调用一个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-i

我想通过apachecamel调用一个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>

WEBSERVICES_3479023
DUP_实体
此实体已存在。
`在这里输入代码`

有谁能帮我介绍一下如何创建此SOAP消息的代码片段或示例吗?

我可以向您介绍如何在Spring DSL中使用CXF POJO格式

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" />
   ...
只需检查服务接口的外观即可

案例2:WSDL没有定义自定义头,您需要添加它

对于这两个问题,请看我对另一个问题的回答:


另外,如果出于某些原因不需要显式封送/解封送JAXB POJO,则不需要其他任何东西。您不关心SOAP等。CXF将从您的WSDL定义中为您做到这一点。

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

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" />
   ...
只需检查服务接口的外观即可

案例2:WSDL没有定义自定义头,您需要添加它

对于这两个问题,请看我对另一个问题的回答:


另外,如果出于某些原因不需要显式封送/解封送JAXB POJO,则不需要其他任何东西。您不关心SOAP等。CXF将从您的WSDL定义中为您做到这一点。

为什么SOAP的“dataFormat是消息”?也许POJO或有效载荷是更好的选择?同样,对于CXF端点for SOAP,必须有一个WSDL,您不必担心自己创建完整的SOAP。CXF会处理好的。但如果您仍然需要创建完整的SOAP信封,您可以使用XQuery、XSLT、DOM builder。。。有很多选择,但都比使用JAXB的POJO更糟糕、更慢。实际上,我有一个太大的WSDL,无法从中创建POJO类。由于这个原因,我无法使用dataFormat POJO。我还需要添加SOAP头,但dataFormat负载只处理消息体(很可能)。所以dataFormat消息是唯一的选择。但是,使用这种数据格式,我找到了一些示例来读取传入的SOAP消息,而不是创建SOAP消息。这方面的任何例子都会非常有帮助。你走错了方向。你的两个假设都不正确。这不是“大WSDL”的情况。你必须使用它。自定义SOAP创建是个坏主意。使用PAYLOAD ot POJO格式,您可以创建标题,也可以创建所需的标题。我仍然推荐POJO,关注您的实际功能,而不是花时间重新设计一个weel。所有这些都已经存在:CXF、CAMEL、JAXB正是为了做您需要的事情,正确、快速、优化。因此,登记所有这些都是一项挑战。你能告诉我或者分享一些关于CXF_CAMEL_JAXB的链接吗?你很幸运:-)我有一个生成了大约10万个类的项目。关于CXF_CAMEL_JAXB没有任何具体的内容。现在我在打电话。。。稍后我会看一看,并尝试给你们举一个例子…为什么“数据格式是消息“为了肥皂?也许POJO或有效载荷是更好的选择?同样,对于CXF端点for SOAP,必须有一个WSDL,您不必担心自己创建完整的SOAP。CXF会处理好的。但如果您仍然需要创建完整的SOAP信封,您可以使用XQuery、XSLT、DOM builder。。。有很多选择,但都比使用JAXB的POJO更糟糕、更慢。实际上,我有一个太大的WSDL,无法从中创建POJO类。由于这个原因,我无法使用dataFormat POJO。我还需要添加SOAP头,但dataFormat负载只处理消息体(很可能)。所以dataFormat消息是唯一的选择。但是,使用这种数据格式,我找到了一些示例来读取传入的SOAP消息,而不是创建SOAP消息。这方面的任何例子都会非常有帮助。你走错了方向。你的两个假设都不正确。这不是“大WSDL”的情况。你必须使用它。自定义SOAP创建是个坏主意。使用PAYLOAD ot POJO格式,您可以创建标题,也可以创建所需的标题。我仍然推荐POJO,关注您的实际功能,而不是花时间重新设计一个weel。所有这些都已经存在:CXF、CAMEL、JAXB正是为了做您需要的事情,正确、快速、优化。因此,登记所有这些都是一项挑战。你能告诉我或者分享一些关于CXF_CAMEL_JAXB的链接吗?你很幸运:-)我有一个生成了大约10万个类的项目。关于CXF_CAMEL_JAXB没有任何具体的内容。现在我在打电话。。。稍后我会看一看并试着给你举个例子…非常感谢瓦迪姆!非常感谢瓦迪姆!