EOFException with Servlet and serialization

Hi,

I've got a problem using serialization with a servlet. I need to serialize an object and send it to a servlet which will deserialize it. I'm having the folowing exception :

java.io.EOFException

at java.io.DataInputStream.readFully(DataInputStream.java:158)

at java.io.ObjectInputStream.readFully(ObjectInputStream.java:2071)

........

Client code

-

// connects to the servlet

URL url = new URL("http", host, Integer.port, servlet);

HttpURLConnection connection = (HttpURLConnection)url.openConnection();

connection.setDoOutput(true);

connection.setUseCaches(false);

connection.setDefaultUseCaches(false);

connection.setRequestProperty("Content-Type", "application/octet-stream");

// write to stream

ObjectOutputStream oos = new ObjectOutputStream(connection.getOutputStream());

oos.writeObject(record);

oos.flush();

oos.close();

Servlet code

ObjectInputStream ois = new ObjectInputStream(request.getInputStream());

logRecord = (LogRecord)ois.readObject();

ois.close();

Any ideas ? Thanks.

Antonio

[1186 byte] By [a.goncal] at [2007-9-26 12:40:42]
# 1
I'm getting the same error. Can anyone help?
wbracken at 2007-7-2 12:03:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
I have got the same problem. whi can help me? my email is:mkw@ips.gov.au
mkhw at 2007-7-2 12:03:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Make sure that your servlet handles the transaction in the same thread that doPost() or doGet() is called in.

I ended up porting some old ServerSocket based code to a servlet, and was handing off the request and response objects to a handler thread on the server side. I ended up with a ton of intermittent errors like this.

Once I started handling the transactions in the same thread things worked heartbreakingly well.

danielpasco at 2007-7-2 12:03:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...