Return-Path: Delivered-To: apmail-hc-dev-archive@www.apache.org Received: (qmail 58638 invoked from network); 16 Jun 2008 13:48:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Jun 2008 13:48:19 -0000 Received: (qmail 51745 invoked by uid 500); 16 Jun 2008 13:48:21 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 51705 invoked by uid 500); 16 Jun 2008 13:48:21 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 51694 invoked by uid 99); 16 Jun 2008 13:48:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jun 2008 06:48:21 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.130] (HELO eos.apache.org) (140.211.11.130) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jun 2008 13:47:40 +0000 Received: from eos.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id 65531D65C for ; Mon, 16 Jun 2008 13:47:28 +0000 (GMT) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Apache Wiki To: dev@hc.apache.org Date: Mon, 16 Jun 2008 13:47:28 -0000 Message-ID: <20080616134728.6211.76281@eos.apache.org> Subject: [Httpcomponents Wiki] Update of "HttpEntity" by QuintinBeukes X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Httpcomponents Wiki" for change notification. The following page has been changed by QuintinBeukes: http://wiki.apache.org/HttpComponents/HttpEntity ------------------------------------------------------------------------------ This is an entity which receives it's content from a !ContentProducer. Content producers are objects which produce their content on demand, by writing it out to an output stream. They are expected to be able produce their content every time they are requested to do so. So creating a !EntityTemplate, you supply a reference to a content producer, which effectively creates a repeatable entity. - There are no standard !ContentProducers in HttpComponents. To use this entity you will need to extend !ContentProducer and override the writeTo(OutputStream) method. Inside this method you will write the full content body to the output stream. + There are no standard !ContentProducers in HttpComponents. It's basically just a convenience interface to allow wrapping up complex logic into an entity. To use this entity you will need to create a class that implements !ContentProducer and override the writeTo(OutputStream) method. Inside this method you will write the full content body to the output stream. + + If you for instance made a HTTP server, you would serve static files with the FileEntity, but running CGI programs can be done with a ContentProducer, inside which you run the program and supply the content as it becomes available. This way you don't need to buffer it in a string and then use a StringEntity or ByteArrayEntity. Like I mentioned, a convenience class. + + {{{#!java numbers=off + ContentProducer myContentProducer = new ContentProducer() { + @Override + public void writeTo(OutputStream out) throws IOException + { + out.write("ContentProducer rocks!".getBytes()); + out.write(("Time requested: " + new Date()).getBytes()); + } + }; + HttpEntity myEntity = new EntityTemplate(myContentProducer); + }}} [[Anchor(FileEntity)]] === FileEntity === - ... To be completed ... + This entity is reads it's content body from a file. Since this is mostly used to stream large files of different types, you need to supply the content type of the file, for instance, sending a zip you would supply the content type "application/zip", for XML "application/xml". + + {{{#!java numbers=off + File staticFile = new File("/path/to/a-class-software/httpcore-4.0-beta1.jar"); + HttpEntity entity = new FileEntity(staticFile, "application/java-archive"); + }}} [[Anchor(HttpEntityWrapper)]] === HttpEntityWrapper === --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org