簡體   English   中英

當dataFormat為MESSAGE或CXF_MESSAGE時,在Apache Camel中創建SOAP消息

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

我想通過Apache Camel調用Web服務,dataFormat是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消息嗎?

我可以為您提供有關如何在Spring DSL中使用CXF POJO格式的一些想法。

Spring Context可能如下所示:

<?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. 那么你的參考,將其從駱駝航線fromto由URI組件,它看起來像: uri="cxf:bean:{endpoint bean id}"

然后您可能有兩種情況:情況1. WSDL將Header定義為消息的一部分。 由Maven CXF插件生成的服務之后:

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

只需檢查Service Interface的外觀。

情況2:WSDL沒有定義自定義標頭,您需要添加它。

看看我對另一個問題的回答: 無法在使用dataFormat作為POJO通過Camel調用Web Service時設置SOAP Header

PS如果由於某些原因不需要,明確編組/解組JAXB POJO,則不需要任何其他內容。 您不關心SOAP等.CXF將從您的WSDL定義中為您完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM