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.conn; 029 030import java.io.IOException; 031import java.util.concurrent.TimeUnit; 032 033import javax.net.ssl.SSLSession; 034 035import org.apache.http.HttpClientConnection; 036import org.apache.http.HttpHost; 037import org.apache.http.conn.routing.HttpRoute; 038import org.apache.http.params.HttpParams; 039import org.apache.http.protocol.HttpContext; 040 041/** 042 * A client-side connection with advanced connection logic. 043 * Instances are typically obtained from a connection manager. 044 * 045 * @since 4.0 046 * 047 * @deprecated (4.3) replaced by {@link HttpClientConnectionManager}. 048 */ 049@Deprecated 050public interface ManagedClientConnection extends 051 HttpClientConnection, HttpRoutedConnection, ManagedHttpClientConnection, ConnectionReleaseTrigger { 052 053 /** 054 * Indicates whether this connection is secure. 055 * The return value is well-defined only while the connection is open. 056 * It may change even while the connection is open. 057 * 058 * @return {@code true} if this connection is secure, 059 * {@code false} otherwise 060 */ 061 @Override 062 boolean isSecure(); 063 064 /** 065 * Obtains the current route of this connection. 066 * 067 * @return the route established so far, or 068 * {@code null} if not connected 069 */ 070 @Override 071 HttpRoute getRoute(); 072 073 /** 074 * Obtains the SSL session of the underlying connection, if any. 075 * If this connection is open, and the underlying socket is an 076 * {@link javax.net.ssl.SSLSocket SSLSocket}, the SSL session of 077 * that socket is obtained. This is a potentially blocking operation. 078 * <p> 079 * <b>Note:</b> Whether the underlying socket is an SSL socket 080 * can not necessarily be determined via {@link #isSecure}. 081 * Plain sockets may be considered secure, for example if they are 082 * connected to a known host in the same network segment. 083 * On the other hand, SSL sockets may be considered insecure, 084 * for example depending on the chosen cipher suite. 085 * </p> 086 * 087 * @return the underlying SSL session if available, 088 * {@code null} otherwise 089 */ 090 @Override 091 SSLSession getSSLSession(); 092 093 /** 094 * Opens this connection according to the given route. 095 * 096 * @param route the route along which to open. It will be opened to 097 * the first proxy if present, or directly to the target. 098 * @param context the context for opening this connection 099 * @param params the parameters for opening this connection 100 * 101 * @throws IOException in case of a problem 102 */ 103 void open(HttpRoute route, HttpContext context, HttpParams params) 104 throws IOException; 105 106 /** 107 * Indicates that a tunnel to the target has been established. 108 * The route is the one previously passed to {@link #open open}. 109 * Subsequently, {@link #layerProtocol layerProtocol} can be called 110 * to layer the TLS/SSL protocol on top of the tunnelled connection. 111 * <p> 112 * <b>Note:</b> In HttpClient 3, a call to the corresponding method 113 * would automatically trigger the layering of the TLS/SSL protocol. 114 * This is not the case anymore, you can establish a tunnel without 115 * layering a new protocol over the connection. 116 * </p> 117 * 118 * @param secure {@code true} if the tunnel should be considered 119 * secure, {@code false} otherwise 120 * @param params the parameters for tunnelling this connection 121 * 122 * @throws IOException in case of a problem 123 */ 124 void tunnelTarget(boolean secure, HttpParams params) 125 throws IOException; 126 127 /** 128 * Indicates that a tunnel to an intermediate proxy has been established. 129 * This is used exclusively for so-called <i>proxy chains</i>, where 130 * a request has to pass through multiple proxies before reaching the 131 * target. In that case, all proxies but the last need to be tunnelled 132 * when establishing the connection. Tunnelling of the last proxy to the 133 * target is optional and would be indicated via {@link #tunnelTarget}. 134 * 135 * @param next the proxy to which the tunnel was established. 136 * This is <i>not</i> the proxy <i>through</i> which 137 * the tunnel was established, but the new end point 138 * of the tunnel. The tunnel does <i>not</i> yet 139 * reach to the target, use {@link #tunnelTarget} 140 * to indicate an end-to-end tunnel. 141 * @param secure {@code true} if the connection should be 142 * considered secure, {@code false} otherwise 143 * @param params the parameters for tunnelling this connection 144 * 145 * @throws IOException in case of a problem 146 */ 147 void tunnelProxy(HttpHost next, boolean secure, HttpParams params) 148 throws IOException; 149 150 /** 151 * Layers a new protocol on top of a {@link #tunnelTarget tunnelled} 152 * connection. This is typically used to create a TLS/SSL connection 153 * through a proxy. 154 * The route is the one previously passed to {@link #open open}. 155 * It is not guaranteed that the layered connection is 156 * {@link #isSecure secure}. 157 * 158 * @param context the context for layering on top of this connection 159 * @param params the parameters for layering on top of this connection 160 * 161 * @throws IOException in case of a problem 162 */ 163 void layerProtocol(HttpContext context, HttpParams params) 164 throws IOException; 165 166 /** 167 * Marks this connection as being in a reusable communication state. 168 * The checkpoints for reuseable communication states (in the absence 169 * of pipelining) are before sending a request and after receiving 170 * the response in its entirety. 171 * The connection will automatically clear the checkpoint when 172 * used for communication. A call to this method indicates that 173 * the next checkpoint has been reached. 174 * <p> 175 * A reusable communication state is necessary but not sufficient 176 * for the connection to be reused. 177 * A {@link #getRoute route} mismatch, the connection being closed, 178 * or other circumstances might prevent reuse. 179 * </p> 180 */ 181 void markReusable(); 182 183 /** 184 * Marks this connection as not being in a reusable state. 185 * This can be used immediately before releasing this connection 186 * to prevent its reuse. Reasons for preventing reuse include 187 * error conditions and the evaluation of a 188 * {@link org.apache.http.ConnectionReuseStrategy reuse strategy}. 189 * <p> 190 * <b>Note:</b> 191 * It is <i>not</i> necessary to call here before writing to 192 * or reading from this connection. Communication attempts will 193 * automatically unmark the state as non-reusable. It can then 194 * be switched back using {@link #markReusable markReusable}. 195 * </p> 196 */ 197 void unmarkReusable(); 198 199 /** 200 * Indicates whether this connection is in a reusable communication state. 201 * See {@link #markReusable markReusable} and 202 * {@link #unmarkReusable unmarkReusable} for details. 203 * 204 * @return {@code true} if this connection is marked as being in 205 * a reusable communication state, 206 * {@code false} otherwise 207 */ 208 boolean isMarkedReusable(); 209 210 /** 211 * Assigns a state object to this connection. Connection managers may make 212 * use of the connection state when allocating persistent connections. 213 * 214 * @param state The state object 215 */ 216 void setState(Object state); 217 218 /** 219 * Returns the state object associated with this connection. 220 * 221 * @return The state object 222 */ 223 Object getState(); 224 225 /** 226 * Sets the duration that this connection can remain idle before it is 227 * reused. The connection should not be used again if this time elapses. The 228 * idle duration must be reset after each request sent over this connection. 229 * The elapsed time starts counting when the connection is released, which 230 * is typically after the headers (and any response body, if present) is 231 * fully consumed. 232 */ 233 void setIdleDuration(long duration, TimeUnit unit); 234 235}