First thanks for help.

Our application is sending objects to the servlets using the URLConnection.
The servlet then processes the request and sends the appropriate response
object.

here is the code for our uploadObject method


URL servletURL url = new URL(location);
URLConnection urlConnection = url .openConnection();

urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setDefaultUseCaches(false);
urlConnection.setRequestProperty("Content-Type",
                                        "application/octet-stream");


outputToServlet =       new
ObjectOutputStream(urlConnection.getOutputStream());
// send object to servlet
outputToServlet.writeObject(objectToServer);
// read object from servlet
inputFromServlet = new ObjectInputStream(urlConnection.getInputStream());
// Exception occurs here



the servlet code is (the doGet method)


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

Object objectFromClient = in.readObject();

Object resultObject = processReceivedObject(objectFromClient,
                                        request, response);
if (resultObject != null) {
        // Create output stream to write Object
        out = new ObjectOutputStream(response.getOutputStream());
        
        out.writeObject(resultObject);
}
if (in != null) {
        in.close();
}
// Close the output stream
if (out != null) {
        out.flush();
        out.close();
}


Narinder.



-----Original Message-----
From: Randy Layman [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 28, 2001 5:17 PM
To: Tomcat Users List
Subject: RE: Getting java.io.StreamCorruptedException (URGENT).



        First question, how are you sending Objects to the servlet?  Are you
sure that immediately following the HTTP header is your object?  Why don't
you read the bytes and print them out to see if, perhaps, there is an extra
space or new line character in what you are reading?

        Randy

> -----Original Message-----
> From: Narinder Singh [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, November 28, 2001 2:53 AM
> To: [EMAIL PROTECTED]
> Subject: Getting java.io.StreamCorruptedException (URGENT).
> 
> 
> Hi
> 
> I am using tomcat 3.2.3.
> I am getting java.io.StreamCorruptedException while trying to 
> read objects
> from servlet.
> 
> Here is the Exception (stack trace)
> 
> java.io.StreamCorruptedException: InputStream does not 
> contain a serialized
> object
>       at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
>       at java.io.ObjectInputStream.<init>(Unknown Source)
>       at com.quark.client.Connect.uploadObject(Connect.java:229)
> 
> 
> and the code for getting the object follows
> 
>    outputToServlet =  new
> ObjectOutputStream(urlConnection.getOutputStream());
>    outputToServlet.writeObject(objectToServer);
>    inputFromServlet = new 
> ObjectInputStream(urlConnection.getInputStream());
> // Exception occurs here
> 
> 
> I have narrowed down the problem to the 'ObjectInputStream' class's
> readStreamHeader() method.
> the exception is throws on STREAM_MAGIC mismatch.
> 
> Also this exception occurs only for some particular objects (i.e for
> particular state).
> Can any one please tell what might be the possible cause of problem.
> 
> 
> Regards
> Narinder
> [EMAIL PROTECTED]
> 
> 
> --
> To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>
> 

--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to