javax.net.ssl

Class HttpsURLConnection

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 {@link HttpURLConnection}, and it will transparently negotiate the SSL connection.

Field Summary
protected HostnameVerifierhostnameVerifier
The hostname verifier used for this connection.
Constructor Summary
protected HttpsURLConnection(URL url)
Creates a new HTTPS URL connection.
Method Summary
abstract StringgetCipherSuite()
Returns the cipher name negotiated for this connection.
static HostnameVerifiergetDefaultHostnameVerifier()
Returns the default hostname verifier used in all new connections.
static SSLSocketFactorygetDefaultSSLSocketFactory()
Returns the default SSL socket factory used in all new connections.
HostnameVerifiergetHostnameVerifier()
Returns the current hostname verifier for this instance.
abstract Certificate[]getLocalCertificates()
Returns the certificates used on the local side in this connection.
PrincipalgetLocalPrincipal()
Returns the local principal for this connection.
PrincipalgetPeerPrincipal()
Returns the remote peer's principal for this connection.
abstract Certificate[]getServerCertificates()
Returns the certificates sent by the other party.
SSLSocketFactorygetSSLSocketFactory()
Returns the current SSL socket factory for this instance.
static voidsetDefaultHostnameVerifier(HostnameVerifier newDefault)
Sets the default hostname verifier to be used in all new connections.
static voidsetDefaultSSLSocketFactory(SSLSocketFactory newDefault)
Sets the default SSL socket factory to be used in all new connections.
voidsetHostnameVerifier(HostnameVerifier hostnameVerifier)
Sets the hostname verifier for this instance.
voidsetSSLSocketFactory(SSLSocketFactory factory)
Sets the SSL socket factory for this instance.

Field Detail

hostnameVerifier

protected HostnameVerifier hostnameVerifier
The hostname verifier used for this connection.

Constructor Detail

HttpsURLConnection

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

Parameters: url The URL of the connection being established.

UNKNOWN: This was marked as throwing IOException in 1.4, but this was removed in 1.5.

Method Detail

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 {@link javax.security.x500.X500Principal} for the end entity certificate in the local certificate chain if those certificates are of type {@link java.security.cert.X509Certificate}. Otherwise, this method returns null.

Returns: The local principal.

Since: 1.5

getPeerPrincipal

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

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

Returns: The remote principal.

Throws: SSLPeerUnverifiedException If the remote peer has not been verified.

Since: 1.5

getServerCertificates

public abstract Certificate[] getServerCertificates()
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.

getSSLSocketFactory

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

Returns: The current SSL socket factory.

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 {@link 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 {@link 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.