• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java $
3  * $Revision: 672969 $
4  * $Date: 2008-06-30 18:09:50 -0700 (Mon, 30 Jun 2008) $
5  *
6  * ====================================================================
7  * Licensed to the Apache Software Foundation (ASF) under one
8  * or more contributor license agreements.  See the NOTICE file
9  * distributed with this work for additional information
10  * regarding copyright ownership.  The ASF licenses this file
11  * to you under the Apache License, Version 2.0 (the
12  * "License"); you may not use this file except in compliance
13  * with 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,
18  * software distributed under the License is distributed on an
19  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20  * KIND, either express or implied.  See the License for the
21  * specific language governing permissions and limitations
22  * under the License.
23  * ====================================================================
24  *
25  * This software consists of voluntary contributions made by many
26  * individuals on behalf of the Apache Software Foundation.  For more
27  * information on the Apache Software Foundation, please see
28  * <http://www.apache.org/>.
29  *
30  */
31 
32 package org.apache.http.conn;
33 
34 import java.io.IOException;
35 import java.util.concurrent.TimeUnit;
36 
37 import javax.net.ssl.SSLSession;
38 
39 import org.apache.http.HttpClientConnection;
40 import org.apache.http.HttpInetConnection;
41 import org.apache.http.HttpHost;
42 import org.apache.http.params.HttpParams;
43 import org.apache.http.protocol.HttpContext;
44 
45 import org.apache.http.conn.routing.HttpRoute;
46 
47 
48 
49 /**
50  * A client-side connection with advanced connection logic.
51  * Instances are typically obtained from a connection manager.
52  *
53  * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
54  *
55  *
56  * <!-- empty lines to avoid svn diff problems -->
57  * @version   $Revision: 672969 $
58  *
59  * @since 4.0
60  *
61  * @deprecated Please use {@link java.net.URL#openConnection} instead.
62  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
63  *     for further details.
64  */
65 @Deprecated
66 public interface ManagedClientConnection extends
67     HttpClientConnection, HttpInetConnection, ConnectionReleaseTrigger {
68 
69 
70     /**
71      * Indicates whether this connection is secure.
72      * The return value is well-defined only while the connection is open.
73      * It may change even while the connection is open.
74      *
75      * @return  <code>true</code> if this connection is secure,
76      *          <code>false</code> otherwise
77      */
isSecure()78     boolean isSecure()
79         ;
80 
81 
82     /**
83      * Obtains the current route of this connection.
84      *
85      * @return  the route established so far, or
86      *          <code>null</code> if not connected
87      */
getRoute()88     HttpRoute getRoute()
89         ;
90 
91 
92     /**
93      * Obtains the SSL session of the underlying connection, if any.
94      * If this connection is open, and the underlying socket is an
95      * {@link javax.net.ssl.SSLSocket SSLSocket}, the SSL session of
96      * that socket is obtained. This is a potentially blocking operation.
97      * <br/>
98      * <b>Note:</b> Whether the underlying socket is an SSL socket
99      * can not necessarily be determined via {@link #isSecure}.
100      * Plain sockets may be considered secure, for example if they are
101      * connected to a known host in the same network segment.
102      * On the other hand, SSL sockets may be considered insecure,
103      * for example depending on the chosen cipher suite.
104      *
105      * @return  the underlying SSL session if available,
106      *          <code>null</code> otherwise
107      */
getSSLSession()108     SSLSession getSSLSession()
109         ;
110 
111 
112     /**
113      * Opens this connection according to the given route.
114      *
115      * @param route     the route along which to open. It will be opened to
116      *                  the first proxy if present, or directly to the target.
117      * @param context   the context for opening this connection
118      * @param params    the parameters for opening this connection
119      *
120      * @throws IOException      in case of a problem
121      */
open(HttpRoute route, HttpContext context, HttpParams params)122     void open(HttpRoute route, HttpContext context, HttpParams params)
123         throws IOException
124         ;
125 
126 
127     /**
128      * Indicates that a tunnel to the target has been established.
129      * The route is the one previously passed to {@link #open open}.
130      * Subsequently, {@link #layerProtocol layerProtocol} can be called
131      * to layer the TLS/SSL protocol on top of the tunnelled connection.
132      * <br/>
133      * <b>Note:</b> In HttpClient 3, a call to the corresponding method
134      * would automatically trigger the layering of the TLS/SSL protocol.
135      * This is not the case anymore, you can establish a tunnel without
136      * layering a new protocol over the connection.
137      *
138      * @param secure    <code>true</code> if the tunnel should be considered
139      *                  secure, <code>false</code> otherwise
140      * @param params    the parameters for tunnelling this connection
141      *
142      * @throws IOException  in case of a problem
143      */
tunnelTarget(boolean secure, HttpParams params)144     void tunnelTarget(boolean secure, HttpParams params)
145         throws IOException
146         ;
147 
148 
149     /**
150      * Indicates that a tunnel to an intermediate proxy has been established.
151      * This is used exclusively for so-called <i>proxy chains</i>, where
152      * a request has to pass through multiple proxies before reaching the
153      * target. In that case, all proxies but the last need to be tunnelled
154      * when establishing the connection. Tunnelling of the last proxy to the
155      * target is optional and would be indicated via {@link #tunnelTarget}.
156      *
157      * @param next      the proxy to which the tunnel was established.
158      *                  This is <i>not</i> the proxy <i>through</i> which
159      *                  the tunnel was established, but the new end point
160      *                  of the tunnel. The tunnel does <i>not</i> yet
161      *                  reach to the target, use {@link #tunnelTarget}
162      *                  to indicate an end-to-end tunnel.
163      * @param secure    <code>true</code> if the connection should be
164      *                  considered secure, <code>false</code> otherwise
165      * @param params    the parameters for tunnelling this connection
166      *
167      * @throws IOException  in case of a problem
168      */
tunnelProxy(HttpHost next, boolean secure, HttpParams params)169     void tunnelProxy(HttpHost next, boolean secure, HttpParams params)
170         throws IOException
171         ;
172 
173 
174     /**
175      * Layers a new protocol on top of a {@link #tunnelTarget tunnelled}
176      * connection. This is typically used to create a TLS/SSL connection
177      * through a proxy.
178      * The route is the one previously passed to {@link #open open}.
179      * It is not guaranteed that the layered connection is
180      * {@link #isSecure secure}.
181      *
182      * @param context   the context for layering on top of this connection
183      * @param params    the parameters for layering on top of this connection
184      *
185      * @throws IOException      in case of a problem
186      */
layerProtocol(HttpContext context, HttpParams params)187     void layerProtocol(HttpContext context, HttpParams params)
188         throws IOException
189         ;
190 
191 
192     /**
193      * Marks this connection as being in a reusable communication state.
194      * The checkpoints for reuseable communication states (in the absence
195      * of pipelining) are before sending a request and after receiving
196      * the response in it's entirety.
197      * The connection will automatically clear the checkpoint when
198      * used for communication. A call to this method indicates that
199      * the next checkpoint has been reached.
200      * <br/>
201      * A reusable communication state is necessary but not sufficient
202      * for the connection to be reused.
203      * A {@link #getRoute route} mismatch, the connection being closed,
204      * or other circumstances might prevent reuse.
205      */
markReusable()206     void markReusable()
207         ;
208 
209 
210     /**
211      * Marks this connection as not being in a reusable state.
212      * This can be used immediately before releasing this connection
213      * to prevent it's reuse. Reasons for preventing reuse include
214      * error conditions and the evaluation of a
215      * {@link org.apache.http.ConnectionReuseStrategy reuse strategy}.
216      * <br/>
217      * <b>Note:</b>
218      * It is <i>not</i> necessary to call here before writing to
219      * or reading from this connection. Communication attempts will
220      * automatically unmark the state as non-reusable. It can then
221      * be switched back using {@link #markReusable markReusable}.
222      */
unmarkReusable()223     void unmarkReusable()
224         ;
225 
226 
227     /**
228      * Indicates whether this connection is in a reusable communication state.
229      * See {@link #markReusable markReusable} and
230      * {@link #unmarkReusable unmarkReusable} for details.
231      *
232      * @return  <code>true</code> if this connection is marked as being in
233      *          a reusable communication state,
234      *          <code>false</code> otherwise
235      */
isMarkedReusable()236     boolean isMarkedReusable()
237         ;
238 
239     /**
240      * Assigns a state object to this connection. Connection managers may make
241      * use of the connection state when allocating persistent connections.
242      *
243      * @param state The state object
244      */
setState(Object state)245     void setState(Object state)
246         ;
247 
248     /**
249      * Returns the state object associated with this connection.
250      *
251      * @return The state object
252      */
getState()253     Object getState()
254         ;
255 
256     /**
257      * Sets the duration that this connection can remain idle before it is
258      * reused. The connection should not be used again if this time elapses. The
259      * idle duration must be reset after each request sent over this connection.
260      * The elapsed time starts counting when the connection is released, which
261      * is typically after the headers (and any response body, if present) is
262      * fully consumed.
263      */
setIdleDuration(long duration, TimeUnit unit)264     void setIdleDuration(long duration, TimeUnit unit);
265 
266 } // interface ManagedClientConnection
267