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)
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.
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:
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)
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.