Hi,

I build a little test application that sends serialized String objects to
the server and receives a serialized string back. I mistakenly said that it
throws a NotSerializableException. In fact it is :

java.io.StreamCorruptedException:InputStream does not contain a serialized
object.

And it only happens on the way to the server...the String that I send back
to my application arrives safely. 

*****APPLICATION SIDE******
//HERE IS HOW I SEND IT FROM THE APPLICATION TO THE SERVLET
URL                 url                 = null;
URLConnection       connection          = null;
ObjectOutputStream  objectOutputStream  = null;
InputStream         replyStream         = null;
String servletURLString    = (String) iParams.get("param_servletURL");
String  argString = "?" + "requestType" + "=" + "TESTOBJSTREAM";

// open an url connection to the server
url           = new URL(servletURLString + argString);
connection    = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", "application/octet-stream");

try
{
 // serialize the object and write it to the stream,
 // then flush and close the stream
 objectOutputStream  = new ObjectOutputStream(connection.getOutputStream());
 objectOutputStream.writeObject(commObject);
 objectOutputStream.flush();
 objectOutputStream.close();
 replyStream = connection.getInputStream();
}
catch (Exception e)
{
 System.out.println("NO RETURN OBJECT"+e);
}

*********SERVLET SIDE*********
//HERE IS HOW I RECEIVE IT ON THE SERVLET SIDE
InputStream         inputStream        = request.getInputStream();
ObjectInputStream   objectInputStream  = new ObjectInputStream(inputStream);
Object              receivedObject     = objectInputStream.readObject();
//THE REST IS IRRELEVANT,BECAUSE AT THIS POINT A
java.io.StreamCorruptedException IS THROWN. THEN I CATCH IT AND SEND BACK AN EXCEPTION 
LISTING WHICH
ARRIVES OK AT THE APPLICATION

Thanks

Blair




>From: GOMEZ Henri 
>Subject:  RE: Apj13 and Java Object Streams
>Date:  Tue, 15 May 2001 12:36:39 +0200

>Could you send us an example code ?)

>Henri Gomez                 ___[_]____

>>-----Original Message-----
>>From: Blair Dye [mailto:[EMAIL PROTECTED]]
>>Sent: Monday, May 14, 2001 9:02 PM
>>To: [EMAIL PROTECTED]
>>Subject: Apj13 and Java Object Streams
>>
>>
>>Hi,
>>
>>Tomcat 3.2.2
>>I have tried to switch protocols to Apjv13, but cant seem to get
>Object
>>Serialization working. It throws a Not Serializable Exception
>>even though
>>everything works fine with Apj12.
>>
>>Anyone else had similar problems or solutions?
>>
>>Thanks
>>Blair

-- 
 

Sent through GMX FreeMail - http://www.gmx.net

Reply via email to