Return-Path: Delivered-To: apmail-hc-dev-archive@www.apache.org Received: (qmail 4204 invoked from network); 31 Mar 2009 13:54:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 31 Mar 2009 13:54:23 -0000 Received: (qmail 11763 invoked by uid 500); 31 Mar 2009 13:54:23 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 11709 invoked by uid 500); 31 Mar 2009 13:54:22 -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 11698 invoked by uid 99); 31 Mar 2009 13:54:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Mar 2009 13:54:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO aurora.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Mar 2009 13:54:12 +0000 Received: from aurora.apache.org (localhost [127.0.0.1]) by aurora.apache.org (8.13.8+Sun/8.13.8) with ESMTP id n2VDrqkI027219 for ; Tue, 31 Mar 2009 13:53:52 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: Tue, 31 Mar 2009 13:53:52 -0000 Message-ID: <20090331135352.26893.76654@aurora.apache.org> Subject: [Httpcomponents Wiki] Update of "HttpClientTutorial" by OlegKalnichevski 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 OlegKalnichevski: http://wiki.apache.org/HttpComponents/HttpClientTutorial ------------------------------------------------------------------------------ }; byte[] response = httpclient.execute(httpget, handler); + }}} + + === HTTP execution context === + + Originally HTTP has been designed as a stateless, response-request oriented protocol. However, real world applications often need to be able to persist state information through several logically related request-response exchanges. In order to enable applications to maintain a processing state HttpClient allows HTTP requests to be executed within a particular execution context, referred to as HTTP context. Multiple logically related requests can participate in a logical session if the same context is reused between consecutive requests. HTTP context functions similarly to java.util.Map. It is simply a collection of arbitrary named values. Application can populate context attributes prior to a request execution or examine the context after the execution has been completed. + + In the course of HTTP request execution HttpClient adds the following attributes to the execution context: + + * 'http.connection' - HttpConnection instance representing the actual connection to the target server. + + * 'http.target_host' - HttpHost instance representing the connection target. + + * 'http.proxy_host' - HttpHost instance representing the connection proxy, if used. + + * 'http.request' - HttpRequest instance representing the actual HTTP request. + + * 'http.response' - HttpResponse instance representing the actual HTTP response. + + * 'http.request_sent' - Boolean object representing the flag indicating whether the actual request has been fully transmitted to the connection target. + + For instance, in order to determine the final redirect target, one can examine the value of the 'http.target_host' attribute after the request execution: + + {{{ + DefaultHttpClient httpclient = new DefaultHttpClient(); + + HttpContext localContext = new BasicHttpContext(); + HttpGet httpget = new HttpGet("http://www.google.com/"); + + HttpResponse response = httpclient.execute(httpget, localContext); + + HttpHost target = (HttpHost) localContext.getAttribute( + ExecutionContext.HTTP_TARGET_HOST); + + System.out.println("Final target: " + target); + + HttpEntity entity = response.getEntity(); + if (entity != null) { + entity.consumeContent(); + } + }}} + + stdout > + + {{{ + Final target: http://www.google.ch }}} === Exception handling === @@ -464, +509 @@ In some situations HTTP request execution fail to complete within the expected time frame due to high load on the target server or too many concurrent requests executed on the client side. In such cases it may be necessary to terminate the request prematurely and unblock the execution thread blocked in a I/O operation. HTTP requests being executed by HttpClient can be aborted at any stage of execution by invoking HttpUriRequest#abort method. This method is thread-safe and can be called from any thread. When an HTTP request is aborted its execution thread blocked in an I/O operation is guaranteed to unblock by throwing a InterruptedIOException - == HTTP execution context == - - Originally HTTP has been designed as a stateless, response-request oriented protocol. However, real world applications often need to be able to persist state information through several logically related request-response exchanges. In order to enable applications to maintain a processing state HttpClient allows HTTP requests to be executed within a particular execution context, referred to as HTTP context. Multiple logically related requests can participate in a logical session if the same context is reused between consecutive requests. - - HTTP context functions similarly to java.util.Map. It is simply a collection of arbitrary named values. Application can populate context attributes prior to a request execution or examine the context after the execution has been completed. - - In the course of HTTP request execution HttpClient adds the following attributes to the execution context: - - * '''http.connection''' - HttpConnection instance representing the actual connection to the target server. - - * '''http.target_host''' - HttpHost instance representing the connection target. - - * '''http.proxy_host''' - HttpHost instance representing the connection proxy, if used. - - * '''http.request''' - HttpRequest instance representing the actual HTTP request. - - * '''http.response''' - HttpResponse instance representing the actual HTTP response. - - * '''http.request_sent''' - Boolean object representing the flag indicating whether the actual request has been fully transmitted to the connection target. - == HTTP protocol interceptors == HTTP protocol customization using custom protocol interceptors --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org