| Author |
REST service accepting XML data
|
wayne forrest
Greenhorn
Joined: Aug 23, 2010
Posts: 17
|
|
Hi , need some advice on how to RECEIVE XML data using a REST service, I want to accept XML data and have
the REST SERVICE process the XML data and deliver a response.
Would one store the entire XML document in a POST variable, using @POST together with String on the java rest service side?
and is it "safe" to have XML document stored in the POST variable or does have to be URLENCODED or BASE64 encoded?
Thanks/
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
1. The XML document should be written (as text) in the body of the POST request.
2. Not sure what you mean by "safe" - what security problems are you worried about?
3. Since XML documents are text, there appears to be no reason to encode.
4. Just read the request input stream for processing - see getInputStream or getReader
Bill
|
Java Resources at www.wbrogden.com
|
 |
wayne forrest
Greenhorn
Joined: Aug 23, 2010
Posts: 17
|
|
Thanks William,
(1)
What do you mean by in the body of the POST, is there perhaps an example of how to do a POST that has
XML as body.
(2)
By safe I meant that there are no funny characters that I need to encode, and that my XML document
will be received exactly the way it was sent.
Thanks.
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
A POST reguest will have:
1. request header lines - these are text conforming to the HTTP standard, such as:
2. a blank line terminates the header lines
3. the body
The body of the request may be anything - text, binary image, serialized object, etc.
Here is part of the code needed to send a POST, where serviceURL is a string like http:\\ etc.. and reqStr is XML text
You need to get very familiar with the java.net.URLConnection and HttpURLConnection javadocs.
Bill
|
 |
 |
|
|
subject: REST service accepting XML data
|
|
|