• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • HttpComponents組件特性探究(3)

    發表于:2012-11-23來源:Csdn作者:fengjia10點擊數: 標簽:開源框架
    * header contains gzip (in any casing). * * @param httpResponse the resulting HttpResponse to check * @return whether the given response indicates a GZIP response */ protected boolean isGzipResponse(H

      * header contains "gzip" (in any casing).

      *

      * @param httpResponse the resulting HttpResponse to check

      * @return whether the given response indicates a GZIP response

      */

      protected boolean isGzipResponse(HttpResponse httpResponse) {

      Header encodingHeader = httpResponse.getFirstHeader(HTTP_HEADER_CONTENT_ENCODING);

      return (encodingHeader != null && encodingHeader.getValue() != null && encodingHeader

      .getValue().toLowerCase().contains(ENCODING_GZIP));

      }

      /**

      * Shutdown hook that closes the underlying

      * {@link org.apache.http.conn.ClientConnectionManager

      * ClientConnectionManager}'s connection pool, if any.

      */

      public void destroy() {

      getHttpClient().getConnectionManager().shutdown();

      }

      enum HttpMethod {

      GET,

      POST,

      HEAD,

      OPTIONS,

      PUT,

      DELETE,

      TRACE

      }

      }

      /**

      * @author von gosling 2012-3-2

      */

      public class HttpComponentsClientExecutor implements DisposableBean {

      private static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 100;

      private static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 5; //notice IE 6,7,8

      private static final int DEFAULT_CONN_TIMEOUT_MILLISECONDS = 5 * 1000;

      private static final int DEFAULT_READ_TIMEOUT_MILLISECONDS = 60 * 1000;

      private static final String HTTP_HEADER_CONTENT_ENCODING = "Content-Encoding";

      private static final String ENCODING_GZIP = "gzip";

      private HttpClient httpClient;

      /**

      * Create a new instance of the HttpComponentsClient with a default

      * {@link HttpClient} that uses a default

      * {@link org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager}.

      */

      public HttpComponentsClientExecutor() {

      SchemeRegistry schemeRegistry = new SchemeRegistry();

      schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));

      schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

      ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(

      schemeRegistry);

      connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);

      connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);

      this.httpClient = new DefaultHttpClient(connectionManager);

      setConnectTimeout(DEFAULT_CONN_TIMEOUT_MILLISECONDS);

      setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS);

      }

      /**

      * Create a new instance of the HttpComponentsClient with the given

      * {@link HttpClient} instance.

      *

      * @param httpClient the HttpClient instance to use for this request

      */

      public HttpComponentsClientExecutor(HttpClient httpClient) {

      Validate.notNull(httpClient, "HttpClient must not be null");

      //notice: if you want to custom exception recovery mechanism

      //you should provide an implementation of the HttpRequestRetryHandler interface.

      this.httpClient = httpClient;

      }

      /**

      * Set the {@code HttpClient} used by this request.

      */

      public void setHttpClient(HttpClient httpClient) {

      this.httpClient = httpClient;

      }

      /**

      * Return the {@code HttpClient} used by this request.

      */

      public HttpClient getHttpClient() {

      return this.httpClient;

      }

      /**

      * Set the connection timeout for the underlying HttpClient. A timeout value

      * of 0 specifies an infinite timeout.

      *

      * @param timeout the timeout value in milliseconds

      */

      public void setConnectTimeout(int timeout) {

      Validate.isTrue(timeout >= 0, "Timeout must be a non-negative value");

      getHttpClient().getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,

      timeout);

      }

      /**

      * Set the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout

      * for waiting for data or, put differently, a maximum period inactivity

      * between two consecutive data packets.A timeout value of 0 specifies an

      * infinite timeout.

      *

      * @param timeout the timeout value in milliseconds

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>