So I have the following code:
public void SendToApplication(HttpServletRequest request) throws IOException, TransformerException {
BufferedReader br = new BufferedReader(new FileReader(new File("CreatePoll.xml")));
String line;
StringBuilder sb = new StringBuilder();
while((line=br.readLine())!= null) sb.append(line.trim());
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://localhost:8080/cs9322.simple.rest.doodle/rest/polls/comment");
StringEntity input = new StringEntity(sb.toString());
input.setContentType("text/xml");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
HttpEntity entity = response.getEntity();
}
Which reads a XML file (CreatePoll.xml),
<Comment xmlns:xs="http://localhost:8080/cs9322.simple.rest.doodle/CommentSchema">
<Poll_ID>2</Poll_ID>
<Name>Bob</Name>
<Text>testing junk</Text>
<Timestamp>2012-10-14T12:37:04</Timestamp>
</Comment>
And posts it to a web service, the problem I am having now is trying to receive the XML response from the web service after sending that. XML I am meant to receive is:
<comment>
<address>
</address>
</comment>
Can someone help me out here it’d be much appreciated!
If you utilize the Apache Commons IO, then you can use the
IOUtilsclass to read the input stream from theHttpEntity. Example using the twitter Rest API: