我想通过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" />
...
很简单:
在 Spring 中,您将 cxf 端点定义为 Bean
{http://camel.apache.org/schema/cxf}cxfEndpoint
,然后你从骆驼路由
from
或to
URI 组件对它的引用,如下所示:uri="cxf:bean:{endpoint bean id}"
那么你可能有两种情况: 案例 1.WSDL 将标头定义为消息的一部分。 Maven CXF 插件生成的服务后:
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
只需检查服务接口的外观。
情况 2:WSDL 没有定义自定义标头,您需要添加它。
对于两者,请看我对另一个问题的回答: 使用 dataFormat 作为 POJO 通过 Camel 调用 Web 服务时无法设置 SOAP 标头
附言如果您出于某些原因不需要,明确封送/取消编组 JAXB POJO,您不需要其他任何东西。你不关心 SOAP 等。CXF 会从你的 WSDL 定义中为你做这件事。