Hi Udara,

I tried a similar scenario using the following main sequence.

<sequence xmlns="http://ws.apache.org/ns/synapse"; name="main">
   <in></in>
   <out>
      <payloadFactory media-type="json">
         <format>{     "stock_code" : "$1",     "stock_price" :
"$2"}</format>
         <args>
            <arg xmlns:ns="http://org.apache.synapse/xsd"; xmlns:m0="
http://services.samples/xsd"; expression="//m0:symbol" evaluator="xml"></arg>
            <arg xmlns:ns="http://org.apache.synapse/xsd"; xmlns:m0="
http://services.samples/xsd"; expression="//m0:last" evaluator="xml"></arg>
         </args>
      </payloadFactory>
      <property name="messageType" value="application/json" scope="axis2"
type="STRING"></property>
   </out>
   <send></send>
</sequence>

Assuming, you are using the sample stockquote client, I sent a request as
below :
ant stockquote -Daddurl=
http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=
http://localhost:8280/ -Dmode=quote -Dsymbol=WSO2

The response is received back on the client with an error (due to json
conversion) as below :

[java] java.lang.Exception: Unexpected response :
<stock_code>WSO2</stock_code>
     [java]     at
samples.common.StockQuoteHandler.parseStandardQuoteResponse(Unknown Source)
     [java]     at samples.userguide.StockQuoteClient.printResult(Unknown
Source)
     [java]     at samples.userguide.StockQuoteClient.executeClient(Unknown
Source)
     [java]     at samples.userguide.StockQuoteClient.main(Unknown Source)

Is this what you are looking for? The response in this case is successfully
received on the client. The client not being able to parse the response is
a different question which will have to be implemented.


Thanks,

Maheeka Jayasuriya
Software Engineer
Mobile : +94777750661

On Tue, Feb 3, 2015 at 2:42 PM, Udara Liyanage <[email protected]> wrote:

> Hi Dilan,
>
> First payloadFactory in out sequence is not in the proxy, it was pasted
> mistakenly. Response from backend is soap. I just wanted to send back a
> dummy json response to the client. That's why I used a payload factory.
> On 26 Jan 2015 10:06, "Dilan Udara Ariyaratne" <[email protected]> wrote:
>
>> Hi Udara,
>>
>> What is the type of response received by ESB from the back-end? Is it XML
>> or JSON?
>> Also if your requirement was to get a JSON in return, what was the
>> purpose of using two payload factories within the out sequence?
>> Shouldn't it be only one payload factory mediator of media-type="json"?
>>
>> Regards,
>> Dilan.
>>
>>
>>
>> *Dilan U. Ariyaratne*
>> Software Engineer
>> WSO2 Inc. <http://wso2.com/>
>> Mobile: +94775149066
>> lean . enterprise . middleware
>>
>> On Fri, Jan 23, 2015 at 4:56 PM, Udara Liyanage <[email protected]> wrote:
>>
>>> Hi,
>>>
>>> I tried below sequence to get a JSON response back. However no response
>>> received to the client. I tried having Respond mediator instead of Send in
>>> out sequence. What is missing which prevents response is being received.
>>>
>>>
>>>    1. <sequence name="main">
>>>    2.       <in>
>>>    3.          <log level="custom">
>>>    4.             <property name="text" value="**inside main **"/>
>>>    5.          </log>
>>>    6.          <payloadFactory media-type="xml">
>>>    7.             <format>
>>>    8.                <m:getQuote xmlns:m="http://services.samples";>
>>>    9.                   <m:request>
>>>    10.                      <m:symbol>IBM</m:symbol>
>>>    11.                   </m:request>
>>>    12.                </m:getQuote>
>>>    13.             </format>
>>>    14.             <args/>
>>>    15.          </payloadFactory>
>>>    16.          <send>
>>>    17.             <endpoint name="secure">               <address uri="
>>>    http://localhost:9000/axis2/services/SecureStockQuoteService"/>
>>>    18.             </endpoint>
>>>    19.          </send>
>>>    20.       </in>
>>>    21.       <out>
>>>    22.          <log level="custom">
>>>    23.             <property name="text" value="**inside out **"/>
>>>    24.          </log>
>>>    25.          <payloadFactory media-type="xml">
>>>    26.             <format>
>>>    27.                <m:getQuote xmlns:m="http://services.samples";>
>>>    28.                   <m:request>
>>>    29.                      <m:symbol>$</m:symbol>
>>>    30.                   </m:request>
>>>    31.                </m:getQuote>
>>>    32.             </format>
>>>    33.             <args>
>>>    34.                <arg xmlns:m0="http://services.samples";
>>>    35.                    evaluator="xml"
>>>    36.                    expression="//m0:Code"/>
>>>    37.             </args>
>>>    38.          </payloadFactory>
>>>    39.          <payloadFactory media-type="json">
>>>    40.             <format>
>>>    41.                 {
>>>    42.     "coordinates": null,
>>>    43.     "created_at": "Fri Jun 24 17:43:26 +0000 2011",
>>>    44.     "truncated": false,
>>>    45.     "favorited": false,
>>>    46.
>>>    47.     "entities": {
>>>    48.         "urls": [
>>>    49.
>>>    50.         ],
>>>    51.         "hashtags": [
>>>    52.             {
>>>    53.                 "indices": [
>>>    54.                     35,
>>>    55.                     45
>>>    56.                 ]
>>>    57.             }
>>>    58.         ],
>>>    59.         "user_mentions": [
>>>    60.         ]
>>>    61.     }
>>>    62. }
>>>    63.             </format>
>>>    64.             <args/>
>>>    65.          </payloadFactory>      <property name="messageType"
>>>    value="application/json" scope="axis2"/>
>>>    66.          <send/>
>>>    67.       </out>
>>>
>>>
>>> --
>>>
>>> Udara Liyanage
>>> Software Engineer
>>> WSO2, Inc.: http://wso2.com
>>> lean. enterprise. middleware
>>>
>>> web: http://udaraliyanage.wordpress.com
>>> phone: +94 71 443 6897
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to