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.params.HttpConnectionParams;
30  import org.apache.http.params.HttpParams;
31  import org.apache.http.util.Args;
32  
33  /**
34   * An adaptor for manipulating HTTP client parameters in {@link HttpParams}.
35   *
36   * @since 4.0
37   *
38   * @deprecated (4.3) use {@link org.apache.http.client.config.RequestConfig}
39   */
40  @Deprecated
41  public class HttpClientParams {
42  
43      private HttpClientParams() {
44          super();
45      }
46  
47      public static boolean isRedirecting(final HttpParams params) {
48          Args.notNull(params, "HTTP parameters");
49          return params.getBooleanParameter
50              (ClientPNames.HANDLE_REDIRECTS, true);
51      }
52  
53      public static void setRedirecting(final HttpParams params, final boolean value) {
54          Args.notNull(params, "HTTP parameters");
55          params.setBooleanParameter
56              (ClientPNames.HANDLE_REDIRECTS, value);
57      }
58  
59      public static boolean isAuthenticating(final HttpParams params) {
60          Args.notNull(params, "HTTP parameters");
61          return params.getBooleanParameter
62              (ClientPNames.HANDLE_AUTHENTICATION, true);
63      }
64  
65      public static void setAuthenticating(final HttpParams params, final boolean value) {
66          Args.notNull(params, "HTTP parameters");
67          params.setBooleanParameter
68              (ClientPNames.HANDLE_AUTHENTICATION, value);
69      }
70  
71      public static String getCookiePolicy(final HttpParams params) {
72          Args.notNull(params, "HTTP parameters");
73          final String cookiePolicy = (String)
74              params.getParameter(ClientPNames.COOKIE_POLICY);
75          if (cookiePolicy == null) {
76              return CookiePolicy.BEST_MATCH;
77          }
78          return cookiePolicy;
79      }
80  
81      public static void setCookiePolicy(final HttpParams params, final String cookiePolicy) {
82          Args.notNull(params, "HTTP parameters");
83          params.setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
84      }
85  
86      /**
87       * Set the parameter {@code ClientPNames.CONN_MANAGER_TIMEOUT}.
88       *
89       * @since 4.2
90       */
91      public static void setConnectionManagerTimeout(final HttpParams params, final long timeout) {
92          Args.notNull(params, "HTTP parameters");
93          params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, timeout);
94      }
95  
96      /**
97       * Get the connectiion manager timeout value.
98       * This is defined by the parameter {@code ClientPNames.CONN_MANAGER_TIMEOUT}.
99       * Failing that it uses the parameter {@code CoreConnectionPNames.CONNECTION_TIMEOUT}
100      * which defaults to 0 if not defined.
101      *
102      * @since 4.2
103      * @return the timeout value
104      */
105     public static long getConnectionManagerTimeout(final HttpParams params) {
106         Args.notNull(params, "HTTP parameters");
107         final Long timeout = (Long) params.getParameter(ClientPNames.CONN_MANAGER_TIMEOUT);
108         if (timeout != null) {
109             return timeout.longValue();
110         }
111         return HttpConnectionParams.getConnectionTimeout(params);
112     }
113 
114 }