Problem reading XML doc

Posted on 2006-04-03
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
    LVL 86

    Expert Comment

    Yes, don't use ObjectInputSTream
    LVL 92

    Accepted Solution

    Thats not sending a serialized Document , should be sent more like:

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

    Expert Comment

    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

    <"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

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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now