1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
43
44
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 }