001/* 002 * ==================================================================== 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 * ==================================================================== 020 * 021 * This software consists of voluntary contributions made by many 022 * individuals on behalf of the Apache Software Foundation. For more 023 * information on the Apache Software Foundation, please see 024 * <http://www.apache.org/>. 025 * 026 */ 027 028package org.apache.http.client.params; 029 030import java.net.InetAddress; 031import java.util.Collection; 032 033import org.apache.http.HttpHost; 034import org.apache.http.auth.params.AuthPNames; 035import org.apache.http.client.config.RequestConfig; 036import org.apache.http.conn.params.ConnRoutePNames; 037import org.apache.http.params.CoreConnectionPNames; 038import org.apache.http.params.CoreProtocolPNames; 039import org.apache.http.params.HttpParams; 040 041/** 042 * @deprecated (4.3) provided for compatibility with {@link HttpParams}. Do not use. 043 * 044 * @since 4.3 045 */ 046@Deprecated 047public final class HttpClientParamConfig { 048 049 private HttpClientParamConfig() { 050 } 051 052 @SuppressWarnings("unchecked") 053 public static RequestConfig getRequestConfig(final HttpParams params) { 054 return getRequestConfig(params, RequestConfig.DEFAULT); 055 } 056 057 @SuppressWarnings("unchecked") 058 public static RequestConfig getRequestConfig(final HttpParams params, final RequestConfig defaultConfig) { 059 final RequestConfig.Builder builder = RequestConfig.copy(defaultConfig) 060 .setSocketTimeout(params.getIntParameter( 061 CoreConnectionPNames.SO_TIMEOUT, defaultConfig.getSocketTimeout())) 062 .setStaleConnectionCheckEnabled(params.getBooleanParameter( 063 CoreConnectionPNames.STALE_CONNECTION_CHECK, defaultConfig.isStaleConnectionCheckEnabled())) 064 .setConnectTimeout(params.getIntParameter( 065 CoreConnectionPNames.CONNECTION_TIMEOUT, defaultConfig.getConnectTimeout())) 066 .setExpectContinueEnabled(params.getBooleanParameter( 067 CoreProtocolPNames.USE_EXPECT_CONTINUE, defaultConfig.isExpectContinueEnabled())) 068 .setAuthenticationEnabled(params.getBooleanParameter( 069 ClientPNames.HANDLE_AUTHENTICATION, defaultConfig.isAuthenticationEnabled())) 070 .setCircularRedirectsAllowed(params.getBooleanParameter( 071 ClientPNames.ALLOW_CIRCULAR_REDIRECTS, defaultConfig.isCircularRedirectsAllowed())) 072 .setConnectionRequestTimeout((int) params.getLongParameter( 073 ClientPNames.CONN_MANAGER_TIMEOUT, defaultConfig.getConnectionRequestTimeout())) 074 .setMaxRedirects(params.getIntParameter( 075 ClientPNames.MAX_REDIRECTS, defaultConfig.getMaxRedirects())) 076 .setRedirectsEnabled(params.getBooleanParameter( 077 ClientPNames.HANDLE_REDIRECTS, defaultConfig.isRedirectsEnabled())) 078 .setRelativeRedirectsAllowed(!params.getBooleanParameter( 079 ClientPNames.REJECT_RELATIVE_REDIRECT, !defaultConfig.isRelativeRedirectsAllowed())); 080 081 final HttpHost proxy = (HttpHost) params.getParameter(ConnRoutePNames.DEFAULT_PROXY); 082 if (proxy != null) { 083 builder.setProxy(proxy); 084 } 085 final InetAddress localAddress = (InetAddress) params.getParameter(ConnRoutePNames.LOCAL_ADDRESS); 086 if (localAddress != null) { 087 builder.setLocalAddress(localAddress); 088 } 089 final Collection<String> targetAuthPrefs = (Collection<String>) params.getParameter(AuthPNames.TARGET_AUTH_PREF); 090 if (targetAuthPrefs != null) { 091 builder.setTargetPreferredAuthSchemes(targetAuthPrefs); 092 } 093 final Collection<String> proxySuthPrefs = (Collection<String>) params.getParameter(AuthPNames.PROXY_AUTH_PREF); 094 if (proxySuthPrefs != null) { 095 builder.setProxyPreferredAuthSchemes(proxySuthPrefs); 096 } 097 final String cookiePolicy = (String) params.getParameter(ClientPNames.COOKIE_POLICY); 098 if (cookiePolicy != null) { 099 builder.setCookieSpec(cookiePolicy); 100 } 101 return builder.build(); 102 } 103 104}