Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Submit xml data to an Url from a servlet

 
Ajith George
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i submit xml data to an Url from a servlet?
XML data is created on a string buffer and now i want to submit it to a url. This should be done with out using attributes..............ie should be writen to the stream.
Please help me out..........

Thanks in advance.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strictly speaking this is an IO question and has nothing to do with Servlets. It doesn't matter whether you do this from a Servlet or any other class. you can use the java.net package or a stronger version in the Jakarta HttpComponents.

Dave
 
Chris Grimble
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've used a bit of code like this in the past.

private void sendXml(String xml, URL endPoint) {
try {
OutputStreamWriter out = null;
try {
URLConnection connection = endPoint.openConnection();
connection.setDoOutput(true);
out = new OutputStreamWriter(connection.getOutputStream());
out.write(xml);
out.flush();
} finally {
if (out != null) {
out.close();
}
}
} catch (IOException e) {
//Handle exception
}
}
 
Ajith George
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chris. But how can i read the response back from the server. i tried input stream but it is returning internal server error.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to look into this article that mentions the numerous URLConnection pitfalls and how to avoid them.

ram.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic