views:

88

answers:

1

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

+1  A: 

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());
BalusC
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'
John Doe