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.