One Star

Parse data from tsv file to json and use tRestClient to create record

Hi,
I have been trying to use the tRESTClient component to create/update data into the database.
Also, the headers being acknowledged but the payload is shown as null i.e {} .
I am attaching my job design here.
Could there possibly be some error in the flow of components? as the payload is not getting rendered in the response-code?
ID: 1
Address: http://.....
Http-Method: PUT
Content-Type: application/json
Headers: {Content-Type=, Accept=, PREAUTH_USER_ID=}
Payload: {}           //// why so????
--------------------------------------
Sep 08, 2014 8:41:57 PM org.apache.cxf.interceptor.LoggingInInterceptor
INFO: Inbound Message
----------------------------
ID: 1
Response-Code: 400
Encoding: UTF-8
Content-Type: application/json;charset=UTF-8
Headers: {connection=, Content-Length=, content-type=, Date=, Server=, Set-Cookie=}
Payload: {"id":"IE-1410189116899","errors":,"message":"Expecting Accept=application/vnd.......mdm-v1+json"}]}
-----------------------
Exception in component tRESTClient_1
javax.ws.rs.BadRequestException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.apache.cxf.jaxrs.client.AbstractClient.convertToWebApplicationException(AbstractClient.java:463)
    at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:881)
    at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:852)
    at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:410)
    at org.apache.cxf.jaxrs.client.WebClient.put(WebClient.java:474)
    at demotraining.test_put_0_1.test_Put.tWriteJSONField_1_InProcess(zany_Put.java:2778)
    at demotraining.test_put_0_1.test_Put$1ThreadXMLField_tWriteJSONField_1_Out.run(test_Put.java:1078)
18 REPLIES
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

my job design is :
TSV file(tFileInputDelimited_1)------tMap_1------tWriteJSONField_1-------tXMLMap_1-------tRESTClient_1(Error here)
Please help!!!!
Community Manager

Re: Parse data from tsv file to json and use tRestClient to create record

Hi 
Can you please upload some screenshots of tXMLMap and tRestClient componnents' settings?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

Here,



 I am a bit confused between the body(Document datatype) column and the string(String datatype) column in tXMLMap. Are the component settings correct? Thank you.
Community Manager

Re: Parse data from tsv file to json and use tRestClient to create record

Hi 
You don't need a tWriteJSONField_1 to write a json string, if you want to pass a request with json format to the rest webservice, just need to select Content Type and Accept Type as Json on tRestClient componnet and define the document in tXMLMap. Please my screenshots:



Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

Hi, 
After removing tWriteJSONField it still doesnt seem to be working at my end.
Attaching screen shots here :
Sep 10, 2014 3:46:26 PM org.apache.cxf.interceptor.LoggingOutInterceptor
INFO: Outbound Message
---------------------------
ID: 1
Address: ......
Http-Method: PUT
Content-Type: application/json
Headers: {Content-Type=, Accept=, PREAUTH_USER_ID=}
Payload: {}
--------------------------------------
Sep 10, 2014 3:46:27 PM org.apache.cxf.interceptor.LoggingInInterceptor
INFO: Inbound Message
----------------------------
ID: 1
Response-Code: 400
Encoding: UTF-8
Content-Type: application/json;charset=UTF-8
Headers: {connection=, Content-Length=, content-type=, Date=, Server=, Set-Cookie=}
Payload: {"id":"IE-1410344187613","errors":,"message":"Expecting Accept=application/......-v1+json"}]}
--------------------------------------
Exception in component tRESTClient_1
javax.ws.rs.BadRequestException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.cxf.jaxrs.client.AbstractClient.convertToWebApplicationException(AbstractClient.java:463)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:881)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:852)
at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:410)
at org.apache.cxf.jaxrs.client.WebClient.put(WebClient.java:474)
at demotraining.zany_put_0_1.zany_Put.tFileInputDelimited_1Process(zany_Put.java:1849)
at demotraining.zany_put_0_1.zany_Put.runJobInTOS(zany_Put.java:2327)
at demotraining.zany_put_0_1.zany_Put.main(zany_Put.java:2186)
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

here,
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

Hi,
Could there possibly be some error in the Accept header?
Payload: {"id":"IE-1410344187613","errors":,"message":"Expecting Accept=application/......-v1+json"}]}
But the same headers are working fine when i call the Put HttpMethod from a Rest Client API(Data does get saved in the database). So i am not sure why I am encountering this error in Talend.
Thank you.
Community Manager

Re: Parse data from tsv file to json and use tRestClient to create record

Hi 
Http-Method: PUT
Content-Type: application/json
Headers: {Content-Type=, Accept=, PREAUTH_USER_ID=}
Payload: {}

The palyload is still empty, have you defined the document tree on tXMLMap? Can you please upload a screenshot of tXMLMap component?

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

The payload is coming fine now, after removing the tWriteJSONField component
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

screenshot of tXMLMap
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

Also, could you help me with this please?
I want to set an element from the json as an array. Can this be done?
Current payload:
here i want the alternateCurrencyCodes and addresses as the array elements.
Required payload:
"alternateCurrencyCodes":,
 "addresses":
}
Current settings in tXMLMap, but not working:


Is this possible?
Thank you.
Community Manager

Re: Parse data from tsv file to json and use tRestClient to create record

here i want the alternateCurrencyCodes and addresses as the array elements.

You can define both alternateCurrenrcyCodes and adresses as loop element, and set All in one attribute as true. see my screenshot.
 
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

Hi, 
thanks! that did help. IS there any way of adding square brackets before/after the elements in the array?
Example:
"alternateCurrencyCodes":,
 "addresses":
}
Community Manager

Re: Parse data from tsv file to json and use tRestClient to create record

It adds automatically the square brackets before/after the elements in an array. see my screenshot


Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

Hi,
I cannot seem to get the square brackets in my payload.
Attaching my screenshots here. Am i doing something wrong?
   
Community Manager

Re: Parse data from tsv file to json and use tRestClient to create record

Hi 
Which version are you using? I am using Talend Open Studio for ESB 5.5.1, if you are using an older version, try to upgrade your studio version and test it again.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

Hello,
I was using Talend Open Studio for Data Integration 5.5.1. Tried with ESB,it worked!
I have another issue.
Currently this is what i get in the payload :
,
      "parentGroupId":"876",
      "agencyGroupId":"191",
      "locale":"en_NZ",
     "defaultCurrencyCode":"GBP",
      "addresses":
   }
]
This is for only one row in the tsv file that is one record.
How can i implement a PUT loop for multiple records in the tsv?
That is the put request will get a payload of multiple values like :

       
           "ids":
           {
               "BuySystem": "ProductIntegrationTest3",
               "PlanSystem": "31C"
           },
           "version": 7,
           "status": "Active",
           "name": "Test3",
           "shortName": "Test3",
           "mediaTypes":
           
           ],
           "defaultCurrencyCode": "GBP",
           "alternateCurrencyCodes":
           
               "EUR"
           ],
           "addresses":
           
               {
                   "type": "Media",
                   "addressLine1": "line 1",
                   "addressLine2": null,
                   "addressLine3": null,
                   "addressLine4": null,
                   "addressLine5": null,
                   "postCode": "postcode",
                   "addressId": "Integration Test"
               }
           ]
       },
       {
           "ids":
           {
               "BuySystem": "3",
               "PlanSystem": "9NH"
           },
           "version": 2,
           "status": "Active",
           "name": "RENAULT",
           "shortName": "RENAULT",
           "mediaTypes":
           
               "Online",
               "Print"
           ],
           "locale": "en_NZ",
           "defaultCurrencyCode": "GBP",
           "alternateCurrencyCodes":
           
               "EUR"
           ],
           "addresses":
           
               {
                   "type": "Financial",
                   "addressLine1": "addressLine1",
                   "addressLine2": "Line2",
                   "addressLine3": "Line3",
                   "addressLine4": null,
                   "addressLine5": null,
                   "postCode": "postCode",
                   "addressId": "333"
               },
               {
                   "type": "Media",
                   "addressLine1": "addressLine1",
                   "addressLine2": "Line2",
                   "addressLine3": "Line3",
                   "addressLine4": null,
                   "addressLine5": null,
                   "postCode": "postCode",
                   "addressId": "653"
               }
           ]
       }
   ]
How can this be implemented? Will i have to use tFlowToIterate_1 component joining it to tRestClient(Tried but not working) or some other component?Thank you.
One Star

Re: Parse data from tsv file to json and use tRestClient to create record

Hi..
I am trying to use txmlmap component with trestclient. I recieve the following error though I don't have any null values in the records: 
 "  Payload: Error 400: BMXAA4149E - null is not a valid organization. Specify a valid Organization value as defined in the Organization application. "
Can you please post a solution for this. I am sharing the screenshots with you

Thanks
Anjali