java - 当 dataFormat 为 MESSAGE 或 CXF_MESSAGE 时,在 Apache Camel 中创建 SOAP 消息

标签 java web-services soap apache-camel cxf

我想通过 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>

只需检查服务接口(interface)是什么样子的。

情况 2:WSDL 未定义自定义 header ,您需要添加它。

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

附注如果由于某些原因您不需要显式编码/取消编码 JAXB POJO,则不需要其他任何内容。您不关心 SOAP 等。CXF 会根据您的 WSDL 定义为您完成这些工作。

关于java - 当 dataFormat 为 MESSAGE 或 CXF_MESSAGE 时,在 Apache Camel 中创建 SOAP 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43386400/

相关文章:

node.js - GraphQL 的 SOAP 转换

java - Java中不使用libpcap进行网络数据包捕获

java - 如何在安装时在 Android 手机的主屏幕上创建应用程序快捷方式

java - 如何从 Callable 返回中期结果?

web-services - Visual Studio 2013 使用有效的 wsdl 文件创建服务数据源时出错

java - 如何运行 MULE RMI?

java - 如何使 java 准备语句像大查询的查询或如何在大查询中转义参数

asp.net - 需要网络服务的帮助

java - 浏览器不显示任何 XML 标签树

java - Wsdl 到 Java OUT 参数