0

I have an ActionScript File sending XML to my servlet. I am only getting empty arrays on output. Anyone know what Exactly I'm doing wrong? output is:

java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:764) at java.io.ObjectInputStream.(ObjectInputStream.java:277) at myDungeonAccessor.myDungeonAccessorServlet.doPost(myDungeonAccessorServlet.java:82)

   package myDungeonAccessor;
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {    
try {
    System.out.println("HEADERS: " + request.getHeaderNames());
    ObjectInputStream in = new ObjectInputStream(request.getInputStream());
    System.out.println(in);
    ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
   } catch(Exception e) {
       e.printStackTrace();
   }

Exception

3
  • In the future, please minimize the piece of code to only show the relevant code. Remove the javadocs, remove all outcommented lines, remove all methods which are out of question. Keep it short and concise as possible with regard to the actual problem (i.e. show only the actually used code lines). It was for example unclear whether you used GET or POST and so on. Commented Apr 29, 2010 at 14:50
  • Sorry, the updated code makes no sense. It actually does no business. It's only printing the enumeration with request header names and it's also printing the reference of the ObjectInputStream which decorated the request body. It is actually not reading from request body nor writing to the response body. With "relevant" code I mean the minimum amount of code which reproduces the exact problem which you're facing. Do you for instance understand what each line of code is exactly doing? If not, then I would take a step back and figure that first. Commented May 1, 2010 at 4:11
  • I dont think you understand the problem.... I am unable to retrieve the XML that I am sending to it. How can I get the XML data to be properly read? I am trying to read the XML as on Object Input Stream.... I created an ActiomScript File that will create an XML String, and I want to send the XML String to a database. I want to do this using a servlet. I am just having an issue with actually receiving the XML on the Java side. It sends fine, but I do not know how to save the XML Properly Commented May 1, 2010 at 17:41

1 Answer 1

1

System.out.println() writes to the stdout (which usually ends up in server logs and/or the IDE console, if any), not to the response. Write to response.getWriter() instead.

That said, I'd suggest to use XStream to write fullworthy Javabeans to XML without pains.

response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
new XStream().toXML(bean, response.getOutputStream());
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your suggestions to make things easier for someone to help me. The issue is receiving the data though, I am getting exception 'java.io.StreamCorruptedException: invalid stream header'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.