首页 > 解决方案 > 调用 SOAP 服务的 MuleSoft REST API

问题描述

我调用一个 SOAP 服务,它使用 REST 服务从数据库调用数据,当我调用 GET 函数时,它返回所有空值,并且 Anypoint Studio 控制台返回这个答案:

信息 2020-11-19 08:51:40,897 [[MuleRuntime].uber.03: [userstory12_soap].getCustomerByLastName.BLOCKING @393df87f] [处理器:; 事件:bb2e3fd0-2a76-11eb-9a6c-86c5a63076bd] org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean:从类 org.mule 创建服务 {http://client.internal.soap.mule.org/}ProxyService .soap.internal.client.CxfClientFactory$ProxyService

我不知道为什么它不起作用,因为我将我的流程与同事的流程进行了比较,它们完全相同(除了变量名称的一些细微变化)。解决这个问题的任何输入都会很棒!在下面找到我的流程和 XML 的屏幕截图

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<mule xmlns:wsc="http://www.mulesoft.org/schema/mule/wsc" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit-soap="http://www.mulesoft.org/schema/mule/apikit-soap" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.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/apikit-soap http://www.mulesoft.org/schema/mule/apikit-soap/current/mule-apikit-soap.xsd http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.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/wsc http://www.mulesoft.org/schema/mule/wsc/current/mule-wsc.xsd">
    <http:listener-config name="api-httpListenerConfig">
        <http:listener-connection host="0.0.0.0" port="8087"/>
    </http:listener-config>
    <apikit-soap:config httpStatusVarName="httpStatus" name="soapkit-config" port="us12SOAP" service="us12" wsdlLocation="SOAPUS12.wsdl"/>
    <db:config name="Database_Config" doc:name="Database Config" doc:id="176ab101-fa7d-4ee9-aca3-5c0bf9fe8c77" >
        <db:mssql-connection host="localhost" port="1433" user="sa" password="Gecegu0722@" databaseName="EAIS_Training" />
    </db:config>
    <wsc:config name="Web_Service_Consumer_Config" doc:name="Web Service Consumer Config" doc:id="0665000a-d19d-4801-a118-2315417e9290" >
        <wsc:connection wsdlLocation="api\SOAPUS12.wsdl" service="us12" port="us12SOAP" address="http://localhost:8087/us12/us12SOAP/" >
            <wsc:web-service-security actor="http://schemas.xmlsoap.org/soap/actor/next" />
        </wsc:connection>
    </wsc:config>
    <flow name="api-main">
        <http:listener config-ref="api-httpListenerConfig" path="/us12/us12SOAP">
            <http:response statusCode="#[attributes.protocolHeaders.httpStatus default 200]">
                <http:body>#[payload]</http:body>
                <http:headers>#[attributes.protocolHeaders default {}]</http:headers>
            </http:response>
            <http:error-response statusCode="#[attributes.protocolHeaders.httpStatus default 500]">
                <http:body>#[payload]</http:body>
                <http:headers>#[attributes.protocolHeaders default {}]</http:headers>
            </http:error-response>
        </http:listener>
        <apikit-soap:router config-ref="soapkit-config">
            <apikit-soap:attributes><![CDATA[#[%dw 2.0
              output application/java
              ---
              {
                  headers: attributes.headers,
                  method: attributes.method,
                  queryString: attributes.queryString
            }]]]></apikit-soap:attributes>
        </apikit-soap:router>
    </flow>
    <flow name="getCustomerDB:\soapkit-config">
        <db:select doc:name="Select" doc:id="75cdc0ea-04b6-429f-a022-9152c14d1dd9" config-ref="Database_Config">
            <db:sql ><![CDATA[SELECT * FROM customer_aux WHERE last_name = :last_name]]></db:sql>
            <db:input-parameters ><![CDATA[#[output application/java
ns ns0 http://www.example.org/us12/
---
{
    last_name: payload.body.ns0#getCustomerDB.last_name
}]]]></db:input-parameters>
        </db:select>
        <ee:transform>
            <ee:message>
                <ee:set-payload><![CDATA[output application/java
ns ns0 http://www.example.org/us12/
---
{
    body: {
        ns0#getCustomerDBResponse: {
            id: payload.id,
            first_name: payload.first_name,
            last_name: payload.last_name,
            birth_date: payload.age,
            street: payload.street,
            city: payload.city,
            country: payload.country,
            phone: payload.phone
        }
    } write "application/xml"
}
]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="getCustomerByLastName" doc:id="0b351b65-af46-414b-9ac6-ccf02812e2d2" >
        <http:listener doc:name="Listener" doc:id="72239ecd-26b9-4a81-90a0-6a486e396eb8" config-ref="api-httpListenerConfig" path="/getCustomerByLastName"/>
        <wsc:consume operation="getCustomerDB" doc:name="Consume" doc:id="d29f381b-d054-4a03-8255-f953ce6996ed" config-ref="Web_Service_Consumer_Config">
            <wsc:message >
                <wsc:body ><![CDATA[#[output application/xml
ns ns0 http://www.example.org/us12
---
{
    ns0#getCustomerDB: {
        last_name: attributes.queryParams.last_name
    }
}]]]></wsc:body>
            </wsc:message>
        </wsc:consume>
        <ee:transform doc:name="Transform Message" doc:id="8a2b6eb1-d798-4f73-a25b-a74f54eeb8ce" >
            <ee:message >
                <ee:set-payload ><![CDATA[output application/json
ns ns0 http://www.example.org/us12/
import * from dw::core::Strings
---
{
    id: payload.body.ns0#getCustomerDBResponse.id default 0,
    firstName: capitalize(payload.body.ns0#getCustomerDBResponse.first_name) default "",
    lastName: capitalize(payload.body.ns0#getCustomerDBResponse.last_name) default "",
    age: payload.body.ns0#getCustomerDBResponse.birth_date default "",
    street: capitalize(payload.body.ns0#getCustomerDBResponse.street) default "",
    city: capitalize(payload.body.ns0#getCustomerDBResponse.city) default "",
    country: capitalize(payload.body.ns0#getCustomerDBResponse.country) default "",
    phone: payload.body.ns0#getCustomerDBResponse.phone default 0
}

]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
</mule>

在此处输入图像描述

在此处输入图像描述

标签: restsoapmuleanypoint-studio

解决方案


推荐阅读