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

x
?
Solved

Problem reading XML doc

Posted on 2006-04-03
7
Medium Priority
?
231 Views
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:

response.getWriter().print(document);

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.
0
Comment
Question by:salmasri
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

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

Accepted Solution

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

ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
out.writeObject(document);
0
 
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.
0
 
LVL 86

Expert Comment

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

Server:

response.setContentType("text/xml");
new XMLOutputter().output(document, response.getWriter());

...

Client:

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
0
 
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).
0

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