Replaced HttpRoutedConnection with HttpSSLConnection interface

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1371171 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2012-08-09 11:42:19 +00:00
parent 2fa4b6b854
commit 320fae656f
5 changed files with 63 additions and 13 deletions

View File

@ -115,12 +115,4 @@ public interface ClientContext {
*/
public static final String USER_TOKEN = "http.user-token";
/**
* Attribute name of a {@link javax.net.SSLSession} object that represents
* the actual SSL session.
*
* @since 4.3
*/
public static final String SSL_SESSION = "http.ssl-session";
}

View File

@ -0,0 +1,52 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.http.conn;
import javax.net.ssl.SSLSession;
import org.apache.http.HttpInetConnection;
/**
* Extended interface that exposes SSL session details.
*
* @since 4.3
*/
public interface HttpSSLConnection extends HttpInetConnection {
/**
* Obtains the SSL session of the underlying connection, if any.
* If this connection is open, and the underlying socket is an
* {@link javax.net.ssl.SSLSocket SSLSocket}, the SSL session of
* that socket is obtained. This is a potentially blocking operation.
*
* @return the underlying SSL session if available,
* <code>null</code> otherwise
*/
SSLSession getSSLSession();
}

View File

@ -47,7 +47,7 @@ import org.apache.http.conn.routing.HttpRoute;
*/
@SuppressWarnings("deprecation")
public interface ManagedClientConnection extends
HttpClientConnection, HttpRoutedConnection, ConnectionReleaseTrigger {
HttpClientConnection, HttpRoutedConnection, HttpSSLConnection, ConnectionReleaseTrigger {
/**
* Indicates whether this connection is secure.

View File

@ -30,12 +30,15 @@ import java.security.Principal;
import javax.net.ssl.SSLSession;
import org.apache.http.HttpConnection;
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AuthScheme;
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.HttpSSLConnection;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
/**
@ -71,9 +74,13 @@ public class DefaultUserTokenHandler implements UserTokenHandler {
}
if (userPrincipal == null) {
SSLSession sslsession = (SSLSession) context.getAttribute(ClientContext.SSL_SESSION);
if (sslsession != null) {
userPrincipal = sslsession.getLocalPrincipal();
HttpConnection conn = (HttpConnection) context.getAttribute(
ExecutionContext.HTTP_CONNECTION);
if (conn instanceof HttpSSLConnection) {
SSLSession sslsession = ((HttpSSLConnection) conn).getSSLSession();
if (sslsession != null) {
userPrincipal = sslsession.getLocalPrincipal();
}
}
}

View File

@ -221,7 +221,6 @@ public class MainClientExec implements ClientExecChain {
}
context.setAttribute(ExecutionContext.HTTP_CONNECTION, managedConn);
context.setAttribute(ClientContext.SSL_SESSION, managedConn.getSSLSession());
if (HttpConnectionParams.isStaleCheckingEnabled(params)) {
// validate connection