1069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/*
2069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnRouteParams.java $
3069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Revision: 658785 $
4069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Date: 2008-05-21 10:47:40 -0700 (Wed, 21 May 2008) $
5069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
6069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ====================================================================
7069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
8069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  Licensed to the Apache Software Foundation (ASF) under one or more
9069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  contributor license agreements.  See the NOTICE file distributed with
10069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  this work for additional information regarding copyright ownership.
11069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  The ASF licenses this file to You under the Apache License, Version 2.0
12069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  (the "License"); you may not use this file except in compliance with
13069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  the License.  You may obtain a copy of the License at
14069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
15069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
16069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
17069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  Unless required by applicable law or agreed to in writing, software
18069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  distributed under the License is distributed on an "AS IS" BASIS,
19069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  See the License for the specific language governing permissions and
21069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *  limitations under the License.
22069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ====================================================================
23069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
24069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * This software consists of voluntary contributions made by many
25069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * individuals on behalf of the Apache Software Foundation.  For more
26069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * information on the Apache Software Foundation, please see
27069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <http://www.apache.org/>.
28069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
29069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */
30069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
31069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpackage org.apache.http.conn.params;
32069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
33069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
34069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport java.net.InetAddress;
35069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
36069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.HttpHost;
37069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.params.HttpParams;
38069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.conn.routing.HttpRoute;
39069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
40069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
41069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
42069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/**
43069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * An adaptor for accessing route related parameters in {@link HttpParams}.
44069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * See {@link ConnRoutePNames} for parameter name definitions.
45069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
46069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
47069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
48069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
49069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @version $Revision: 658785 $
50069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
51069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @since 4.0
52d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath *
53d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * @deprecated Please use {@link java.net.URL#openConnection} instead.
54d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
55d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath *     for further details.
56069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */
57d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath@Deprecated
58069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpublic class ConnRouteParams implements ConnRoutePNames {
59069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
60069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
61069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * A special value indicating "no host".
62069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * This relies on a nonsense scheme name to avoid conflicts
63069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * with actual hosts. Note that this is a <i>valid</i> host.
64069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
65069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public static final HttpHost NO_HOST =
66069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        new HttpHost("127.0.0.255", 0, "no-host");
67069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
68069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
69069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * A special value indicating "no route".
70069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * This is a route with {@link #NO_HOST} as the target.
71069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
72069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public static final HttpRoute NO_ROUTE = new HttpRoute(NO_HOST);
73069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
74069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
75069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /** Disabled default constructor. */
76069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    private ConnRouteParams() {
77069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        // no body
78069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
79069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
80069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
81069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
82069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY}
83069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * parameter value.
84069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link #NO_HOST} will be mapped to <code>null</code>,
85069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * to allow unsetting in a hierarchy.
86069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
87069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param params    the parameters in which to look up
88069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
89069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return  the default proxy set in the argument parameters, or
90069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *          <code>null</code> if not set
91069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
92069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public static HttpHost getDefaultProxy(HttpParams params) {
93069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (params == null) {
94069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new IllegalArgumentException("Parameters must not be null.");
95069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
96069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        HttpHost proxy = (HttpHost)
97069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            params.getParameter(DEFAULT_PROXY);
98069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if ((proxy != null) && NO_HOST.equals(proxy)) {
99069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            // value is explicitly unset
100069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            proxy = null;
101069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
102069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        return proxy;
103069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
104069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
105069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
106069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
107069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Sets the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY}
108069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * parameter value.
109069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
110069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param params    the parameters in which to set the value
111069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param proxy     the value to set, may be <code>null</code>.
112069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *                  Note that {@link #NO_HOST} will be mapped to
113069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *                  <code>null</code> by {@link #getDefaultProxy},
114069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *                  to allow for explicit unsetting in hierarchies.
115069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
116069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public static void setDefaultProxy(HttpParams params,
117069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                                             HttpHost proxy) {
118069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (params == null) {
119069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new IllegalArgumentException("Parameters must not be null.");
120069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
121069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        params.setParameter(DEFAULT_PROXY, proxy);
122069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
123069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
124069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
125069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
126069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Obtains the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE}
127069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * parameter value.
128069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * {@link #NO_ROUTE} will be mapped to <code>null</code>,
129069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * to allow unsetting in a hierarchy.
130069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
131069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param params    the parameters in which to look up
132069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
133069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return  the forced route set in the argument parameters, or
134069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *          <code>null</code> if not set
135069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
136069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public static HttpRoute getForcedRoute(HttpParams params) {
137069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (params == null) {
138069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new IllegalArgumentException("Parameters must not be null.");
139069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
140069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        HttpRoute route = (HttpRoute)
141069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            params.getParameter(FORCED_ROUTE);
142069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if ((route != null) && NO_ROUTE.equals(route)) {
143069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            // value is explicitly unset
144069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            route = null;
145069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
146069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        return route;
147069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
148069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
149069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
150069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
151069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Sets the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE}
152069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * parameter value.
153069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
154069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param params    the parameters in which to set the value
155069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param route     the value to set, may be <code>null</code>.
156069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *                  Note that {@link #NO_ROUTE} will be mapped to
157069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *                  <code>null</code> by {@link #getForcedRoute},
158069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *                  to allow for explicit unsetting in hierarchies.
159069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
160069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public static void setForcedRoute(HttpParams params,
161069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                                            HttpRoute route) {
162069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (params == null) {
163069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new IllegalArgumentException("Parameters must not be null.");
164069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
165069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        params.setParameter(FORCED_ROUTE, route);
166069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
167069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
168069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
169069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
170069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Obtains the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS}
171069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * parameter value.
172069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * There is no special value that would automatically be mapped to
173069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * <code>null</code>. You can use the wildcard address (0.0.0.0 for IPv4,
174069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * :: for IPv6) to override a specific local address in a hierarchy.
175069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
176069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param params    the parameters in which to look up
177069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
178069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return  the local address set in the argument parameters, or
179069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *          <code>null</code> if not set
180069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
181069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public static InetAddress getLocalAddress(HttpParams params) {
182069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (params == null) {
183069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new IllegalArgumentException("Parameters must not be null.");
184069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
185069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        InetAddress local = (InetAddress)
186069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            params.getParameter(LOCAL_ADDRESS);
187069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        // no explicit unsetting
188069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        return local;
189069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
190069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
191069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
192069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
193069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Sets the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS}
194069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * parameter value.
195069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
196069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param params    the parameters in which to set the value
197069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param local     the value to set, may be <code>null</code>
198069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
199069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public static void setLocalAddress(HttpParams params,
200069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                                             InetAddress local) {
201069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (params == null) {
202069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new IllegalArgumentException("Parameters must not be null.");
203069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
204069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        params.setParameter(LOCAL_ADDRESS, local);
205069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
206069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
207069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project}
208069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
209