Problem reading XML doc

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.
salmasriAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Yes, don't use ObjectInputSTream
Mick BarryJava DeveloperCommented:
Thats not sending a serialized Document , should be sent more like:

ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
out.writeObject(document);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
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.
CEHJCommented:
<"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
Mayank SAssociate Director - Product EngineeringCommented:
I remember one of the comments posted here later by CEHJ was a useful approach too (the one about using XML).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.