hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "franck.mosse" <Franck.MO...@gemalto.com>
Subject Re: Sending a multipart message with http client nio causes the UnsupportedOperationException exception
Date Wed, 26 May 2010 07:24:21 GMT



olegk wrote:
> 
> On Tue, 2010-05-25 at 16:57 +0200, MOSSE Franck wrote:
>> Hi,
>> 
>> I am facing an issue while I am trying to send a Multipart Entity with
>> the http client nio api. I received the UnsupportedOperationException
>> exception.
>> 
>> I am using the following libraries:  httpcore-nio-4.0.1;  httpmime-4.0.1
>> and apache-mime4j-0.6.
>> 
>> The multipart message is built with the following code sample:
>> 
>>         BasicHttpEntityEnclosingRequest httppost = new
>> BasicHttpEntityEnclosingRequest( "POST", "http://localhost:8080 ");
>> 
>>         // Get stream from file
>>         FileInputStream fileStream = new FileInputStream( new File(
>> args[0]));
>>         InputStreamBody streamBody = new InputStreamBody( fileStream,
>> "image/png", args[0]);
>> 
>>         // Add a string
>>         StringBody comment = new StringBody( "A binary file of some
>> kind", Charset.forName("UTF-8"));
>> 
>>         MultipartEntity reqEntity = new MultipartEntity();
>>         reqEntity.addPart("comment", comment);
>>         reqEntity.addPart("bin", streamBody);
>> 
>>         httppost.setEntity( reqEntity);
>> 
>> 
>> The http request is sent using the http client nio api.
>> 
>> It seems that somewhere the multipart entity is encapsulated in a
>> NHttpEntityWrapper class that calls the getContent() method of the entity
>> at its construction.
>> The problem is that the MultipartEntity throws the
>> UnsupportedOperationException and no code is provided at the moment for
>> this method.
>> 
>> Can you tell me if it is planned to support this functionality in the
>> future ?
>> Do you known any kind of workaround to solve this problem ?
>> 
>> Thank you for your help.
>> Franck.
>> 
> 
> Franck
> 
> You are trying to use HttpCore NIO transport which is based on the
> non-blocking I/O model with a content library based on the classic
> (blocking) I/O model. These things just do not mix well. HttpMime API is
> inherently blocking. It simply cannot be used in a fully asynchronous
> mode.
> 
> You basically have two options: (1) buffer content in memory or (2) use
> a thread pool executor. Both options are described here:
> 
> http://hc.apache.org/httpcomponents-core-4.0.1/tutorial/html/nio.html#d0e2081
> 
> The question you should be asking yourself whether the use of NIO in
> your particular case makes any sense or not.  
> 
> Oleg  
>  
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> 

Hi olekg,

Using a  buffer content in memory will not be a good solution for me as i
have to transfert large amount of data like videos and i don't want to load
the full video in memory.

Is it planned to include the support of multipart messages and stream body
in the httpcore nio package ?
Franck.
-- 
View this message in context: http://old.nabble.com/Sending-a-multipart-message-with-http-client-nio-causes-the-UnsupportedOperationException-exception-tp28669483p28677346.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message