1 /* 2 * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnRouteParams.java $ 3 * $Revision: 658785 $ 4 * $Date: 2008-05-21 10:47:40 -0700 (Wed, 21 May 2008) $ 5 * 6 * ==================================================================== 7 * 8 * Licensed to the Apache Software Foundation (ASF) under one or more 9 * contributor license agreements. See the NOTICE file distributed with 10 * this work for additional information regarding copyright ownership. 11 * The ASF licenses this file to You under the Apache License, Version 2.0 12 * (the "License"); you may not use this file except in compliance with 13 * the License. You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, software 18 * distributed under the License is distributed on an "AS IS" BASIS, 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 * See the License for the specific language governing permissions and 21 * limitations under the License. 22 * ==================================================================== 23 * 24 * This software consists of voluntary contributions made by many 25 * individuals on behalf of the Apache Software Foundation. For more 26 * information on the Apache Software Foundation, please see 27 * <http://www.apache.org/>. 28 * 29 */ 30 31 package org.apache.http.conn.params; 32 33 34 import java.net.InetAddress; 35 36 import org.apache.http.HttpHost; 37 import org.apache.http.params.HttpParams; 38 import org.apache.http.conn.routing.HttpRoute; 39 40 41 42 /** 43 * An adaptor for accessing route related parameters in {@link HttpParams}. 44 * See {@link ConnRoutePNames} for parameter name definitions. 45 * 46 * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> 47 * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> 48 * 49 * @version $Revision: 658785 $ 50 * 51 * @since 4.0 52 * 53 * @deprecated Please use {@link java.net.URL#openConnection} instead. 54 * Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a> 55 * for further details. 56 */ 57 @Deprecated 58 public class ConnRouteParams implements ConnRoutePNames { 59 60 /** 61 * A special value indicating "no host". 62 * This relies on a nonsense scheme name to avoid conflicts 63 * with actual hosts. Note that this is a <i>valid</i> host. 64 */ 65 public static final HttpHost NO_HOST = 66 new HttpHost("127.0.0.255", 0, "no-host"); 67 68 /** 69 * A special value indicating "no route". 70 * This is a route with {@link #NO_HOST} as the target. 71 */ 72 public static final HttpRoute NO_ROUTE = new HttpRoute(NO_HOST); 73 74 75 /** Disabled default constructor. */ ConnRouteParams()76 private ConnRouteParams() { 77 // no body 78 } 79 80 81 /** 82 * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} 83 * parameter value. 84 * {@link #NO_HOST} will be mapped to <code>null</code>, 85 * to allow unsetting in a hierarchy. 86 * 87 * @param params the parameters in which to look up 88 * 89 * @return the default proxy set in the argument parameters, or 90 * <code>null</code> if not set 91 */ getDefaultProxy(HttpParams params)92 public static HttpHost getDefaultProxy(HttpParams params) { 93 if (params == null) { 94 throw new IllegalArgumentException("Parameters must not be null."); 95 } 96 HttpHost proxy = (HttpHost) 97 params.getParameter(DEFAULT_PROXY); 98 if ((proxy != null) && NO_HOST.equals(proxy)) { 99 // value is explicitly unset 100 proxy = null; 101 } 102 return proxy; 103 } 104 105 106 /** 107 * Sets the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} 108 * parameter value. 109 * 110 * @param params the parameters in which to set the value 111 * @param proxy the value to set, may be <code>null</code>. 112 * Note that {@link #NO_HOST} will be mapped to 113 * <code>null</code> by {@link #getDefaultProxy}, 114 * to allow for explicit unsetting in hierarchies. 115 */ setDefaultProxy(HttpParams params, HttpHost proxy)116 public static void setDefaultProxy(HttpParams params, 117 HttpHost proxy) { 118 if (params == null) { 119 throw new IllegalArgumentException("Parameters must not be null."); 120 } 121 params.setParameter(DEFAULT_PROXY, proxy); 122 } 123 124 125 /** 126 * Obtains the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE} 127 * parameter value. 128 * {@link #NO_ROUTE} will be mapped to <code>null</code>, 129 * to allow unsetting in a hierarchy. 130 * 131 * @param params the parameters in which to look up 132 * 133 * @return the forced route set in the argument parameters, or 134 * <code>null</code> if not set 135 */ getForcedRoute(HttpParams params)136 public static HttpRoute getForcedRoute(HttpParams params) { 137 if (params == null) { 138 throw new IllegalArgumentException("Parameters must not be null."); 139 } 140 HttpRoute route = (HttpRoute) 141 params.getParameter(FORCED_ROUTE); 142 if ((route != null) && NO_ROUTE.equals(route)) { 143 // value is explicitly unset 144 route = null; 145 } 146 return route; 147 } 148 149 150 /** 151 * Sets the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE} 152 * parameter value. 153 * 154 * @param params the parameters in which to set the value 155 * @param route the value to set, may be <code>null</code>. 156 * Note that {@link #NO_ROUTE} will be mapped to 157 * <code>null</code> by {@link #getForcedRoute}, 158 * to allow for explicit unsetting in hierarchies. 159 */ setForcedRoute(HttpParams params, HttpRoute route)160 public static void setForcedRoute(HttpParams params, 161 HttpRoute route) { 162 if (params == null) { 163 throw new IllegalArgumentException("Parameters must not be null."); 164 } 165 params.setParameter(FORCED_ROUTE, route); 166 } 167 168 169 /** 170 * Obtains the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS} 171 * parameter value. 172 * There is no special value that would automatically be mapped to 173 * <code>null</code>. You can use the wildcard address (0.0.0.0 for IPv4, 174 * :: for IPv6) to override a specific local address in a hierarchy. 175 * 176 * @param params the parameters in which to look up 177 * 178 * @return the local address set in the argument parameters, or 179 * <code>null</code> if not set 180 */ getLocalAddress(HttpParams params)181 public static InetAddress getLocalAddress(HttpParams params) { 182 if (params == null) { 183 throw new IllegalArgumentException("Parameters must not be null."); 184 } 185 InetAddress local = (InetAddress) 186 params.getParameter(LOCAL_ADDRESS); 187 // no explicit unsetting 188 return local; 189 } 190 191 192 /** 193 * Sets the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS} 194 * parameter value. 195 * 196 * @param params the parameters in which to set the value 197 * @param local the value to set, may be <code>null</code> 198 */ setLocalAddress(HttpParams params, InetAddress local)199 public static void setLocalAddress(HttpParams params, 200 InetAddress local) { 201 if (params == null) { 202 throw new IllegalArgumentException("Parameters must not be null."); 203 } 204 params.setParameter(LOCAL_ADDRESS, local); 205 } 206 207 } 208 209