How to use TRESTClient with HTTP Method - 'POST' and Content Type - 'FORM'?

Highlighted
Four Stars

How to use TRESTClient with HTTP Method - 'POST' and Content Type - 'FORM'?

How to configure the component to accept a 'form' file and return it in a 'json' file?

Tags (1)
Community Manager

Re: How to use TRESTClient with HTTP Method - 'POST' and Content Type - 'FORM'?

Hi @pedro_cesar,

 

Would you mind elaborating on your requirement and give a few further details? For example, the sort of data you are trying to send, the documentation for the web service you are wishing to use, etc

 

Regards

 

Richard

Four Stars

Re: How to use TRESTClient with HTTP Method - 'POST' and Content Type - 'FORM'?

Hi @rhall_2_0 ,

 

I have a job that I want to send data to an API via POST requisition. I have other jobs that are able to do this when the content type is JSON, but with this one the content type configured in the API is Form. With the JSON. I configure the JSON tree and pass it to the tRESTClient component. I'm not sure nor have I found any documentation as how to configure a content type FORM as input to a tRESTClient.

 

 

Community Manager

Re: How to use TRESTClient with HTTP Method - 'POST' and Content Type - 'FORM'?

Hi @pedro_cesar,

 

You might need to try a few things out here. The first thing to do is to set your HTTP method to POST. Then set your Content-Type to FORM. You will need to set your Accept-Type to JSON. Then you will need to configure your Form parameters in the Query Parameters table. Switch to the Advanced settings and untick "Convert response to DOM Document". Start with that and see how you go

 

Regards

 

Richard

Four Stars

Re: How to use TRESTClient with HTTP Method - 'POST' and Content Type - 'FORM'?

@rhall_2_0 

this mistake happened:

[ERROR]: org.apache.cxf.jaxrs.utils.JAXRSUtils - No message body writer has been found for class javax.ws.rs.core.Form, ContentType: application/json
org.apache.cxf.interceptor.Fault: No message body writer has been found for class javax.ws.rs.core.Form, ContentType: application/json
at org.apache.cxf.jaxrs.client.WebClient$BodyWriter.doWriteBody(WebClient.java:1192)
at org.apache.cxf.jaxrs.client.AbstractClient$AbstractBodyWriter.handleMessage(AbstractClient.java:1230)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:691)
at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1050)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:897)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:866)
at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:334)
at org.apache.cxf.jaxrs.client.WebClient.post(WebClient.java:343)
at bi_hab_talend.teste_aramis_0_1.teste_ARAMIS.tDBInput_1Process(teste_ARAMIS.java:3006)
at bi_hab_talend.teste_aramis_0_1.teste_ARAMIS.runJobInTOS(teste_ARAMIS.java:4812)
at bi_hab_talend.teste_aramis_0_1.teste_ARAMIS.main(teste_ARAMIS.java:4591)
Caused by: javax.ws.rs.ProcessingException: No message body writer has been found for class javax.ws.rs.core.Form, ContentType: application/json
at org.apache.cxf.jaxrs.client.AbstractClient.reportMessageHandlerProblem(AbstractClient.java:834)
at org.apache.cxf.jaxrs.client.AbstractClient.writeBody(AbstractClient.java:512)
at org.apache.cxf.jaxrs.client.WebClient$BodyWriter.doWriteBody(WebClient.java:1187)
... 11 more

Community Manager

Re: How to use TRESTClient with HTTP Method - 'POST' and Content Type - 'FORM'?

I'm afraid it is very difficult to debug web service issues without having the full web service spec and the configuration of the job. A screenshot of the job and the tRestClient component (basic and advanced settings) would be useful. But the real key is likely to be the web service documentation

Four Stars

Re: How to use TRESTClient with HTTP Method - 'POST' and Content Type - 'FORM'?

@rhall_2_0

 

The job is going to get data from the MSSQL database, then in tMap I'm just changing the names of the columns to send the data to the webservice as form data, which is what i'm struggling to do.

 

Below are the screenshots. Do you need any other information? 

 entire_job.PNGBasic_settings.PNGAdvanced_settings.PNG

Community Manager

Re: How to use TRESTClient with HTTP Method - 'POST' and Content Type - 'FORM'?

OK. I think this is where you are going wrong. It is a little fiddly, so this is not unusual. After your tMap_1, you need to add a tFlowToIterate. This will create an iteration after this component. The tFlowToIterate temporarily stores the row data into the globalMap using the key {row}.{column}. So a column called "myValue" coming out of your tMap would have the key "out1.myValue". Keep this in mind.

 

The next thing you need to do is connect a tJava to your iterate link. This is a dummy component. Do nothing with this. Simply connect it to the tRestClient using the OnComponentOK link. Now, your tRestClient looks OK apart from the query parameters. You need to ensure the names are precisely as your web service API has listed them. Your values need to be the globalMap variables explained in the first paragraph. So if your API has a variable name of "variable1" and you want to pass the value of "myValue" to it, you would add the following in the query parameters section....

 

Name: "variable1"

Value: ((String)globalMap.get("out1.myValue"))

 

The above assumes that "myValue" is a String....hence the (String) before the globalMap

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Have you checked out Talend’s 2019 Summer release yet?

Find out about Talend's 2019 Summer release

Blog

Talend Summer 2019 – What’s New?

Talend continues to revolutionize how businesses leverage speed and manage scale

Watch Now

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog