在 mulesoft 中将 soap 消息插入数据库

insert soap message to database in mulesoft

我需要从 SOAP 获取消息并将它们保存到 Mule 中的 MySQL 数据库。

我使用设置变量来获取我想要的文本:

#[xpath('//tra:sayHi/ID/text()').getText()]

然后在数据库组件中,我使用这个:

insert into account(id,name,REF1,REF2) values(#[flowVars.ID],#[flowVars.name],null,null)

当我在 SoapUI 中测试时,我收到以下错误消息:

org.apache.cxf.interceptor.Fault: 找不到将 "SimpleDataType{type=java.lang.Integer, mimeType='text/xml'}" 转换为 "SimpleDataType{type=javax.xml.stream.XMLStreamReader, mimeType='/'}" 的转换器。

我的 XML 是:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd">
<mulexml:namespace-manager>
    <mulexml:namespace prefix="soapenv"
                       uri="http://schemas.xmlsoap.org/soap/envelope/"/>
    <mulexml:namespace prefix="tra"
                       uri="http://training/"/>
</mulexml:namespace-manager>
    <db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="admin" password="pontiac" database="sqwarepeg" doc:name="MySQL Configuration"/>
    <flow name="testFlow1" doc:name="testFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP"/>
        <cxf:proxy-service port="SF2DBPort" namespace="http://training/" service="SF2DBService" payload="body" wsdlLocation="/src/main/resources/SF2DB.wsdl" doc:name="CXF"/>
        <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
        <set-variable variableName="name" value="#[xpath('//tra:sayHi/name/text()').getText()]" doc:name="Set name"/>
        <set-variable variableName="ID" value="#[xpath('//tra:sayHi/ID/text()').getText()]" doc:name="set ID"/>
        <db:insert config-ref="MySQL_Configuration" doc:name="Database">
            <db:parameterized-query><![CDATA[insert into account(id,name,REF1,REF2) values(#[flowVars.ID],#[flowVars.name],null,null)]]></db:parameterized-query>
        </db:insert>
        <logger message="The reply &quot;#[flowVars.ID]&quot; means &quot;Customer ID&quot;" level="INFO" doc:name="Logger"/>
    </flow>
</mule>

当我查看数据库时,记录已被插入。我只是不知道为什么会有错误信息。感谢您的帮助。

您的流程中缺少重要的一点:没有 set-payload 消息处理器来设置 cxf:proxy-service 将序列化为有效 SOAP 响应的响应对象。