Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
How to configure the component to accept a 'form' file and return it in a 'json' file?
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
Hi @rhall ,
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.
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
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
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
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?
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