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