opensubscriber
   Find in this group all groups
 
Unknown more information…

h : httpclient-dev@jakarta.apache.org 10 November 2006 • 3:11PM -0500

java.io.StreamCorruptedException when a sending huge java object...
by Suraj Natarajan

REPLY TO AUTHOR
 
REPLY TO GROUP





Hi,

I am using HttpClient 3.0.1 and sending a java object as a byte[].

Client Side:
--------------
// sending a java object as
HttpClient hc = new HttpClient();
HttpState hs = new HttpState();
hc.setState(initialState);

PostMethod pm = new PostMethod(url);
// serializedJavaObj as a byte[]
pm.setRequestEntity(new ByteArrayRequestEntity(serializedJavaObj));
hc.executeMethod(pm);

Server Side (Servlet):
----------------------

int len = httpRequest.getContentLength();
InputStream is = httpRequest.getInputStream();
byte[] b = new byte[len] ;
// read the entire content in one shot
is.read(b);

// construct the java object from the byte[]
deserialize(b) ;

If the request content length is big around 25K then a
java.io.StreamCorruptedException is thrown during deserialization. This
only happens when the content length is big.

If the stream is read using the code below then it works fine even for
huge content length.
InputStream is = httpRequest.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((read = bis.read(buffer)) != -1) {
  baos.write(buffer, 0, read);
}
deserialize(baos.toByteArray());

Can someone please explain the problem and is there a better way do
this?

Thanks in advance.



This message and the information contained herein is proprietary and confidential and subject to the Amdocs policy statement,
you may review at http://www.amdocs.com/email_disclaimer.asp

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.