[Webinar] Learn how to a build a cloud-first strategyRegister Now


Problem reading XML doc

Posted on 2006-04-03
Medium Priority
Last Modified: 2012-05-05
In my servlet, I create a org.jdom.Document and I send it in my doGet(HttpServletRequest request, HttpServletResponse response) as the following:


Then in my HttpUnit I do the following:
WebResponse response = client.getResponse("http://localhost:8080/myServlet");
ObjectInputStream input = new ObjectInputStream(response.getInputStream());
Document document = (Document) input.readObject();
XMLSerializer.printXmlDoc(document, System.out, true);

The test is failing in the second line above with a StreamCorruptedException.

Any help would be greatly appreciated.
Question by:salmasri
  • 2
  • 2
LVL 86

Expert Comment

ID: 16359487
Yes, don't use ObjectInputSTream
LVL 92

Accepted Solution

objects earned 2000 total points
ID: 16359537
Thats not sending a serialized Document , should be sent more like:

ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
LVL 30

Expert Comment

by:Mayank S
ID: 16361658
Writers and readers are used for character and text-based data. In your case since you are not dealing with that, you need to directly deal with the serialized form of the object.
LVL 86

Expert Comment

ID: 16362045
<"virtually deleted comment", reinstated by GranMod>


new XMLOutputter().output(document, response.getWriter());



WebResponse response = client.getResponse("http://localhost:8080/myServlet");
Document document = new SAXBuilder().build(response.getInputStream());
new XMLOutputter().output(document, System.out);

Your client should just as easily be able to be your web browser
LVL 30

Expert Comment

by:Mayank S
ID: 16369152
I remember one of the comments posted here later by CEHJ was a useful approach too (the one about using XML).

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month20 days, 11 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question