• Post Reply Bookmark Topic Watch Topic
  • New Topic

XStream and Servlet

 
Manjula Babaladi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java application that is making a request to the tomcat and tomcat is mapping it appropriate servlet. I am sending the XML String to the servlet. The servlet has to deserialize the XML String, process it and return appropriate result. Below is the code for java app and servlet. When I execute this, I don't get any exceptions... but I don't get the output either.. that is... java app does not print the output..but when i comment the XStream statements I get some output. Kindly help..

I am new to XStream....

Class ContactServlet{
URL url = new URL("http://localhost:8080/VUWIServer/HelloWorldExample");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);

BufferedWriter out =
new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );
out.write(outXML);
out.flush();
out.close();
BufferedReader in =
new BufferedReader( new InputStreamReader( conn.getInputStream() ) );

String response;
while ( (response = in.readLine()) != null ) {
System.out.println( response );
}
in.close();
}



the Servlet code:

protected void doGet( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException {

BufferedReader bin = null;
BufferedWriter bout = null;



InputStreamReader inStream= new InputStreamReader(request.getInputStream());
bin = new BufferedReader(inStream);

String input = bin.readLine();


MsgInContainer appData = new MsgInContainer();

XStream xs = new XStream(new DomDriver());
//construct an object, appData, from the XML:
appData = (MsgInContainer)xs.fromXML(input);


String output = process(appData);

OutputStreamWriter outStream = new OutputStreamWriter(response.getOutputStream());
bout = new BufferedWriter(outStream);
bout.write(output);
bout.flush();

}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible the problem is:



As I recall, that closes the whole connection so the BufferedReader in does NOT get the response string.

Just out.flush() and let in.close() close the connection.

Bill
 
Manjula Babaladi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:It is possible the problem is:



As I recall, that closes the whole connection so the BufferedReader in does NOT get the response string.

Just out.flush() and let in.close() close the connection.

Bill


Thanks for your reply. I have resolved the issue.. I had not set the "Java EE Module dependencies" to include the modules I was using.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!