2017-03-24 10 views
0

enter image description hereミュールESB Dataweaveは、私がBigcommerceのAPIからの2つのXMLストリームを持つ1つのXML出力を作成

、2つのXMLストリームを消費します。 1つのXMLストリームに注文情報が含まれ、もう1つのストリームには広告申込情報(商品)が含まれます。私は、2つのXMLストリームをdataweaveと組み合わせて、出力として1つのxmlドキュメントを取得しようとしています。添付のように私は流れを実行すると、私はすべての製品が、製品の1つだけのセット(最初のセット)

を得ることはありません=====================ここで=============================================

order.xmlストリームである:ここで

<?xml version="1.0"?> 
<order> 
<id>40144</id> 
<date>2016-05-01</date> 
</order> 

は、製品の流れは、(ここでは複数の製品を持つことになります注意してください)です。

<?xml version="1.0"?> 
<products> 
<product> 
<id>1234</id> 
<order_id>40144</order_id> 
<product_id>12345</product_id> 
<order_address_id>12</order_address_id> 
<name>Widget</name> 
</product> 
<product> 
<id>53245</id> 
<order_id>40144</order_id> 
<product_id>56435</product_id> 
<order_address_id>12</order_address_id> 
<name>Super Widget</name> 
</product> 
</products> 

ここミュールフローの設定は、(システム変数です変更)

<?xml version="1.0" encoding="UTF-8"?> 
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 
xmlns:imaps="http://www.mulesoft.org/schema/mule/imaps" 
xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" 
xmlns:http="http://www.mulesoft.org/schema/mule/http" 
xmlns:imap="http://www.mulesoft.org/schema/mule/imap" 
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" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/xml 
http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd 
http://www.mulesoft.org/schema/mule/imaps 
http://www.mulesoft.org/schema/mule/imaps/current/mule-imaps.xsd 
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/http 
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/imap 
http://www.mulesoft.org/schema/mule/imap/current/mule-imap.xsd 
http://www.mulesoft.org/schema/mule/objectstore 
http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd 
http://www.mulesoft.org/schema/mule/ee/dw 
http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd"> 
<imaps:connector name="IMAP" backupFolder="backup" validateConnections="true" backupEnabled="true" checkFrequency="900" doc:name="IMAP"/> 
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="myserver.net" port="443" doc:name="HTTP Request Configuration"> 
    <http:basic-authentication username="user" password="password"/> 
</http:request-config> 
<flow name="scattgathFlow"> 
    <imaps:inbound-endpoint host="192.168.1.1" port="993" responseTimeout="10000" user="user" password="password" doc:name="IMAP" connector-ref="IMAP"/> 
    <set-variable doc:name="Variable" value="#[message.inboundProperties.subject.replaceAll('[^0-9\\-]', '')]" variableName="email_subj"/> 
    <http:request config-ref="HTTP_Request_Configuration" path="/api/v2/orders/#[email_subj]" method="GET" doc:name="HTTP" metadata:id="72233863-af08-4d0d-9a75-5b726b6d117e"> 
    </http:request> 
    <!-- Sub flow to retrieve products --> 
    <flow-ref name="payload1" doc:name="payload1" metadata:id="896da22a-11f4-4a80-9b38-85507261b002"/> 
     <dw:transform-message metadata:id="8c4bb84a-74f8-4761-8f56-859dcf50473c" doc:name="Transform Message"> 
      <dw:input-payload doc:sample="products.xml"/> 
      <dw:input-outbound-property propertyName="MULE_ENCODING"/> 
      <dw:set-payload> 
    <![CDATA[%dw 1.0 
    %output application/xml 
    %input payload application/xml 
    --- 
    { 
    newxml: { 
     billto: payload.order.customer_id as :string, 
     shipping: payload.order.status, 
    products: { 
     productID: payload.products.product.product_id, 
     sku: payload.products.product.sku, 
     name: payload.products.product.name 
    } 
} 
}]]></dw:set-payload> 
</dw:transform-message> 
<logger message="#[message.payload]" level="INFO" doc:name="Logger"/> 
</flow> 
<sub-flow name="payload1" > 
    <http:request config-ref="HTTP_Request_Configuration" path="/api/v2/orders/#[email_subj]/products.xml" method="GET" doc:name="HTTP" metadata:id="4806e0ff-68f0-4295-baff-d65b07ae5190"/> 
</sub-flow> 
</mule> 
+0

あなたの質問にいくつかの発言...それは実際の質問が含まれていないと、あなたの例では、あなたのdataweaveでペイロードと一致していません。あなたの質問を改善すれば、他の人があなたの問題の解決策を見つけ出すことができます。 – Yevgeniy

答えて

0

あなたはpayload.products.*productを反復しなければなりません。これは、それがどのように見えるかです:あなたの質問から<products>...</products>を使用した場合

%dw 1.0 
%output application/xml 
%input payload application/xml 
--- 
newxml: { 
    products: { 
     (payload.products.*product map { 
      product: { 
       productID: $.product_id, 
       name: $.name 
      } 
     }) 
    } 
} 

出力は次のようになります。

<?xml version='1.0' encoding='UTF-8'?> 
<newxml> 
    <products> 
    <product> 
     <productID>12345</productID> 
     <name>Widget</name> 
    </product> 
    <product> 
     <productID>56435</productID> 
     <name>Super Widget</name> 
    </product> 
    </products> 
</newxml> 

は、ルックhereを取ると、あなたはdataweaveを含むと変換のための多くの例があります例はmapです。

関連する問題