Thanks Sudharma for reply,

As I mentioned* "modifyAgRes.xml" *is a mock of backend service. I cannot
change the backend service. Whatever modifications I have to do is only to
main xml* "**addChild.xml**".*
Plus I think we cannot use payloadFactory this way , as number of elements
coming in input array are not fixed.It can be any number.

One more thing, Enrich mediator is behaving weirdly. For editing the
property of type "OM",
suppose property like this

<property expression="//jsonObject" name="firstResponse" scope="default"
type="OM"/>

use of below xpath sometimes works and sometimes not

*xpath="$ctx:firstResponse"*

but mostly (intermitently) it gives below error

*EnrichMediator} -  Invalid Target object to be enrich. *

I am getting the similar error , even for the xpath you have suggested.

* xpath="get-property('firstResponse')/children*

With Regards,
Aditya




On Thu, Jul 20, 2017 at 3:31 PM, Sudharma Subasinghe <[email protected]>
wrote:

> Hi,
>
> Try using PayloadFactory mediator as below. Change your configs as
> following.
>
> *modifyAgRes.xml*
>
> <case regex="2">
>         <payloadFactory media-type="xml">
>                   <format>
>             <jsonObject xmlns="">
>             <id>$1</id>
>                      <children xmlns="">
>                         <id>$1</id>
>                         <make>$2</make>
>                         <name>Car</name>
>                         <model>Tmaze</model>
>                      </children>
>             </jsonObject>
>                   </format>
>                   <args>
>                      <arg evaluator="xml" expression="//jsonObject/id"/>
>                      <arg evaluator="xml" expression="//jsonObject/make"/>
>                   </args>
>                </payloadFactory>
>     </case>
>     <case regex="3">
>         <payloadFactory media-type="xml">
>                   <format>
>             <jsonObject xmlns="">
>             <id>$1</id>
>                      <children xmlns="">
>                         <id>$1</id>
>                         <make>$2</make>
>                         <name>Mobile</name>
>                         <model>S8</model>
>                      </children>
>             </jsonObject>
>                   </format>
>                   <args>
>                      <arg evaluator="xml" expression="//jsonObject/id"/>
>                      <arg evaluator="xml" expression="//jsonObject/make"/>
>                   </args>
>                </payloadFactory>
>     </case>
>     ----------------------------------------------------------
>          <!--enrich>
>             <source clone="true" xpath="//jsonObject"/>
>             <target type="body"/>
>          </enrich-->
>
>
>
> *addChild.xml*<property name="aggrementResponse"
>                                      expression="//jsonObject/children"
>                                      scope="default"
>                                      type="OM"/>
>
> <enrich>
>              <source xpath="get-property('aggrementResponse')"/>
>               <target action="sibling" xpath="get-property('
> firstResponse')/children"/>
> </enrich>
>
> Thanks
> Sudharma
>
> On Thu, Jul 20, 2017 at 2:03 AM, aditya shivankar <
> [email protected]> wrote:
>
>>  Adding responses as elements ,to an array in json response
>>
>> Input request :
>>
>> [
>> {
>>    "id" : "1",
>> "make" : "TAHB",
>> "children":[
>> {
>> "kid":"1"
>> },
>> {
>> "kid":"2"
>> }
>> ]
>> },
>> {
>> "id" : "2",
>> "make" : "Tonda"
>> },
>> {
>> "id" : "3",
>> "make" : "Tamsung"
>> }
>> ]
>>
>>
>> I am using iterate, to send each element of above array as request to a
>> backend service( In myactual project this is not so simple service i.e.
>> backend service reponse is very complex json with lots of arrays and
>> sub-arrays(child arrays)in it . for better understanding of issue I kept it
>> like this ).
>>
>> The responses of the backend service are aggregated in one soap xml by
>> AggregateMediator.
>>
>> Below is response from AggregateMediator
>>
>>  <?xml version='1.0' encoding='utf-8'?>
>> <soapenv:Envelope xmlns:soapenv="http://schemas.
>> xmlsoap.org/soap/envelope/">
>> <soapenv:Body>
>> <Information>
>> <jsonObject>
>> <id>1</id>
>> <make>TAHB</make>
>> <children>
>> <kid>1</kid>
>> </children>
>> <children>
>> <kid>2</kid>
>> </children>
>> <name>Home</name>
>> <area>5000sqft</area>
>> </jsonObject>
>> <jsonObject>
>> <id>2</id>
>> <make>Tonda</make>
>> <name>Car</name>
>> <model>Tmaze</model>
>> </jsonObject>
>> <jsonObject>
>> <id>3</id>
>> <make>Tamsung</make>
>> <name>Mobile</name>
>> <model>S8</model>
>> </jsonObject>
>> </Information>
>> </soapenv:Body>
>> </soapenv:Envelope>
>>
>> Requirement is to add all the responses from the backend service except
>> the first one, to the child array of the first response of the backend
>> service.
>> I do not know how to do this ? not even how to add new elements to a
>> array in wso2.
>>
>> My Current Output :
>>
>> {
>> "id": 1,
>> "make": "TAHB",
>> "children": [{
>> "kid": 1
>> },
>> {
>> "kid": 2
>> }],
>> "name": "Home",
>> "area": "5000sqft",
>> "jsonObject": [{
>> "id": 2,
>> "make": "Tonda",
>> "name": "Car",
>> "model": "Tmaze"
>> },
>> {
>> "id": 3,
>> "make": "Tamsung",
>> "name": "Mobile",
>> "model": "S8"
>> }]
>> }
>>
>>
>> Desired Output :
>>
>> {
>> "id": 1,
>> "make": "TAHB",
>> "children": [
>> {
>> "kid": 1
>> },
>> {
>> "kid": 2
>> },
>> {
>> "id": 2,
>> "make": "Tonda",
>> "name": "Car",
>> "model": "Tmaze"
>> },
>> {
>> "id": 3,
>> "make": "Tamsung",
>> "name": "Mobile",
>> "model": "S8"
>> }
>> ],
>> "name": "Home",
>> "area": "5000sqft",
>> }
>>
>> Please find main xml and backendService xml attached. It contains what I
>> tried.
>> main xml : addChild.xml
>> backendService xml : modifyAgrRes.xml
>>
>>
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Sudharma Subasinghe,
> Software Engineer,
> WSO2 Inc.
> Email: [email protected] <[email protected]>
> Mobile : +94 710 565 157 <%2B94%20718%20210%20200>
>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to