2017-03-08 3 views
0

Ich versuche, ein JSONPayload mit einem dynamisch generierten json-eval zu verarbeiten, um ein Hotelobjekt auszuwählen. Unten erwähntes direktes json-eval funktioniert gut.Dynamische json-eval-Ausdrücke in WSO2 ESB 5

Direkt json-eval Ausdruck:

json-eval($.content[?(@.hotelcode=='ALE1_LON')]) 

Ich habe wie Optionen ausprobiert Beow aber kein Glück gehabt noch.

VERSUCH 1:

<property name="htlCode" scope="default" type="STRING" value="'ALE1_LON'"/> 
<property expression="fn:concat('$.content[?(@.hotelcode==',get-property('htlCode'),')]')" name="xpathExpr" scope="default" type="STRING"/> 
<property expression="json-eval({$ctx:xpathExpr})" name="hotelContet" scope="default" type="STRING"/> 

Dies verwendet die "{$ctx:xpathExpr}" als JSON-Pfad statt "$.content[?(@.hotelcode=='ALE1_LON')]".

VERSUCH 2:

<property name="htlCode" scope="default" type="STRING" value="'ALE1_LON'"/> 
<property expression="fn:concat('json-eval($.content[?(@.hotelcode==',get-property('htlCode'),')])')" name="hotelContet" scope="default" type="STRING"/> 

Dieses stores "json-eval($.content[?(@.hotelcode=='ALE1_LON')])" auf die hotelContet Eigenschaft ohne es eveluating.

VERSUCH 3:

<property name="htlCode" scope="default" type="STRING" value="'ALE1_LON'"/> 
<property expression="json-eval($.content[?(@.hotelcode=={get-property('htlCode')})])" name="hotelContet" scope="default" type="STRING"/> 

Dies verwendet die "$.content[?(@.hotelcode=={get-property('htlCode')})]" als JSON-Pfad statt "$.content[?(@.hotelcode=='ALE1_LON')]".

VERSUCH 4:

<property name="htlCode" scope="default" type="STRING" value="'ALE1_LON'"/> 
<property expression="json-eval($.content[?(@.hotelcode=={$ctx.htlCode})])" name="hotelContet" scope="default" type="STRING"/> 

Dies verwendet die "$.content[?(@.hotelcode=={$ctx.htlCode})]" als JSON-Pfad statt "$.content[?(@.hotelcode=='ALE1_LON')]".

Json Nutzlast:

{ 
    "_id":"INV27_1112", 
    "_rev":"5-876038bf65752ce4505e50baea6d5581", 
    "content":[ 
     { 
      "hotelcode":"AMB3_LON", 
      "hotelname":"Ambassadors Bloomsbury" 
     }, 
     { 
      "hotelcode":"ALE1_LON", 
      "hotelname":"Alexandra" 
     }, 
     { 
      "hotelcode":"ALO_LON", 
      "hotelname":"Aloft London Excel" 
     } 
    ] 
} 

Hinweis: Ich weiß, dass dies mit Script/Klasse Vermittler erfolgen. Aber ich suche nach einer Lösung innerhalb der json-eval. Und besser, wenn ich auf JSONPath statt auf XPath beschränken kann.

Momentan verwalte ich mich selbst unter Verwendung von unten wie Ansatz über JSON.

<property name="htlCode" scope="default" type="STRING" value="'ALE1_LON'"/> 
<property expression="fn:concat('//content[hotelcode=',$ctx:htlCode,']')" name="hotelContentExpr" scope="default" type="STRING"/> 
<property expression="evaluate($ctx:hotelContentExpr)" name="hotelContent" scope="default" type="STRING"/> 
  • WSO2 ESB Version: 5.0.0

Antwort

0

diese Lösung Testen Sie Ihr Problem

<?xml version="1.0" encoding="UTF-8"?> 
<proxy xmlns="http://ws.apache.org/ns/synapse" 
     name="JsonDynamicExpression" 
     startOnLoad="true" 
     statistics="disable" 
     trace="disable" 
     transports="http,https"> 
    <target> 
     <inSequence> 
     <payloadFactory media-type="json"> 
      <format>{ 
    "_id":"INV27_1112", 
    "_rev":"5-876038bf65752ce4505e50baea6d5581", 
    "content":[ 
     { 
      "hotelcode":"AMB3_LON", 
      "hotelname":"Ambassadors Bloomsbury" 
     }, 
     { 
      "hotelcode":"ALE1_LON", 
      "hotelname":"Alexandra" 
     }, 
     { 
      "hotelcode":"ALO_LON", 
      "hotelname":"Aloft London Excel" 
     } 
    ] 
}</format> 
      <args/> 
     </payloadFactory> 
     <property name="htlCode" scope="default" type="STRING" value="ALO_LON"/> 
     <property expression="fn:concat('//content[hotelcode=','&#34;',get-property('htlCode'),'&#34;',']')" 
        name="hotelContentExpr" 
        scope="default" 
        type="STRING"/> 
     <enrich> 
      <source clone="true" xpath="evaluate(get-property('hotelContentExpr'))"/> 
      <target type="body"/> 
     </enrich> 
     <log> 
      <property expression="$body" name="Cuerpo////////////////////////////"/> 
     </log> 
     <loopback/> 
     </inSequence> 
     <outSequence> 
     <send/> 
     </outSequence> 
    </target> 
    <description/> 
</proxy> 
+0

für die Antwort Danke zu lösen. Ja, ich kann es mit dem XPath über JSON tun, wie ich im letzten Teil meiner Frage erwähnt habe. Aber ich freue mich darauf, JSONPath in der json-eval-Funktion einzusetzen. – namalfernandolk