4

I've tested a POST request via REST API tool and getting the response in an XML format.

I'm not sure which method need to use and what should the response type class for the above.

Could someone help me with the code snippet for the same?

Thanks, Kathir

Kathir
  • 2,733
  • 12
  • 39
  • 67

1 Answers1

4

You need to add xml message converter to covert the xml messages to java objects.

See solution Stack Overflow

Also you can capture the result in String format and manually handle it then. Example :

String xmlData = restTemplate.postForObject(url, parameters, String.class);
// pass this string to xml parser and prepare java object

Sample xml Parsing example

Hope this helps

Community
  • 1
  • 1
Satish Pandey
  • 1,184
  • 4
  • 12
  • 32
  • I have added the same but it doesn't work. Could you please help me with a working sample URL, user name, password, source code? – Kathir Aug 30 '12 at 18:19
  • we need to do the following: Method1: 1) postForObject(url, requestclass with respect to the json request needed by the server, response.class for the incoming json response) 2) set the converter ex: MappingJacksonHttpMessageConverter 3) set the connection manager for multi-threaded env - MultiThreadedHttpConnectionManager 4) set the credentials for HttpClient setAuthenticationPreemptive Method2: postForObject(url, MultiValueMap, response.class). here MultiValueMap has the key and values for the parameters needs to be sent as a part of the body - ex: username, password, etc – Kathir Oct 08 '12 at 05:24