Encounter an invalid stream header

757 views
Skip to first unread message

N@oj

unread,
Jul 9, 2009, 6:30:46 AM7/9/09
to Google Web Toolkit
Hi folks,

I'm working on a small application which tend to communicate with a
foreign webserver to generate specific contents. A RPC is used when
the user fire the event by clicking on a button.

Java.net is used with URL et URLConnection. Tipically I write a
serialized string to the outputstream whereas the distant servlet read
the inputstream to reconstitute the string object.

It works fine without the appengine, but when I want to use it, I get
this error : java.io.StreamCorruptedException: invalid stream header

I can't understand why this exception is happening...

Here is some code of my AskGenerationImpl class :

URL url = new URL("http://localhost:8080/requestmanager/download");
//URLConnection con = url.openConnection();
HttpURLConnection con = (HttpURLConnection)url.openConnection
();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setDefaultUseCaches(false);
con.setRequestMethod("POST");
con.setRequestProperty("Transfert-Coding", "chunked");
//con.setRequestProperty("HTTP-Version", "HTTP/1.0");
//con.setRequestProperty("Content-Encoding", "iso-8859-1");
//con.setRequestProperty("Content-Type", "application/x-java-
serialized-object");
/con.setRequestProperty("Content-Type","application/x-www-form-
urlencoded");
con.setRequestProperty("Content-Encoding", "gzip");
con.setRequestProperty("Cache-Control", "no-cache");
con.setRequestProperty("Pragma","no-cache");
con.setRequestProperty("User-Agent", "Java/1.5.0_19");
//con.setRequestProperty("Connection", "keep-alive");
con.setRequestProperty("Content-Type", "application/x-www-form-
urlencoded");

con.connect();

String s = new String("anku");

ObjectOutputStream oos = new ObjectOutputStream(con.getOutputStream
());
oos.writeObject(s);
oos.flush();
oos.close();

InputStream is = con.getInputStream();
ObjectInputStream ois = new ObjectInputStream(is);
Object o = ois.readObject();
ois.close();

And here the servlet :

try {
InputStream is = request.getInputStream();
ObjectInputStream ois = new ObjectInputStream(is); // <<--
Crash here
}

I tryed to manipulate byte arrays. The content send is always the
same : -84 -19 0 5 116 0 4 97 110 107 117 (the last 4 bytes represent
the string "anku")
Without the appengine, it doesn't crash and the received byte array
is : 172 237 0 5 116 ...
With the appengine, the received byte array is : 63 63 0 5 116 ...

Is there any clue ? Did I miss something in the encoding/content
type ?

If someone have any idea, please let my know :)

Thank you.

N@oj

unread,
Jul 10, 2009, 2:40:03 AM7/10/09
to Google Web Toolkit
Well,

After new research, I've found that first two bytes 63 correspond to
the "?" char, or 0x3f hexadecimal value, which means that magic number
and version number are incorrect.

I think it comes from Jakarta, this is the only difference when I'm
using the appengine...

Any advice ?

N@oj

unread,
Jul 13, 2009, 6:16:59 AM7/13/09
to Google Web Toolkit
Hello,

I'm still working on it... and remain stuck!

Here comes a new discovery : sending a serialized object to the
servlet failed because headers seem invalid. But when the servlet
responds, with a serialized object too, the server gets it correctly.

What does this mean ? Does the response use different headers ? I
can't find if it comes from jetty or jakarta :/

Bye.

Rooney Wayne

unread,
Aug 5, 2014, 10:26:58 PM8/5/14
to google-we...@googlegroups.com, Google-We...@googlegroups.com
I run into the same problem. Did you figure it out after several years?

在 2009年7月13日星期一UTC+8下午6时16分59秒,N@oj写道:
Reply all
Reply to author
Forward
0 new messages