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/impl/conn/AbstractPoolEntry.java $ 3069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Revision: 658775 $ 4069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Date: 2008-05-21 10:30:45 -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.impl.conn; 32069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 33069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 34069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport java.io.IOException; 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.protocol.HttpContext; 39069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.conn.routing.HttpRoute; 40069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.conn.routing.RouteTracker; 41069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.conn.ClientConnectionOperator; 42069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.conn.OperatedClientConnection; 43069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 44069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 45069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 46069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/** 47069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * A pool entry for use by connection manager implementations. 48069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Pool entries work in conjunction with an 49069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * {@link AbstractClientConnAdapter adapter}. 50069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The adapter is handed out to applications that obtain a connection. 51069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The pool entry stores the underlying connection and tracks the 52069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * {@link HttpRoute route} established. 53069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The adapter delegates methods for establishing the route to 54069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * it's pool entry. 55069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <br/> 56069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * If the managed connections is released or revoked, the adapter 57069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * gets disconnected, but the pool entry still contains the 58069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * underlying connection and the established route. 59069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 60069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> 61069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:becke@u.washington.edu">Michael Becke</a> 62069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 63069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 64069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <!-- empty lines to avoid svn diff problems --> 65069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @version $Revision: 658775 $ 66069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 67069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @since 4.0 68d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * 69d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * @deprecated Please use {@link java.net.URL#openConnection} instead. 70d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a> 71d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * for further details. 72069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 73d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath@Deprecated 74069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpublic abstract class AbstractPoolEntry { 75069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 76069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** The connection operator. */ 77069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project protected final ClientConnectionOperator connOperator; 78069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 79069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** The underlying connection being pooled or used. */ 80069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project protected final OperatedClientConnection connection; 81069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 82069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** The route for which this entry gets allocated. */ 83069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project //@@@ currently accessed from connection manager(s) as attribute 84069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project //@@@ avoid that, derived classes should decide whether update is allowed 85069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project //@@@ SCCM: yes, TSCCM: no 86069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project protected volatile HttpRoute route; 87069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 88069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** Connection state object */ 89069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project protected volatile Object state; 90069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 91069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** The tracked route, or <code>null</code> before tracking starts. */ 92069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project protected volatile RouteTracker tracker; 93069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 94069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 95069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 96069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Creates a new pool entry. 97069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 98069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param connOperator the Connection Operator for this entry 99069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param route the planned route for the connection, 100069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * or <code>null</code> 101069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 102069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project protected AbstractPoolEntry(ClientConnectionOperator connOperator, 103069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project HttpRoute route) { 104069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project super(); 105069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (connOperator == null) { 106069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException("Connection operator may not be null"); 107069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 108069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.connOperator = connOperator; 109069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.connection = connOperator.createConnection(); 110069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.route = route; 111069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.tracker = null; 112069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 113069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 114069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 115069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Returns the state object associated with this pool entry. 116069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 117069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @return The state object 118069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 119069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public Object getState() { 120069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project return state; 121069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 122069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 123069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 124069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Assigns a state object to this pool entry. 125069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 126069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param state The state object 127069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 128069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public void setState(final Object state) { 129069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.state = state; 130069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 131069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 132069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 133069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Opens the underlying connection. 134069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 135069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param route the route along which to open the connection 136069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param context the context for opening the connection 137069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param params the parameters for opening the connection 138069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 139069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @throws IOException in case of a problem 140069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 141069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public void open(HttpRoute route, 142069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project HttpContext context, HttpParams params) 143069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throws IOException { 144069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 145069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (route == null) { 146069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 147069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Route must not be null."); 148069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 149069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project //@@@ is context allowed to be null? depends on operator? 150069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (params == null) { 151069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 152069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Parameters must not be null."); 153069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 154069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if ((this.tracker != null) && this.tracker.isConnected()) { 155069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalStateException("Connection already open."); 156069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 157069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 158069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // - collect the arguments 159069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // - call the operator 160069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // - update the tracking data 161069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // In this order, we can be sure that only a successful 162069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // opening of the connection will be tracked. 163069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 164069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project //@@@ verify route against planned route? 165069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 166069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.tracker = new RouteTracker(route); 167069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project final HttpHost proxy = route.getProxyHost(); 168069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 169069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project connOperator.openConnection 170069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project (this.connection, 171069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project (proxy != null) ? proxy : route.getTargetHost(), 172069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project route.getLocalAddress(), 173069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project context, params); 174069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 175069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project RouteTracker localTracker = tracker; // capture volatile 176069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 177069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // If this tracker was reset while connecting, 178069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // fail early. 179069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (localTracker == null) { 180069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IOException("Request aborted"); 181069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 182069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 183069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (proxy == null) { 184069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project localTracker.connectTarget(this.connection.isSecure()); 185069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } else { 186069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project localTracker.connectProxy(proxy, this.connection.isSecure()); 187069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 188069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 189069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } // open 190069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 191069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 192069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 193069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Tracks tunnelling of the connection to the target. 194069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The tunnel has to be established outside by sending a CONNECT 195069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * request to the (last) proxy. 196069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 197069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param secure <code>true</code> if the tunnel should be 198069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * considered secure, <code>false</code> otherwise 199069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param params the parameters for tunnelling the connection 200069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 201069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @throws IOException in case of a problem 202069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 203069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public void tunnelTarget(boolean secure, HttpParams params) 204069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throws IOException { 205069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 206069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (params == null) { 207069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 208069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Parameters must not be null."); 209069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 210069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 211069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project //@@@ check for proxy in planned route? 212069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if ((this.tracker == null) || !this.tracker.isConnected()) { 213069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalStateException("Connection not open."); 214069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 215069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.tracker.isTunnelled()) { 216069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalStateException 217069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Connection is already tunnelled."); 218069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 219069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 220069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // LOG.debug? 221069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 222069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.connection.update(null, tracker.getTargetHost(), 223069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project secure, params); 224069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.tracker.tunnelTarget(secure); 225069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 226069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } // tunnelTarget 227069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 228069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 229069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 230069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Tracks tunnelling of the connection to a chained proxy. 231069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * The tunnel has to be established outside by sending a CONNECT 232069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * request to the previous proxy. 233069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 234069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param next the proxy to which the tunnel was established. 235069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * See {@link org.apache.http.conn.ManagedClientConnection#tunnelProxy 236069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ManagedClientConnection.tunnelProxy} 237069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * for details. 238069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param secure <code>true</code> if the tunnel should be 239069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * considered secure, <code>false</code> otherwise 240069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param params the parameters for tunnelling the connection 241069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 242069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @throws IOException in case of a problem 243069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 244069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public void tunnelProxy(HttpHost next, boolean secure, HttpParams params) 245069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throws IOException { 246069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 247069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (next == null) { 248069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 249069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Next proxy must not be null."); 250069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 251069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (params == null) { 252069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 253069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Parameters must not be null."); 254069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 255069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 256069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project //@@@ check for proxy in planned route? 257069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if ((this.tracker == null) || !this.tracker.isConnected()) { 258069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalStateException("Connection not open."); 259069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 260069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 261069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // LOG.debug? 262069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 263069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.connection.update(null, next, secure, params); 264069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.tracker.tunnelProxy(next, secure); 265069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 266069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } // tunnelProxy 267069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 268069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 269069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 270069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Layers a protocol on top of an established tunnel. 271069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 272069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param context the context for layering 273069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @param params the parameters for layering 274069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 275069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @throws IOException in case of a problem 276069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 277069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public void layerProtocol(HttpContext context, HttpParams params) 278069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throws IOException { 279069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 280069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project //@@@ is context allowed to be null? depends on operator? 281069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (params == null) { 282069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalArgumentException 283069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Parameters must not be null."); 284069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 285069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 286069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if ((this.tracker == null) || !this.tracker.isConnected()) { 287069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalStateException("Connection not open."); 288069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 289069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (!this.tracker.isTunnelled()) { 290069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project //@@@ allow this? 291069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalStateException 292069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Protocol layering without a tunnel not supported."); 293069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 294069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project if (this.tracker.isLayered()) { 295069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project throw new IllegalStateException 296069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project ("Multiple protocol layering not supported."); 297069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 298069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 299069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // - collect the arguments 300069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // - call the operator 301069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // - update the tracking data 302069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // In this order, we can be sure that only a successful 303069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // layering on top of the connection will be tracked. 304069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 305069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project final HttpHost target = tracker.getTargetHost(); 306069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 307069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project connOperator.updateSecureConnection(this.connection, target, 308069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project context, params); 309069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 310069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project this.tracker.layerProtocol(this.connection.isSecure()); 311069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 312069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } // layerProtocol 313069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 314069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 315069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project /** 316069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Shuts down the entry. 317069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * 318069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * If {@link #open(HttpRoute, HttpContext, HttpParams)} is in progress, 319069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * this will cause that open to possibly throw an {@link IOException}. 320069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */ 321069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project protected void shutdownEntry() { 322069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project tracker = null; 323069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project } 324069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 325069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 326069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project} // class AbstractPoolEntry 327069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 328