0

When I use the 'Body to Parameter Map' transformer, I can get the parameter in URL, but I cannot get the content. When I use the 'JSON to Object' transformer, I can only get the content, but the parameter is lost in the payload. How can I get both of them? The configuration as follows:

<flow name="zhicall-httpFlow" doc:name="zhicall-httpFlow">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081"  path="test" encoding="UTF-8" doc:name="InHTTP" mimeType="application/json"/>
    <http:body-to-parameter-map-transformer doc:name="Body to Parameter Map"/>
    <json:json-to-object-transformer returnClass="java.util.Map" mimeType="application/json" doc:name="JSON to Object"/>
   <!--  <http:body-to-parameter-map-transformer ignoreBadInput="true" doc:name="Body to Parameter Map" encoding="UTF-8" mimeType="application/json"/> -->
    <!-- <set-property doc:name="Content-Type Property" propertyName="Content-Type" value="application/json"/> -->
    <custom-transformer encoding="UTF-8" class="com.zhicall.esb.transformer.MyTransformer" doc:name="Java" mimeType="application/json"/>
</flow>
4

1 に答える 1

2

提供されたフローに従って、最初のトランスフォーマーがペイロードを変換します。そのため、処理が 2 番目のトランスフォーマー (json-to-object) に到達するまでに、元のペイロードは存在しなくなります。

したがって、元のペイロードをフロー変数として保存してから、トランスフォーマーを適用してみてください。

元のペイロードがフロー変数として保存されるようにフローを変更しました。http トランスフォーマーの後、変換されたペイロードはフロー変数として保存され、ペイロードは元の入力にリセットされます。次に、2 番目のトランスフォーマーがこの元のペイロードに作用し、それを変換します。このようにして、オリジナルは両方のトランスフォーマーによって独立して変換されます。そして、1 つはフロー変数として、もう 1 つは json トランスフォーマーの後のペイロードとして、両方の変換された出力があります。

<flow name="zhicall-httpFlow" doc:name="zhicall-httpFlow">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081"  path="test" encoding="UTF-8" doc:name="InHTTP" mimeType="application/json"/>

    <set-variable variableName="originalInput" value="#[payload]" />

    <http:body-to-parameter-map-transformer doc:name="Body to Parameter Map"/>

    <set-variable value="#[payload]" variableName="httpParamMap" />
    <set-payload value="#[flowVars['originalInput']]"></set-payload>

    <json:json-to-object-transformer returnClass="java.util.Map" mimeType="application/json" doc:name="JSON to Object"/>
   <!--  <http:body-to-parameter-map-transformer ignoreBadInput="true" doc:name="Body to Parameter Map" encoding="UTF-8" mimeType="application/json"/> -->
    <!-- <set-property doc:name="Content-Type Property" propertyName="Content-Type" value="application/json"/> -->
    <custom-transformer encoding="UTF-8" class="com.zhicall.esb.transformer.MyTransformer" doc:name="Java" mimeType="application/json"/>
</flow>

お役に立てれば。

于 2013-05-29T14:05:51.690 に答える