Class RecordableHttpsURLConnection

java.lang.Object
java.net.URLConnection
java.net.HttpURLConnection
javax.net.ssl.HttpsURLConnection
com.easypost.easyvcr.clients.httpurlconnection.RecordableHttpsURLConnection

public final class RecordableHttpsURLConnection extends HttpsURLConnection
  • Constructor Details

  • Method Details

    • connect

      public void connect() throws IOException
      Specified by:
      connect in class URLConnection
      Throws:
      IOException
    • disconnect

      public void disconnect()
      Specified by:
      disconnect in class HttpURLConnection
    • usingProxy

      public boolean usingProxy()
      Specified by:
      usingProxy in class HttpURLConnection
    • getHeaderFieldKey

      public String getHeaderFieldKey(int n)
      Returns the key for the nth header field. Some implementations may treat the 0th header field as special, i.e. as the status line returned by the HTTP server. In this case, getHeaderField(0) returns the status line, but getHeaderFieldKey(0) returns null.
      Overrides:
      getHeaderFieldKey in class HttpURLConnection
      Parameters:
      n - an index, where n >=0.
      Returns:
      the key for the nth header field, or null if the key does not exist.
    • setFixedLengthStreamingMode

      public void setFixedLengthStreamingMode(int contentLength)
      This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.

      An exception will be thrown if the application attempts to write more data than the indicated content-length, or if the application closes the OutputStream before writing the indicated amount.

      When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.

      This method must be called before the URLConnection is connected.

      NOTE: setFixedLengthStreamingMode(long) is recommended instead of this method as it allows larger content lengths to be set.

      Overrides:
      setFixedLengthStreamingMode in class HttpURLConnection
      Parameters:
      contentLength - The number of bytes which will be written to the OutputStream.
      Throws:
      IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.
      IllegalArgumentException - if a content length less than zero is specified.
      Since:
      1.5
      See Also:
      setChunkedStreamingMode(int)
    • setFixedLengthStreamingMode

      public void setFixedLengthStreamingMode(long contentLength)
      This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.

      An exception will be thrown if the application attempts to write more data than the indicated content-length, or if the application closes the OutputStream before writing the indicated amount.

      When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.

      This method must be called before the URLConnection is connected.

      The content length set by invoking this method takes precedence over any value set by setFixedLengthStreamingMode(int).

      Overrides:
      setFixedLengthStreamingMode in class HttpURLConnection
      Parameters:
      contentLength - The number of bytes which will be written to the OutputStream.
      Throws:
      IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.
      IllegalArgumentException - if a content length less than zero is specified.
      Since:
      1.7
    • setChunkedStreamingMode

      public void setChunkedStreamingMode(int chunklen)
      This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is not known in advance. In this mode, chunked transfer encoding is used to send the request body. Note, not all HTTP servers support this mode.

      When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.

      This method must be called before the URLConnection is connected.

      Overrides:
      setChunkedStreamingMode in class HttpURLConnection
      Parameters:
      chunklen - The number of bytes to write in each chunk. If chunklen is less than or equal to zero, a default value will be used.
      Throws:
      IllegalStateException - if URLConnection is already connected or if a different streaming mode is already enabled.
      Since:
      1.5
      See Also:
      setFixedLengthStreamingMode(int)
    • getHeaderField

      public String getHeaderField(int n)
      Returns the value for the nth header field. Some implementations may treat the 0th header field as special, i.e. as the status line returned by the HTTP server.

      This method can be used in conjunction with the getHeaderFieldKey method to iterate through all the headers in the message.

      Overrides:
      getHeaderField in class HttpURLConnection
      Parameters:
      n - an index, where n>=0.
      Returns:
      the value of the nth header field, or null if the value does not exist.
      See Also:
      HttpURLConnection.getHeaderFieldKey(int)
    • getInstanceFollowRedirects

      public boolean getInstanceFollowRedirects()
      Returns the value of this RecordableHttpUrlConnection's instanceFollowRedirects field.
      Overrides:
      getInstanceFollowRedirects in class HttpURLConnection
      Returns:
      the value of this RecordableHttpUrlConnection's instanceFollowRedirects field.
      Since:
      1.3
      See Also:
      setInstanceFollowRedirects(boolean)
    • setInstanceFollowRedirects

      public void setInstanceFollowRedirects(boolean followRedirects)
      Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this RecordableHttpUrlConnection instance.

      The default value comes from followRedirects, which defaults to true.

      Overrides:
      setInstanceFollowRedirects in class HttpURLConnection
      Parameters:
      followRedirects - a boolean indicating whether or not to follow HTTP redirects.
      Since:
      1.3
      See Also:
      getInstanceFollowRedirects()
    • getRequestMethod

      public String getRequestMethod()
      get the request method.
      Overrides:
      getRequestMethod in class HttpURLConnection
      Returns:
      the HTTP request method
      See Also:
      setRequestMethod(String)
    • setRequestMethod

      public void setRequestMethod(String method) throws ProtocolException
      Set the method for the URL request, one of:
      • GET
      • POST
      • HEAD
      • OPTIONS
      • PUT
      • DELETE
      • TRACE
      are legal, subject to protocol restrictions. The default method is GET.
      Overrides:
      setRequestMethod in class HttpURLConnection
      Parameters:
      method - the HTTP method
      Throws:
      ProtocolException - if the method cannot be reset or if the requested method isn't valid for HTTP.
      SecurityException - if a security manager is set and the method is "TRACE", but the "allowHttpTrace" NetPermission is not granted.
      See Also:
      getRequestMethod()
    • getResponseCode

      public int getResponseCode() throws IOException
      gets the status code from an HTTP response message. For example, in the case of the following status lines:
       HTTP/1.0 200 OK
       HTTP/1.0 401 Unauthorized
       
      It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e., the response is not valid HTTP).
      Overrides:
      getResponseCode in class HttpURLConnection
      Returns:
      the HTTP Status-Code, or -1
      Throws:
      IOException - if an error occurred connecting to the server.
    • getResponseMessage

      public String getResponseMessage() throws IOException
      gets the HTTP response message, if any, returned along with the response code from a server. From responses like:
       HTTP/1.0 200 OK
       HTTP/1.0 404 Not Found
       
      Extracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).
      Overrides:
      getResponseMessage in class HttpURLConnection
      Returns:
      the HTTP response message, or null
      Throws:
      IOException - if an error occurred connecting to the server.
    • getPermission

      public Permission getPermission() throws IOException
      Returns a SocketPermission object representing the permission necessary to connect to the destination host and port.
      Overrides:
      getPermission in class HttpURLConnection
      Returns:
      a SocketPermission object representing the permission necessary to connect to the destination host and port.
      Throws:
      IOException - if an error occurs while computing the permission.
    • getErrorStream

      public InputStream getErrorStream()
      Returns the error stream if the connection failed but the server sent useful data nonetheless. The typical example is when an HTTP server responds with a 404, which will cause a FileNotFoundException to be thrown in connect, but the server sent an HTML help page with suggestions as to what to do.

      This method will not cause a connection to be initiated. If the connection was not connected, or if the server did not have an error while connecting or if the server had an error but no error data was sent, this method will return null. This is the default.

      Overrides:
      getErrorStream in class HttpURLConnection
      Returns:
      an error stream if any, null if there have been no errors, the connection is not connected or the server sent no useful data.
    • getConnectTimeout

      public int getConnectTimeout()
      Returns setting for connect timeout.

      0 return implies that the option is disabled (i.e., timeout of infinity).

      Overrides:
      getConnectTimeout in class URLConnection
      Returns:
      an int that indicates the connect timeout value in milliseconds
      Since:
      1.5
      See Also:
      setConnectTimeout(int), connect()
    • setConnectTimeout

      public void setConnectTimeout(int timeout)
      Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection. If the timeout expires before the connection can be established, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.

      Some non-standard implementation of this method may ignore the specified timeout. To see the connect timeout set, please call getConnectTimeout().

      Overrides:
      setConnectTimeout in class URLConnection
      Parameters:
      timeout - an int that specifies the connect timeout value in milliseconds
      Throws:
      IllegalArgumentException - if the timeout parameter is negative
      Since:
      1.5
      See Also:
      getConnectTimeout(), connect()
    • getReadTimeout

      public int getReadTimeout()
      Returns setting for read timeout. 0 return implies that the option is disabled (i.e., timeout of infinity).
      Overrides:
      getReadTimeout in class URLConnection
      Returns:
      an int that indicates the read timeout value in milliseconds
      Since:
      1.5
      See Also:
      setReadTimeout(int), InputStream.read()
    • setReadTimeout

      public void setReadTimeout(int timeout)
      Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.

      Some non-standard implementation of this method ignores the specified timeout. To see the read timeout set, please call getReadTimeout().

      Overrides:
      setReadTimeout in class URLConnection
      Parameters:
      timeout - an int that specifies the timeout value to be used in milliseconds
      Throws:
      IllegalArgumentException - if the timeout parameter is negative
      Since:
      1.5
      See Also:
      getReadTimeout(), InputStream.read()
    • getURL

      public URL getURL()
      Returns the value of this URLConnection's URL field.
      Overrides:
      getURL in class URLConnection
      Returns:
      the value of this URLConnection's URL field.
    • getContentType

      public String getContentType()
      Returns the value of the content-type header field.
      Overrides:
      getContentType in class URLConnection
      Returns:
      the content type of the resource that the URL references, or null if not known.
      See Also:
      URLConnection.getHeaderField(String)
    • getContentEncoding

      public String getContentEncoding()
      Returns the value of the content-encoding header field.
      Overrides:
      getContentEncoding in class URLConnection
      Returns:
      the content encoding of the resource that the URL references, or null if not known.
      See Also:
      URLConnection.getHeaderField(String)
    • getExpiration

      public long getExpiration()
      Returns the value of the expires header field.
      Overrides:
      getExpiration in class URLConnection
      Returns:
      the expiration date of the resource that this URL references, or 0 if not known. The value is the number of milliseconds since January 1, 1970 GMT.
      See Also:
      URLConnection.getHeaderField(String)
    • getHeaderField

      public String getHeaderField(String name)
      Returns the value of the named header field.

      If called on a connection that sets the same header multiple times with possibly different values, only the last value is returned.

      Overrides:
      getHeaderField in class URLConnection
      Parameters:
      name - the name of a header field.
      Returns:
      the value of the named header field, or null if there is no such field in the header.
    • getHeaderFields

      public Map<String,​List<String>> getHeaderFields()
      Returns an unmodifiable Map of the header fields. The Map keys are Strings that represent the response-header field names. Each Map value is an unmodifiable List of Strings that represents the corresponding field values.
      Overrides:
      getHeaderFields in class URLConnection
      Returns:
      a Map of header fields
      Since:
      1.4
    • getContent

      public Object getContent() throws IOException
      Retrieves the contents of this URL connection.

      This method first determines the content type of the object by calling the getContentType method. If this is the first time that the application has seen that specific content type, a content handler for that content type is created.

      This is done as follows:

      1. If the application has set up a content handler factory instance using the setContentHandlerFactory method, the createContentHandler method of that instance is called with the content type as an argument; the result is a content handler for that content type.
      2. If no ContentHandlerFactory has yet been set up, or if the factory's createContentHandler method returns null, then the ServiceLoader mechanism is used to locate ContentHandlerFactory implementations using the system class loader. The order that factories are located is implementation specific, and an implementation is free to cache the located factories. A ServiceConfigurationError, Error or RuntimeException thrown from the createContentHandler, if encountered, will be propagated to the calling thread. The createContentHandler method of each factory, if instantiated, is invoked, with the content type, until a factory returns non-null, or all factories have been exhausted.
      3. Failing that, this method tries to load a content handler class as defined by ContentHandler. If the class does not exist, or is not a subclass of ContentHandler, then an UnknownServiceException is thrown.
      Overrides:
      getContent in class URLConnection
      Returns:
      the object fetched. The instanceof operator should be used to determine the specific kind of object returned.
      Throws:
      IOException - if an I/O error occurs while getting the content.
      UnknownServiceException - if the protocol does not support the content type.
      See Also:
      ContentHandlerFactory.createContentHandler(String), URLConnection.getContentType(), URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory)
    • toString

      public String toString()
      Returns a String representation of this URL connection.
      Overrides:
      toString in class URLConnection
      Returns:
      a string representation of this URLConnection.
    • getDoInput

      public boolean getDoInput()
      Returns the value of this URLConnection's doInput flag.
      Overrides:
      getDoInput in class URLConnection
      Returns:
      the value of this URLConnection's doInput flag.
      See Also:
      setDoInput(boolean)
    • setDoInput

      public void setDoInput(boolean doinput)
      Sets the value of the doInput field for this URLConnection to the specified value.

      A URL connection can be used for input and/or output. Set the doInput flag to true if you intend to use the URL connection for input, false if not. The default is true.

      Overrides:
      setDoInput in class URLConnection
      Parameters:
      doinput - the new value.
      Throws:
      IllegalStateException - if already connected
      See Also:
      getDoInput()
    • getDoOutput

      public boolean getDoOutput()
      Returns the value of this URLConnection's doOutput flag.
      Overrides:
      getDoOutput in class URLConnection
      Returns:
      the value of this URLConnection's doOutput flag.
      See Also:
      setDoOutput(boolean)
    • setDoOutput

      public void setDoOutput(boolean dooutput)
      Sets the value of the doOutput field for this URLConnection to the specified value.

      A URL connection can be used for input and/or output. Set the doOutput flag to true if you intend to use the URL connection for output, false if not. The default is false.

      Overrides:
      setDoOutput in class URLConnection
      Parameters:
      dooutput - the new value.
      Throws:
      IllegalStateException - if already connected
      See Also:
      getDoOutput()
    • getAllowUserInteraction

      public boolean getAllowUserInteraction()
      Returns the value of the allowUserInteraction field for this object.
      Overrides:
      getAllowUserInteraction in class URLConnection
      Returns:
      the value of the allowUserInteraction field for this object.
      See Also:
      setAllowUserInteraction(boolean)
    • setAllowUserInteraction

      public void setAllowUserInteraction(boolean allowuserinteraction)
      Set the value of the allowUserInteraction field of this URLConnection.
      Overrides:
      setAllowUserInteraction in class URLConnection
      Parameters:
      allowuserinteraction - the new value.
      Throws:
      IllegalStateException - if already connected
      See Also:
      getAllowUserInteraction()
    • getUseCaches

      public boolean getUseCaches()
      Returns the value of this URLConnection's useCaches field.
      Overrides:
      getUseCaches in class URLConnection
      Returns:
      the value of this URLConnection's useCaches field.
      See Also:
      setUseCaches(boolean)
    • setUseCaches

      public void setUseCaches(boolean usecaches)
      Sets the value of the useCaches field of this URLConnection to the specified value.

      Some protocols do caching of documents. Occasionally, it is important to be able to "tunnel through" and ignore the caches (e.g., the "reload" button in a browser). If the UseCaches flag on a connection is true, the connection is allowed to use whatever caches it can. If false, caches are to be ignored. The default value comes from defaultUseCaches, which defaults to true.

      Overrides:
      setUseCaches in class URLConnection
      Parameters:
      usecaches - a boolean indicating whether or not to allow caching
      Throws:
      IllegalStateException - if already connected
      See Also:
      getUseCaches()
    • getIfModifiedSince

      public long getIfModifiedSince()
      Returns the value of this object's ifModifiedSince field.
      Overrides:
      getIfModifiedSince in class URLConnection
      Returns:
      the value of this object's ifModifiedSince field.
      See Also:
      setIfModifiedSince(long)
    • setIfModifiedSince

      public void setIfModifiedSince(long ifmodifiedsince)
      Sets the value of the ifModifiedSince field of this URLConnection to the specified value.
      Overrides:
      setIfModifiedSince in class URLConnection
      Parameters:
      ifmodifiedsince - the new value.
      Throws:
      IllegalStateException - if already connected
      See Also:
      getIfModifiedSince()
    • getDefaultUseCaches

      public boolean getDefaultUseCaches()
      Returns the default value of a URLConnection's useCaches flag.

      This default is "sticky", being a part of the static state of all URLConnections. This flag applies to the next, and all following URLConnections that are created.

      Overrides:
      getDefaultUseCaches in class URLConnection
      Returns:
      the default value of a URLConnection's useCaches flag.
      See Also:
      setDefaultUseCaches(boolean)
    • setDefaultUseCaches

      public void setDefaultUseCaches(boolean defaultusecaches)
      Sets the default value of the useCaches field to the specified value.
      Overrides:
      setDefaultUseCaches in class URLConnection
      Parameters:
      defaultusecaches - the new value.
      See Also:
      getDefaultUseCaches()
    • setRequestProperty

      public void setRequestProperty(String key, String value)
      Sets the general request property. If a property with the key already exists, overwrite its value with the new value.

      NOTE: HTTP requires all request properties which can legally have multiple instances with the same key to use a comma-separated list syntax which enables multiple properties to be appended into a single property.

      Overrides:
      setRequestProperty in class URLConnection
      Parameters:
      key - the keyword by which the request is known (e.g., "Accept").
      value - the value associated with it.
      Throws:
      IllegalStateException - if already connected
      NullPointerException - if key is null
      See Also:
      getRequestProperty(String)
    • addRequestProperty

      public void addRequestProperty(String key, String value)
      Adds a general request property specified by a key-value pair. This method will not overwrite existing values associated with the same key.
      Overrides:
      addRequestProperty in class URLConnection
      Parameters:
      key - the keyword by which the request is known (e.g., "Accept").
      value - the value associated with it.
      Throws:
      IllegalStateException - if already connected
      NullPointerException - if key is null
      Since:
      1.4
      See Also:
      getRequestProperties()
    • getRequestProperty

      public String getRequestProperty(String key)
      Returns the value of the named general request property for this connection.
      Overrides:
      getRequestProperty in class URLConnection
      Parameters:
      key - the keyword by which the request is known (e.g., "Accept").
      Returns:
      the value of the named general request property for this connection. If key is null, then null is returned.
      Throws:
      IllegalStateException - if already connected
      See Also:
      setRequestProperty(String, String)
    • getRequestProperties

      public Map<String,​List<String>> getRequestProperties()
      Returns an unmodifiable Map of general request properties for this connection. The Map keys are Strings that represent the request-header field names. Each Map value is a unmodifiable List of Strings that represents the corresponding field values.
      Overrides:
      getRequestProperties in class URLConnection
      Returns:
      a Map of the general request properties for this connection.
      Throws:
      IllegalStateException - if already connected
      Since:
      1.4
    • getInputStream

      public InputStream getInputStream() throws IOException
      Overrides:
      getInputStream in class URLConnection
      Throws:
      IOException
    • getHeaderFieldDate

      public long getHeaderFieldDate(String name, long Default)
      Overrides:
      getHeaderFieldDate in class HttpURLConnection
    • getContentLength

      public int getContentLength()
      Returns the value of the content-length header field.

      Note: getContentLengthLong() should be preferred over this method, since it returns a long instead and is therefore more portable.

      Overrides:
      getContentLength in class URLConnection
      Returns:
      the content length of the resource that this connection's URL references, -1 if the content length is not known, or if the content length is greater than Integer.MAX_VALUE.
    • getContentLengthLong

      public long getContentLengthLong()
      Returns the value of the content-length header field as a long.
      Overrides:
      getContentLengthLong in class URLConnection
      Returns:
      the content length of the resource that this connection's URL references, or -1 if the content length is not known.
      Since:
      1.7
    • getDate

      public long getDate()
      Returns the value of the date header field.
      Overrides:
      getDate in class URLConnection
      Returns:
      the sending date of the resource that the URL references, or 0 if not known. The value returned is the number of milliseconds since January 1, 1970 GMT.
      See Also:
      URLConnection.getHeaderField(String)
    • getLastModified

      public long getLastModified()
      Returns the value of the last-modified header field. The result is the number of milliseconds since January 1, 1970 GMT.
      Overrides:
      getLastModified in class URLConnection
      Returns:
      the date the resource referenced by this URLConnection was last modified, or 0 if not known.
      See Also:
      URLConnection.getHeaderField(String)
    • getHeaderFieldInt

      public int getHeaderFieldInt(String name, int Default)
      Returns the value of the named field parsed as a number.

      This form of getHeaderField exists because some connection types (e.g., http-ng) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.

      Overrides:
      getHeaderFieldInt in class URLConnection
      Parameters:
      name - the name of the header field.
      Default - the default value.
      Returns:
      the value of the named field, parsed as an integer. The Default value is returned if the field is missing or malformed.
    • getHeaderFieldLong

      public long getHeaderFieldLong(String name, long Default)
      Returns the value of the named field parsed as a number.

      This form of getHeaderField exists because some connection types (e.g., http-ng) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.

      Overrides:
      getHeaderFieldLong in class URLConnection
      Parameters:
      name - the name of the header field.
      Default - the default value.
      Returns:
      the value of the named field, parsed as a long. The Default value is returned if the field is missing or malformed.
      Since:
      1.7
    • getContent

      public Object getContent(Class[] classes) throws IOException
      Retrieves the contents of this URL connection.
      Overrides:
      getContent in class URLConnection
      Parameters:
      classes - the Class array indicating the requested types
      Returns:
      the object fetched that is the first match of the type specified in the classes array. null if none of the requested types are supported. The instanceof operator should be used to determine the specific kind of object returned.
      Throws:
      IOException - if an I/O error occurs while getting the content.
      UnknownServiceException - if the protocol does not support the content type.
      Since:
      1.3
      See Also:
      URLConnection.getContent(), ContentHandlerFactory.createContentHandler(String), URLConnection.getContent(Class[]), URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory)
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Returns an output stream that writes to this connection.
      Overrides:
      getOutputStream in class URLConnection
      Returns:
      an output stream that writes to this connection.
      Throws:
      IOException - if an I/O error occurs while creating the output stream.
      UnknownServiceException - if the protocol does not support output.
    • getCipherSuite

      public String getCipherSuite()
      Specified by:
      getCipherSuite in class HttpsURLConnection
    • getLocalCertificates

      public Certificate[] getLocalCertificates()
      Specified by:
      getLocalCertificates in class HttpsURLConnection
    • getServerCertificates

      public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException
      Specified by:
      getServerCertificates in class HttpsURLConnection
      Throws:
      SSLPeerUnverifiedException
    • getPeerPrincipal

      public Principal getPeerPrincipal() throws SSLPeerUnverifiedException
      Returns the server's principal which was established as part of defining the session.

      Note: Subclasses should override this method. If not overridden, it will default to returning the X500Principal of the server's end-entity certificate for certificate-based ciphersuites, or throw an SSLPeerUnverifiedException for non-certificate based ciphersuites, such as Kerberos.

      Overrides:
      getPeerPrincipal in class HttpsURLConnection
      Returns:
      the server's principal. Returns an X500Principal of the end-entity certiticate for X509-based cipher suites, and KerberosPrincipal for Kerberos cipher suites.
      Throws:
      SSLPeerUnverifiedException - if the peer was not verified
      IllegalStateException - if this method is called before the connection has been established.
      Since:
      1.5
      See Also:
      getServerCertificates(), getLocalPrincipal()
    • getLocalPrincipal

      public Principal getLocalPrincipal()
      Returns the principal that was sent to the server during handshaking.

      Note: Subclasses should override this method. If not overridden, it will default to returning the X500Principal of the end-entity certificate that was sent to the server for certificate-based ciphersuites or, return null for non-certificate based ciphersuites, such as Kerberos.

      Overrides:
      getLocalPrincipal in class HttpsURLConnection
      Returns:
      the principal sent to the server. Returns an X500Principal of the end-entity certificate for X509-based cipher suites, and KerberosPrincipal for Kerberos cipher suites. If no principal was sent, then null is returned.
      Throws:
      IllegalStateException - if this method is called before the connection has been established.
      Since:
      1.5
      See Also:
      getLocalCertificates(), getPeerPrincipal()
    • getHostnameVerifier

      public HostnameVerifier getHostnameVerifier()
      gets the HostnameVerifier in place on this instance.
      Overrides:
      getHostnameVerifier in class HttpsURLConnection
      Returns:
      the host name verifier
      See Also:
      setHostnameVerifier(HostnameVerifier), HttpsURLConnection.setDefaultHostnameVerifier(HostnameVerifier)
    • setHostnameVerifier

      public void setHostnameVerifier(HostnameVerifier v)
      Sets the HostnameVerifier for this instance.

      New instances of this class inherit the default static hostname verifier set by setDefaultHostnameVerifier. Calls to this method replace this object's HostnameVerifier.

      Overrides:
      setHostnameVerifier in class HttpsURLConnection
      Parameters:
      v - the host name verifier
      Throws:
      IllegalArgumentException - if the HostnameVerifier parameter is null.
      See Also:
      getHostnameVerifier(), HttpsURLConnection.setDefaultHostnameVerifier(HostnameVerifier)
    • getSSLSocketFactory

      public SSLSocketFactory getSSLSocketFactory()
      gets the SSL socket factory to be used when creating sockets for secure https URL connections.
      Overrides:
      getSSLSocketFactory in class HttpsURLConnection
      Returns:
      the SSLSocketFactory
      See Also:
      setSSLSocketFactory(SSLSocketFactory)
    • setSSLSocketFactory

      public void setSSLSocketFactory(SSLSocketFactory sf)
      Sets the SSLSocketFactory to be used when this instance creates sockets for secure https URL connections.

      New instances of this class inherit the default static SSLSocketFactory set by setDefaultSSLSocketFactory. Calls to this method replace this object's SSLSocketFactory.

      Overrides:
      setSSLSocketFactory in class HttpsURLConnection
      Parameters:
      sf - the SSL socket factory
      Throws:
      IllegalArgumentException - if the SSLSocketFactory parameter is null.
      SecurityException - if a security manager exists and its checkSetFactory method does not allow a socket factory to be specified.
      See Also:
      getSSLSocketFactory()