Tazz
Tazz

Reputation: 89

wso2 Return property value from insequence

I'm creating an wso2 that call an endpoint and then filter the response just to send back one field, but for some reason the esb answer with all the json

I have something like that:

<resource methods="POST" uri-template="/ESB">
    <inSequence>
            <call description="">
                <endpoint key="CountryEP"/>
            </call>
            <property description="" expression="json-eval($.zones[0].countryCode)" name="uri.var.countryCode" scope="default" type="STRING"/>
            <log description="">
                <property expression="fn:concat('countryCode ', get-property('uri.var.countryCode')) " name="property_name"/>
            </log>
            <send buildmessage="true" description=""/>
    </inSequence>
    <outSequence/>
    <faultSequence/>
</resource>

And my Endpoint

<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="CountryEP" xmlns="http://ws.apache.org/ns/synapse">
    <http method="get" trace="enable" uri-template="http://api.timezonedb.com/v2/list-time-zone?key=6HW6EJUENX9T&amp;format=json&amp;country={uri.var.country}"/>
</endpoint>

So as you can see above, i send a parameter to the API, and the API answers with a json, then i try to parse just one field (using the property) and i have the correct value:

INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:97744789-8c88-41ff-9475-870761016834, Direction: request, property_name = countryCode CA

But i can't return just that value, the esb return all json... ideas?

Thanks in advance,

EDIT: also tried with RESPONSE attribute on the property mediator

Upvotes: 1

Views: 382

Answers (1)

Jorge Infante Osorio
Jorge Infante Osorio

Reputation: 2153

Try something like this:

        <call description="">
            <endpoint key="CountryEP"/>
        </call>
        <property description="" expression="json-eval($.zones[0].countryCode)" name="uri.var.countryCode" scope="default" type="STRING"/>
        <log description="">
            <property expression="fn:concat('countryCode ', get-property('uri.var.countryCode')) " name="property_name"/>
        </log>
   <payloadFactory media-type="json">
        <format>{ "Country Code": $1}</format>
           <args>
             <arg expression="$.zones[0].countryCode.text" evaluator="json"/>
           </args>
   </payloadFactory>
   <property name="messageType" value="application/json" scope="axis2"/>
   <respond/>

Upvotes: 2

Related Questions