• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XStream and Servlet

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();

}
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic