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  
28  package org.apache.http.client.params;
29  
30  import java.net.InetAddress;
31  import java.util.Collection;
32  
33  import org.apache.http.HttpHost;
34  import org.apache.http.auth.params.AuthPNames;
35  import org.apache.http.client.config.RequestConfig;
36  import org.apache.http.conn.params.ConnRoutePNames;
37  import org.apache.http.params.CoreConnectionPNames;
38  import org.apache.http.params.CoreProtocolPNames;
39  import org.apache.http.params.HttpParams;
40  
41  /**
42   * @deprecated (4.3) provided for compatibility with {@link HttpParams}. Do not use.
43   *
44   * @since 4.3
45   */
46  @Deprecated
47  public final class HttpClientParamConfig {
48  
49      private HttpClientParamConfig() {
50      }
51  
52      @SuppressWarnings("unchecked")
53      public static RequestConfig getRequestConfig(final HttpParams params) {
54          return getRequestConfig(params, RequestConfig.DEFAULT);
55      }
56  
57      @SuppressWarnings("unchecked")
58      public static RequestConfig getRequesRequestConfigng class="jxr_keyword">final HttpParams params, final RequestConfig defaultConfig) {
59          final RequestConfig.Builder builder = RequestConfig.copy(defaultConfig)
60                  .setSocketTimeout(params.getIntParameter(
61                          CoreConnectionPNames.SO_TIMEOUT, defaultConfig.getSocketTimeout()))
62                  .setStaleConnectionCheckEnabled(params.getBooleanParameter(
63                          CoreConnectionPNames.STALE_CONNECTION_CHECK, defaultConfig.isStaleConnectionCheckEnabled()))
64                  .setConnectTimeout(params.getIntParameter(
65                          CoreConnectionPNames.CONNECTION_TIMEOUT, defaultConfig.getConnectTimeout()))
66                  .setExpectContinueEnabled(params.getBooleanParameter(
67                          CoreProtocolPNames.USE_EXPECT_CONTINUE, defaultConfig.isExpectContinueEnabled()))
68                  .setAuthenticationEnabled(params.getBooleanParameter(
69                          ClientPNames.HANDLE_AUTHENTICATION, defaultConfig.isAuthenticationEnabled()))
70                  .setCircularRedirectsAllowed(params.getBooleanParameter(
71                          ClientPNames.ALLOW_CIRCULAR_REDIRECTS, defaultConfig.isCircularRedirectsAllowed()))
72                  .setConnectionRequestTimeout((int) params.getLongParameter(
73                          ClientPNames.CONN_MANAGER_TIMEOUT, defaultConfig.getConnectionRequestTimeout()))
74                  .setMaxRedirects(params.getIntParameter(
75                          ClientPNames.MAX_REDIRECTS, defaultConfig.getMaxRedirects()))
76                  .setRedirectsEnabled(params.getBooleanParameter(
77                          ClientPNames.HANDLE_REDIRECTS, defaultConfig.isRedirectsEnabled()))
78                  .setRelativeRedirectsAllowed(!params.getBooleanParameter(
79                          ClientPNames.REJECT_RELATIVE_REDIRECT, !defaultConfig.isRelativeRedirectsAllowed()));
80  
81          final HttpHost proxy = (HttpHost) params.getParameter(ConnRoutePNames.DEFAULT_PROXY);
82          if (proxy != null) {
83              builder.setProxy(proxy);
84          }
85          final InetAddress localAddress = (InetAddress) params.getParameter(ConnRoutePNames.LOCAL_ADDRESS);
86          if (localAddress != null) {
87              builder.setLocalAddress(localAddress);
88          }
89          final Collection<String> targetAuthPrefs = (Collection<String>) params.getParameter(AuthPNames.TARGET_AUTH_PREF);
90          if (targetAuthPrefs != null) {
91              builder.setTargetPreferredAuthSchemes(targetAuthPrefs);
92          }
93          final Collection<String> proxySuthPrefs = (Collection<String>) params.getParameter(AuthPNames.PROXY_AUTH_PREF);
94          if (proxySuthPrefs != null) {
95              builder.setProxyPreferredAuthSchemes(proxySuthPrefs);
96          }
97          final String cookiePolicy = (String) params.getParameter(ClientPNames.COOKIE_POLICY);
98          if (cookiePolicy != null) {
99              builder.setCookieSpec(cookiePolicy);
100         }
101         return builder.build();
102     }
103 
104 }