One Star

using Rest with POST XML

Hi,
I have a job that is a REST service in which I use XML to pass data to and it returns XML. The data is posted to it using POST.
So in the job I mapped for the incoming an field named id
However I do not know how to pass the data to it. I did a POST (content type application/xml ) with an xml like this:
123
But the job in talend fills in null for the id. I am not exacly sure what the problem is, is my POST data structure not correct? or is it not possible to use the tRESTREquest directly like this with an incoming XML and should another component extract the XML fields from the RestRequest?

12 REPLIES
Employee

Re: using Rest with POST XML

Hi,
We created tutorials about REST service; they might help you. Here is the link to the first one: http://talendforge.org/tutorials/tutorial.php?language=english&idTuto=104
Regards,

--
Marie
One Star

Re: using Rest with POST XML

Thank you, I will have a look!
Employee

Re: using Rest with POST XML

Hi
The id field in the input will only be filled if you have an ID in URL pattern, like
/foo/bar/{id}
The body will be however put in the flow, please use tXMLMap after tRESTRequest to parse it.
Renat
One Star

Re: using Rest with POST XML

Hi, I want to use POST with XML data with the REST service, so your solution will not work for me. But I found the problem, the body type of the rest service was set to String instead of Document.
I set it to Document and after that I can use tXmlMap to access the XMl fields.
One Star

Re: using Rest with POST XML

hi all,
I would like to create a trest service too, with a similar sheme.
Do you use trest to test the trest service ? can you provide an example of the structure of an http post via trest ?
i run the service in talend with http://localhost:8095/service and trest with the same (in talend too), i get the 415 error status
 25 mai 2012 16:07:13 org.apache.cxf.jaxrs.utils.JAXRSUtils findTargetMethod
ATTENTION: No operation matching request path "/service" is found, Relative Path: /service, HTTP Method: POST, ContentType: text/plain, Accept: text/html,image/gif,image/jpeg,*/*,*/*;q=.2,. Please enable FINE/TRACE log level for more details.

thanks in advance Smiley Happy
One Star

Re: using Rest with POST XML

i correct this error by adding an header : "content-type" "application/xml" Smiley Happy
is someone able to provide the configuration of txmlmap between trestrequest and trest response ? i am unable to qualify this content (received by tresrequest).
many thanks
One Star

Re: using Rest with POST XML

Hi,
after a tRestClient component, the response is available in a tlogRow.
But if I use a tXMLmap to get xml content, I have no error but no results.
Where is the problem?
Thanks for help
Four Stars

Re: using Rest with POST XML

Hi,
I have similar problems when I try to design a REST Service using PUT or POST methods to insert or update datas in a DB.
I did not find any tutorial about REST Service with output to DB and the PDF documentation about REST Components does not provide such scenario. Only the use case with http GET and a DB input is explained.
If anybody from Talend, who already exprimented this kind of REST Service, could explain the main steps, it would probably help many users !
Thanks
Four Stars

Re: using Rest with POST XML

Does anybody knows what is wrong in my example below ? The flow seems empty and all components are remaining in "Starting" status ... I tried both POST and PUT methods
One Star

Re: using Rest with POST XML

Hi,
I've created a short tutorial how to use the tRESTRequest in combination with POST XML below:
1. Create flow as shown in the RESTRequestExampleREST_POST_XML screenshot
--> The body is set to "Document", this will hold the XML payload
2. In the tXML component (see xmlMapExampleREST_POST_XML screenshot), define the schema schema for the body, in this case I used a simple schema:



3. Map the xml fields to your target schema, in this case "messageContent" of type String
4. The messageContent is printed using the tLogRow (using TablePrint)
5. The tRESTResponse is default (returns 200 OK)

Now, start the job and run the command below to test:
curl -X POST -H "Content-Type: application/xml" -H "Accept: application/xml" -d "123" http://127.0.0.1:8090/myRESTService/publishId
As a result, you have the tLogRow component printing the value of :
| tLogRow_1 |
|=------------=|
|messageContent|
|=------------=|
|123 |
'--------------'
That's all.
Robin
Four Stars

Re: using Rest with POST XML

Great, many thanks Robin !
One Star

Re: using Rest with POST XML

Hello. try to do as rhuiser wrote and i have a null result. Can't understand, what I am doing wrong