View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  package org.apache.http.client.params;
28  
29  import org.apache.http.annotation.Immutable;
30  import org.apache.http.client.config.RequestConfig;
31  import org.apache.http.params.HttpConnectionParams;
32  import org.apache.http.params.HttpParams;
33  import org.apache.http.util.Args;
34  
35  /**
36   * An adaptor for manipulating HTTP client parameters in {@link HttpParams}.
37   *
38   * @since 4.0
39   *
40   * @deprecated (4.3) use {@link RequestConfig}
41   */
42  @Deprecated
43  @Immutable
44  public class HttpClientParams {
45  
46      private HttpClientParams() {
47          super();
48      }
49  
50      public static boolean isRedirecting(final HttpParams params) {
51          Args.notNull(params, "HTTP parameters");
52          return params.getBooleanParameter
53              (ClientPNames.HANDLE_REDIRECTS, true);
54      }
55  
56      public static void setRedirecting(final HttpParams params, final boolean value) {
57          Args.notNull(params, "HTTP parameters");
58          params.setBooleanParameter
59              (ClientPNames.HANDLE_REDIRECTS, value);
60      }
61  
62      public static boolean isAuthenticating(final HttpParams params) {
63          Args.notNull(params, "HTTP parameters");
64          return params.getBooleanParameter
65              (ClientPNames.HANDLE_AUTHENTICATION, true);
66      }
67  
68      public static void setAuthenticating(final HttpParams params, final boolean value) {
69          Args.notNull(params, "HTTP parameters");
70          params.setBooleanParameter
71              (ClientPNames.HANDLE_AUTHENTICATION, value);
72      }
73  
74      public static String getCookiePolicy(final HttpParams params) {
75          Args.notNull(params, "HTTP parameters");
76          final String cookiePolicy = (String)
77              params.getParameter(ClientPNames.COOKIE_POLICY);
78          if (cookiePolicy == null) {
79              return CookiePolicy.BEST_MATCH;
80          }
81          return cookiePolicy;
82      }
83  
84      public static void setCookiePolicy(final HttpParams params, final String cookiePolicy) {
85          Args.notNull(params, "HTTP parameters");
86          params.setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
87      }
88  
89      /**
90       * Set the parameter {@code ClientPNames.CONN_MANAGER_TIMEOUT}.
91       *
92       * @since 4.2
93       */
94      public static void setConnectionManagerTimeout(final HttpParams params, final long timeout) {
95          Args.notNull(params, "HTTP parameters");
96          params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, timeout);
97      }
98  
99      /**
100      * Get the connectiion manager timeout value.
101      * This is defined by the parameter {@code ClientPNames.CONN_MANAGER_TIMEOUT}.
102      * Failing that it uses the parameter {@code CoreConnectionPNames.CONNECTION_TIMEOUT}
103      * which defaults to 0 if not defined.
104      *
105      * @since 4.2
106      * @return the timeout value
107      */
108     public static long getConnectionManagerTimeout(final HttpParams params) {
109         Args.notNull(params, "HTTP parameters");
110         final Long timeout = (Long) params.getParameter(ClientPNames.CONN_MANAGER_TIMEOUT);
111         if (timeout != null) {
112             return timeout.longValue();
113         }
114         return HttpConnectionParams.getConnectionTimeout(params);
115     }
116 
117 }