hi bindul

thanks for moving this request - ididn't realise there was a separate
list for http-client.

in reply to your question:
by reading the bytes from 'item.openStream()' in a loop and logging the
number of bytes processed i was able to verify that the
'item.openStream()' correctly returns the file content.
(i did this just befor the line where i would pass the stream to the
entity)

the InputStreamRequestEntity's constructor seems to not be able to get
the contents of the stream passed as argument ....?

cheers
alessandro



-----Original Message-----
From: Bindul Bhowmik [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 15, 2007 10:06 PM
To: Jakarta Commons Users List; HttpClient User Discussion
Subject: Re: IllegalStateException: Content must be set before entity is
written

Hello Alessandro,

Moving this discussion to the HttpClient Users list.

On 2/15/07, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> hi there
>
> i'm traing to send a multipart reqest using the 
> InputStreamRequestEntity in httpclient 3.0.1.
> this is the code:
>
> note: clientRequest is an incoming HttpServletRequest, and the stream 
> used for the InputStreamRequestEntity's constructor is obtained by 
> using the commons.FileUpload API.
>
>         ServletFileUpload upload = new ServletFileUpload();
>         FileItemIterator iter = upload.getItemIterator(clientRequest);
>         while (iter.hasNext()) {
>           FileItemStream item = iter.next();
>           String name = item.getFieldName();
>           if (item.isFormField()) {
>             postMethod.addParameter(name, 
> Streams.asString(item.openStream()));
>           } else {
>             postMethod.setRequestEntity(new 
> InputStreamRequestEntity(item.openStream()));
>           }
>         }
>

Can you check if the 'item.openStream()' returns null? The reason the
exception is thrown is that the InputStream passed on to the
InputStreamRequestEntity is null.

> upon executing the post method, the following exception is thrown:
>
> java.lang.IllegalStateException: Content must be set before entity is 
> written
>         at
> org.apache.commons.httpclient.methods.InputStreamRequestEntity.writeRe
> qu
> est(InputStreamRequestEntity.java:176)
>         at
> org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeReque
> st
> Body(EntityEnclosingMethod.java:495)
>         at
> org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBa
> se
> .java:1973)
>         at
> org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.ja
> va
> :993)
>         at
> org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Http
> Me
> thodDirector.java:397)
>         at
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMet
> ho
> dDirector.java:170)
>         at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java
> :3
> 96)
>         at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java
> :3
> 24)
>
> i'm obviously doing something wrong ;-) .. could someone help me 
> understand what?
>
> thanks in advance for any hint!
> cheers
> alessandro
>

Regards,
Bindul

--
Bindul Bhowmik
MindTree Consulting Ltd.

---------------------------------------------------------------------
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]

Reply via email to