Return-Path: Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: (qmail 21061 invoked from network); 26 May 2010 07:24:50 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 26 May 2010 07:24:50 -0000 Received: (qmail 11222 invoked by uid 500); 26 May 2010 07:24:49 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 11068 invoked by uid 500); 26 May 2010 07:24:48 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 11060 invoked by uid 99); 26 May 2010 07:24:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 May 2010 07:24:47 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_HELO_PASS,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 May 2010 07:24:42 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1OHAyT-0008B8-O0 for httpclient-users@hc.apache.org; Wed, 26 May 2010 00:24:21 -0700 Message-ID: <28677346.post@talk.nabble.com> Date: Wed, 26 May 2010 00:24:21 -0700 (PDT) From: "franck.mosse" To: httpclient-users@hc.apache.org Subject: Re: Sending a multipart message with http client nio causes the UnsupportedOperationException exception In-Reply-To: <1274816820.14228.75.camel@ubuntu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: Franck.MOSSE@gemalto.com References: <6E6A11D164A93742B3B1CFB8DA721C2101366771C654@CROEXCFWP03.gemalto.com> <1274816820.14228.75.camel@ubuntu> 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