Return-Path: Delivered-To: apmail-hc-commits-archive@www.apache.org Received: (qmail 66908 invoked from network); 5 Jan 2011 14:16:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Jan 2011 14:16:33 -0000 Received: (qmail 60209 invoked by uid 500); 5 Jan 2011 14:16:33 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 60156 invoked by uid 500); 5 Jan 2011 14:16:32 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 60149 invoked by uid 99); 5 Jan 2011 14:16:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Jan 2011 14:16:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Jan 2011 14:16:30 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1E9C32388A39; Wed, 5 Jan 2011 14:16:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1055464 - in /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http: client/protocol/ conn/ impl/client/ Date: Wed, 05 Jan 2011 14:16:08 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110105141609.1E9C32388A39@eris.apache.org> Author: olegk Date: Wed Jan 5 14:16:08 2011 New Revision: 1055464 URL: http://svn.apache.org/viewvc?rev=1055464&view=rev Log: Use special HttpRoutedConnection interafce to access route details in the protocol level classes, as ManagedClientConnection interface is blocking I/O model specific Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/HttpRoutedConnection.java - copied, changed from r1055401, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?rev=1055464&r1=1055463&r2=1055464&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java Wed Jan 5 14:16:08 2011 @@ -47,7 +47,8 @@ import org.apache.http.ProtocolException import org.apache.http.client.CookieStore; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.params.HttpClientParams; -import org.apache.http.conn.ManagedClientConnection; +import org.apache.http.conn.HttpRoutedConnection; +import org.apache.http.conn.routing.HttpRoute; import org.apache.http.cookie.Cookie; import org.apache.http.cookie.CookieOrigin; import org.apache.http.cookie.CookieSpec; @@ -118,7 +119,7 @@ public class RequestAddCookies implement } // Obtain the client connection (required) - ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute( + HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute( ExecutionContext.HTTP_CONNECTION); if (conn == null) { throw new IllegalStateException("Client connection not specified in HTTP context"); @@ -144,7 +145,21 @@ public class RequestAddCookies implement String hostName = targetHost.getHostName(); int port = targetHost.getPort(); if (port < 0) { - port = conn.getRemotePort(); + HttpRoute route = conn.getRoute(); + if (route.getHopCount() == 1) { + port = conn.getRemotePort(); + } else { + // Target port will be selected by the proxy. + // Use conventional ports for known schemes + String scheme = targetHost.getSchemeName(); + if (scheme.equalsIgnoreCase("http")) { + port = 80; + } else if (scheme.equalsIgnoreCase("https")) { + port = 443; + } else { + port = 0; + } + } } CookieOrigin cookieOrigin = new CookieOrigin( Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java?rev=1055464&r1=1055463&r2=1055464&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestClientConnControl.java Wed Jan 5 14:16:08 2011 @@ -34,7 +34,7 @@ import org.apache.http.annotation.Immuta import org.apache.http.HttpException; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; -import org.apache.http.conn.ManagedClientConnection; +import org.apache.http.conn.HttpRoutedConnection; import org.apache.http.conn.routing.HttpRoute; import org.apache.http.protocol.ExecutionContext; import org.apache.http.protocol.HTTP; @@ -69,7 +69,7 @@ public class RequestClientConnControl im } // Obtain the client connection (required) - ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute( + HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute( ExecutionContext.HTTP_CONNECTION); if (conn == null) { throw new IllegalStateException("Client connection not specified in HTTP context"); Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/HttpRoutedConnection.java (from r1055401, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java) URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/HttpRoutedConnection.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/HttpRoutedConnection.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java&r1=1055401&r2=1055464&rev=1055464&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/HttpRoutedConnection.java Wed Jan 5 14:16:08 2011 @@ -27,27 +27,17 @@ package org.apache.http.conn; -import java.io.IOException; -import java.util.concurrent.TimeUnit; - import javax.net.ssl.SSLSession; -import org.apache.http.HttpClientConnection; import org.apache.http.HttpInetConnection; -import org.apache.http.HttpHost; -import org.apache.http.params.HttpParams; -import org.apache.http.protocol.HttpContext; - import org.apache.http.conn.routing.HttpRoute; /** - * A client-side connection with advanced connection logic. - * Instances are typically obtained from a connection manager. + * Interface to access routing information of a client side connection. * - * @since 4.0 + * @since 4.1 */ -public interface ManagedClientConnection extends - HttpClientConnection, HttpInetConnection, ConnectionReleaseTrigger { +public interface HttpRoutedConnection extends HttpInetConnection { /** * Indicates whether this connection is secure. @@ -85,143 +75,4 @@ public interface ManagedClientConnection */ SSLSession getSSLSession(); - /** - * Opens this connection according to the given route. - * - * @param route the route along which to open. It will be opened to - * the first proxy if present, or directly to the target. - * @param context the context for opening this connection - * @param params the parameters for opening this connection - * - * @throws IOException in case of a problem - */ - void open(HttpRoute route, HttpContext context, HttpParams params) - throws IOException; - - /** - * Indicates that a tunnel to the target has been established. - * The route is the one previously passed to {@link #open open}. - * Subsequently, {@link #layerProtocol layerProtocol} can be called - * to layer the TLS/SSL protocol on top of the tunnelled connection. - *
- * Note: In HttpClient 3, a call to the corresponding method - * would automatically trigger the layering of the TLS/SSL protocol. - * This is not the case anymore, you can establish a tunnel without - * layering a new protocol over the connection. - * - * @param secure true if the tunnel should be considered - * secure, false otherwise - * @param params the parameters for tunnelling this connection - * - * @throws IOException in case of a problem - */ - void tunnelTarget(boolean secure, HttpParams params) - throws IOException; - - /** - * Indicates that a tunnel to an intermediate proxy has been established. - * This is used exclusively for so-called proxy chains, where - * a request has to pass through multiple proxies before reaching the - * target. In that case, all proxies but the last need to be tunnelled - * when establishing the connection. Tunnelling of the last proxy to the - * target is optional and would be indicated via {@link #tunnelTarget}. - * - * @param next the proxy to which the tunnel was established. - * This is not the proxy through which - * the tunnel was established, but the new end point - * of the tunnel. The tunnel does not yet - * reach to the target, use {@link #tunnelTarget} - * to indicate an end-to-end tunnel. - * @param secure true if the connection should be - * considered secure, false otherwise - * @param params the parameters for tunnelling this connection - * - * @throws IOException in case of a problem - */ - void tunnelProxy(HttpHost next, boolean secure, HttpParams params) - throws IOException; - - /** - * Layers a new protocol on top of a {@link #tunnelTarget tunnelled} - * connection. This is typically used to create a TLS/SSL connection - * through a proxy. - * The route is the one previously passed to {@link #open open}. - * It is not guaranteed that the layered connection is - * {@link #isSecure secure}. - * - * @param context the context for layering on top of this connection - * @param params the parameters for layering on top of this connection - * - * @throws IOException in case of a problem - */ - void layerProtocol(HttpContext context, HttpParams params) - throws IOException; - - /** - * Marks this connection as being in a reusable communication state. - * The checkpoints for reuseable communication states (in the absence - * of pipelining) are before sending a request and after receiving - * the response in its entirety. - * The connection will automatically clear the checkpoint when - * used for communication. A call to this method indicates that - * the next checkpoint has been reached. - *
- * A reusable communication state is necessary but not sufficient - * for the connection to be reused. - * A {@link #getRoute route} mismatch, the connection being closed, - * or other circumstances might prevent reuse. - */ - void markReusable(); - - /** - * Marks this connection as not being in a reusable state. - * This can be used immediately before releasing this connection - * to prevent its reuse. Reasons for preventing reuse include - * error conditions and the evaluation of a - * {@link org.apache.http.ConnectionReuseStrategy reuse strategy}. - *
- * Note: - * It is not necessary to call here before writing to - * or reading from this connection. Communication attempts will - * automatically unmark the state as non-reusable. It can then - * be switched back using {@link #markReusable markReusable}. - */ - void unmarkReusable(); - - /** - * Indicates whether this connection is in a reusable communication state. - * See {@link #markReusable markReusable} and - * {@link #unmarkReusable unmarkReusable} for details. - * - * @return true if this connection is marked as being in - * a reusable communication state, - * false otherwise - */ - boolean isMarkedReusable(); - - /** - * Assigns a state object to this connection. Connection managers may make - * use of the connection state when allocating persistent connections. - * - * @param state The state object - */ - void setState(Object state); - - /** - * Returns the state object associated with this connection. - * - * @return The state object - */ - Object getState(); - - /** - * Sets the duration that this connection can remain idle before it is - * reused. The connection should not be used again if this time elapses. The - * idle duration must be reset after each request sent over this connection. - * The elapsed time starts counting when the connection is released, which - * is typically after the headers (and any response body, if present) is - * fully consumed. - */ - void setIdleDuration(long duration, TimeUnit unit); - } Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java?rev=1055464&r1=1055463&r2=1055464&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ManagedClientConnection.java Wed Jan 5 14:16:08 2011 @@ -33,7 +33,6 @@ import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLSession; import org.apache.http.HttpClientConnection; -import org.apache.http.HttpInetConnection; import org.apache.http.HttpHost; import org.apache.http.params.HttpParams; import org.apache.http.protocol.HttpContext; @@ -47,7 +46,7 @@ import org.apache.http.conn.routing.Http * @since 4.0 */ public interface ManagedClientConnection extends - HttpClientConnection, HttpInetConnection, ConnectionReleaseTrigger { + HttpClientConnection, HttpRoutedConnection, ConnectionReleaseTrigger { /** * Indicates whether this connection is secure. Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java?rev=1055464&r1=1055463&r2=1055464&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java Wed Jan 5 14:16:08 2011 @@ -37,7 +37,7 @@ import org.apache.http.auth.AuthState; import org.apache.http.auth.Credentials; import org.apache.http.client.UserTokenHandler; import org.apache.http.client.protocol.ClientContext; -import org.apache.http.conn.ManagedClientConnection; +import org.apache.http.conn.HttpRoutedConnection; import org.apache.http.protocol.ExecutionContext; import org.apache.http.protocol.HttpContext; @@ -74,7 +74,7 @@ public class DefaultUserTokenHandler imp } if (userPrincipal == null) { - ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute( + HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute( ExecutionContext.HTTP_CONNECTION); if (conn.isOpen()) { SSLSession sslsession = conn.getSSLSession();