When MultiPartRequestEntity is used to send serialized object, the
server (servlet) throws error "unexpected jdwp error: 35" while reading
the object. I've attached code snippet from client and server
Client code:
ByteArrayOutputStream requestStream = new
ByteArrayOutputStream();
ObjectOutputStream objectOutput = new
ObjectOutputStream(requestStream);
objectOutput.writeObject(request);
objectOutput.close();
String enc = "ISO-8859-1";
MultipartRequestEntity entity = new MultipartRequestEntity(
new Part[] {
new FilePart(
"param1",
new ByteArrayPartSource("filename.txt",
requestStream.toByteArray()),
"application/octet-stream",
enc) },
post.getParams());
post.setRequestEntity(entity);
NameValuePair[] pair = new NameValuePair[1];
pair[0] = new NameValuePair(IRequest.HTTP_REQUEST_HANDLER,
handler);
post.setQueryString(pair);
m_client.executeMethod(post);
Server code:
public void doFilter(ServletRequest request, ServletResponse
response, FilterChain chain)
throws IOException, ServletException {
if (m_abortErrorMessage != null) {
((HttpServletResponse) response).sendError(500,
m_abortErrorMessage);
return;
}
if (request instanceof HttpServletRequest) {
HttpServletRequest req = (HttpServletRequest) request;
String reqHandlerName =
req.getParameter(IRequest.HTTP_REQUEST_HANDLER);
if (reqHandlerName != null) {
InputStream reqInputStream = req.getInputStream();
ObjectInputStream reqStream = new
ObjectInputStream(reqInputStream); //this line throws the error
IRequest reqObject = null;
try {
reqObject = (IRequest) reqStream.readObject();
}
catch (ClassNotFoundException e) {
((HttpServletResponse) response).sendError(400);
}
}
}
The same server code works fine when InputStreamRequestEntity is used,
here is client code
ByteArrayOutputStream requestStream = new
ByteArrayOutputStream();
ObjectOutputStream objectOutput = new
ObjectOutputStream(requestStream);
objectOutput.writeObject(request);
objectOutput.close();
InputStream requestContent = new
ByteArrayInputStream(requestStream.toByteArray());
if (requestContent != null) {
post.setRequestEntity(new
InputStreamRequestEntity(requestContent));
}
NameValuePair[] pair = new NameValuePair[1];
pair[0] = new NameValuePair(IRequest.HTTP_REQUEST_HANDLER,
handler);
post.setQueryString(pair);
m_client.executeMethod(post);
We need to use multipart request entity.
I appreciate help to solve this problem.
Regards
Valli
-----Original Message-----
From: Oleg Kalnichevski [mailto:[EMAIL PROTECTED]
Sent: Sunday, May 18, 2008 8:09 AM
To: HttpClient User Discussion
Subject: Re: Sending serialized object and stream
On Fri, 2008-05-16 at 16:05 -0400, [EMAIL PROTECTED] wrote:
> Hi All,
>
> I've requirement to send both serialized java object and stream
object.
> Here is the code that sends serialized object
>
> ByteArrayOutputStream requestStream = new
> ByteArrayOutputStream();
> ObjectOutputStream objectOutput = new
> ObjectOutputStream(requestStream);
> objectOutput.writeObject(request);
> objectOutput.close();
>
> InputStream requestContent = new
> ByteArrayInputStream(requestStream.toByteArray());
> if (requestContent != null) {
> post.setRequestEntity(new
> InputStreamRequestEntity(requestContent));
> }
>
> We need to optionally send stream object as well. I believe we need to
> use multipart request entity. The HC currently supports FilePart and
> StringPart. Do we need to write another type of Part like StreamPart
to
> do so?
>
Yes, you do
Oleg
> Help is appreciated.
>
> Thanks in advance
>
> Valli
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]