javax.net.ssl

Class HttpsURLConnection

Known Direct Subclasses:
HTTPURLConnection

public abstract class HttpsURLConnection
extends HttpURLConnection

A URL connection that connects via the Secure Socket Layer (SSL) for HTTPS connections.

This class may be used in the same way as HttpURLConnection, and it will transparently negotiate the SSL connection.

Field Summary

protected HostnameVerifier
hostnameVerifier
The hostname verifier used for this connection.

Fields inherited from class java.net.HttpURLConnection

HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_NO_CONTENT, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, responseCode, responseMessage

Fields inherited from class java.net.URLConnection

allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches

Constructor Summary

HttpsURLConnection(URL url)
Creates a new HTTPS URL connection.

Method Summary

abstract String
getCipherSuite()
Returns the cipher name negotiated for this connection.
static HostnameVerifier
getDefaultHostnameVerifier()
Returns the default hostname verifier used in all new connections.
static SSLSocketFactory
getDefaultSSLSocketFactory()
Returns the default SSL socket factory used in all new connections.
HostnameVerifier
getHostnameVerifier()
Returns the current hostname verifier for this instance.
abstract Certificate[]
getLocalCertificates()
Returns the certificates used on the local side in this connection.
Principal
getLocalPrincipal()
Returns the local principal for this connection.
Principal
getPeerPrincipal()
Returns the remote peer's principal for this connection.
SSLSocketFactory
getSSLSocketFactory()
Returns the current SSL socket factory for this instance.
abstract Certificate[]
getServerCertificates()
Returns the certificates sent by the other party.
static void
setDefaultHostnameVerifier(HostnameVerifier newDefault)
Sets the default hostname verifier to be used in all new connections.
static void
setDefaultSSLSocketFactory(SSLSocketFactory newDefault)
Sets the default SSL socket factory to be used in all new connections.
void
setHostnameVerifier(HostnameVerifier hostnameVerifier)
Sets the hostname verifier for this instance.
void
setSSLSocketFactory(SSLSocketFactory factory)
Sets the SSL socket factory for this instance.

Methods inherited from class java.net.HttpURLConnection

disconnect, getErrorStream, getFollowRedirects, getHeaderFieldDate, getInstanceFollowRedirects, getPermission, getRequestMethod, getResponseCode, getResponseMessage, setFollowRedirects, setInstanceFollowRedirects, setRequestMethod, usingProxy

Methods inherited from class java.net.URLConnection

addRequestProperty, connect, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getOutputStream, getPermission, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

hostnameVerifier

protected HostnameVerifier hostnameVerifier
The hostname verifier used for this connection.

Constructor Details

HttpsURLConnection

protected HttpsURLConnection(URL url)
Creates a new HTTPS URL connection.
Parameters:
url - The URL of the connection being established.

Method Details

getCipherSuite

public abstract String getCipherSuite()
Returns the cipher name negotiated for this connection.
Returns:
The cipher name.
Throws:
IllegalStateException - If the connection has not yet been established.

getDefaultHostnameVerifier

public static HostnameVerifier getDefaultHostnameVerifier()
Returns the default hostname verifier used in all new connections. If the default verifier has not been set, a new default one will be provided by this method.
Returns:
The default hostname verifier.

getDefaultSSLSocketFactory

public static SSLSocketFactory getDefaultSSLSocketFactory()
Returns the default SSL socket factory used in all new connections. If the default SSL socket factory has not been set, a new default one will be provided by this method.
Returns:
The default SSL socket factory.

getHostnameVerifier

public HostnameVerifier getHostnameVerifier()
Returns the current hostname verifier for this instance.
Returns:
The hostname verifier.

getLocalCertificates

public abstract Certificate[] getLocalCertificates()
Returns the certificates used on the local side in this connection.
Returns:
The local certificates.
Throws:
IllegalStateException - If the connection has not yet been established.

getLocalPrincipal

public Principal getLocalPrincipal()
Returns the local principal for this connection.

The default implementation will return the javax.security.x500.X500Principal for the end entity certificate in the local certificate chain if those certificates are of type X509Certificate. Otherwise, this method returns null.

Returns:
The local principal.
Since:
1.5

getPeerPrincipal

public Principal getPeerPrincipal()
            throws SSLPeerUnverifiedException
Returns the remote peer's principal for this connection.

The default implementation will return the javax.security.x500.X500Principal for the end entity certificate in the remote peer's certificate chain if those certificates are of type X509Certificate. Otherwise, this method returns null.

Returns:
The remote principal.
Throws:
SSLPeerUnverifiedException - If the remote peer has not been verified.
Since:
1.5

getSSLSocketFactory

public SSLSocketFactory getSSLSocketFactory()
Returns the current SSL socket factory for this instance.
Returns:
The current SSL socket factory.

getServerCertificates

public abstract Certificate[] getServerCertificates()
            throws SSLPeerUnverifiedException
Returns the certificates sent by the other party.
Returns:
The peer's certificates.
Throws:
IllegalStateException - If the connection has not yet been established.
SSLPeerUnverifiedException - If the peer could not be verified.

setDefaultHostnameVerifier

public static void setDefaultHostnameVerifier(HostnameVerifier newDefault)
Sets the default hostname verifier to be used in all new connections.
Parameters:
newDefault - The new default hostname verifier.
Throws:
IllegalArgumentException - If newDefault is null.
SecurityException - If there is a security manager currently installed and the caller does not have the SSLPermission "setHostnameVerifier".

setDefaultSSLSocketFactory

public static void setDefaultSSLSocketFactory(SSLSocketFactory newDefault)
Sets the default SSL socket factory to be used in all new connections.
Parameters:
newDefault - The new socket factory.
Throws:
IllegalArgumentException - If newDefault is null.
SecurityException - If there is a security manager installed and a call to SecurityManager.checkSetFactory() fails.

setHostnameVerifier

public void setHostnameVerifier(HostnameVerifier hostnameVerifier)
Sets the hostname verifier for this instance.
Parameters:
hostnameVerifier - The new verifier.
Throws:
IllegalArgumentException - If hostnameVerifier is null.

setSSLSocketFactory

public void setSSLSocketFactory(SSLSocketFactory factory)
Sets the SSL socket factory for this instance.
Parameters:
factory - The new factory.
Throws:
IllegalArgumentException - If factory is null.

HttpsURLConnection.java -- an HTTPS connection. Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.