Class JDKHttpConnection

  • All Implemented Interfaces:
    HttpConnection

    public class JDKHttpConnection
    extends java.lang.Object
    implements HttpConnection
    A HttpConnection which simply delegates every call to a HttpURLConnection. This is the default implementation used by JGit
    Since:
    3.3
    • Constructor Detail

      • JDKHttpConnection

        protected JDKHttpConnection​(java.net.URL url)
                             throws java.net.MalformedURLException,
                                    java.io.IOException
        Parameters:
        url -
        Throws:
        java.net.MalformedURLException
        java.io.IOException
      • JDKHttpConnection

        protected JDKHttpConnection​(java.net.URL url,
                                    java.net.Proxy proxy)
                             throws java.net.MalformedURLException,
                                    java.io.IOException
        Parameters:
        url -
        proxy -
        Throws:
        java.net.MalformedURLException
        java.io.IOException
    • Method Detail

      • getResponseCode

        public int getResponseCode()
                            throws java.io.IOException
        Specified by:
        getResponseCode in interface HttpConnection
        Returns:
        the HTTP Status-Code, or -1
        Throws:
        java.io.IOException
        See Also:
        HttpURLConnection.getResponseCode()
      • getURL

        public java.net.URL getURL()
        Specified by:
        getURL in interface HttpConnection
        Returns:
        the URL.
        See Also:
        URLConnection.getURL()
      • getResponseMessage

        public java.lang.String getResponseMessage()
                                            throws java.io.IOException
        Specified by:
        getResponseMessage in interface HttpConnection
        Returns:
        the HTTP response message, or null
        Throws:
        java.io.IOException
        See Also:
        HttpURLConnection.getResponseMessage()
      • getHeaderFields

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getHeaderFields()
        Specified by:
        getHeaderFields in interface HttpConnection
        Returns:
        a Map of header fields
        See Also:
        URLConnection.getHeaderFields()
      • setRequestProperty

        public void setRequestProperty​(java.lang.String key,
                                       java.lang.String value)
        Specified by:
        setRequestProperty in interface HttpConnection
        Parameters:
        key - the keyword by which the request is known (e.g., " Accept").
        value - the value associated with it.
        See Also:
        URLConnection.setRequestProperty(String, String)
      • setRequestMethod

        public void setRequestMethod​(java.lang.String method)
                              throws java.net.ProtocolException
        Specified by:
        setRequestMethod in interface HttpConnection
        Parameters:
        method - the HTTP method
        Throws:
        java.net.ProtocolException - if the method cannot be reset or if the requested method isn't valid for HTTP.
        See Also:
        HttpURLConnection.setRequestMethod(String)
      • setUseCaches

        public void setUseCaches​(boolean usecaches)
        Specified by:
        setUseCaches in interface HttpConnection
        Parameters:
        usecaches - a boolean indicating whether or not to allow caching
        See Also:
        URLConnection.setUseCaches(boolean)
      • setConnectTimeout

        public void setConnectTimeout​(int timeout)
        Specified by:
        setConnectTimeout in interface HttpConnection
        Parameters:
        timeout - an int that specifies the connect timeout value in milliseconds
        See Also:
        URLConnection.setConnectTimeout(int)
      • setReadTimeout

        public void setReadTimeout​(int timeout)
        Specified by:
        setReadTimeout in interface HttpConnection
        Parameters:
        timeout - an int that specifies the timeout value to be used in milliseconds
        See Also:
        URLConnection.setReadTimeout(int)
      • getContentType

        public java.lang.String getContentType()
        Specified by:
        getContentType in interface HttpConnection
        Returns:
        the content type of the resource that the URL references, or null if not known.
        See Also:
        URLConnection.getContentType()
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        Specified by:
        getInputStream in interface HttpConnection
        Returns:
        an input stream that reads from this open connection.
        Throws:
        java.io.IOException - if an I/O error occurs while creating the input stream.
        See Also:
        URLConnection.getInputStream()
      • getHeaderField

        public java.lang.String getHeaderField​(java.lang.String name)
        Specified by:
        getHeaderField in interface HttpConnection
        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.
        See Also:
        URLConnection.getHeaderField(String)
      • getContentLength

        public int getContentLength()
        Specified by:
        getContentLength in interface HttpConnection
        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.
        See Also:
        URLConnection.getContentLength()
      • setInstanceFollowRedirects

        public void setInstanceFollowRedirects​(boolean followRedirects)
        Specified by:
        setInstanceFollowRedirects in interface HttpConnection
        Parameters:
        followRedirects - a boolean indicating whether or not to follow HTTP redirects.
        See Also:
        HttpURLConnection.setInstanceFollowRedirects(boolean)
      • setDoOutput

        public void setDoOutput​(boolean dooutput)
        Specified by:
        setDoOutput in interface HttpConnection
        Parameters:
        dooutput - the new value.
        See Also:
        URLConnection.setDoOutput(boolean)
      • setFixedLengthStreamingMode

        public void setFixedLengthStreamingMode​(int contentLength)
        Specified by:
        setFixedLengthStreamingMode in interface HttpConnection
        Parameters:
        contentLength - The number of bytes which will be written to the OutputStream.
        See Also:
        HttpURLConnection.setFixedLengthStreamingMode(int)
      • getOutputStream

        public java.io.OutputStream getOutputStream()
                                             throws java.io.IOException
        Specified by:
        getOutputStream in interface HttpConnection
        Returns:
        an output stream that writes to this connection.
        Throws:
        java.io.IOException
        See Also:
        URLConnection.getOutputStream()
      • setChunkedStreamingMode

        public void setChunkedStreamingMode​(int chunklen)
        Specified by:
        setChunkedStreamingMode in interface HttpConnection
        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.
        See Also:
        HttpURLConnection.setChunkedStreamingMode(int)
      • getRequestMethod

        public java.lang.String getRequestMethod()
        Specified by:
        getRequestMethod in interface HttpConnection
        Returns:
        the HTTP request method
        See Also:
        HttpURLConnection.getRequestMethod()
      • usingProxy

        public boolean usingProxy()
        Specified by:
        usingProxy in interface HttpConnection
        Returns:
        a boolean indicating if the connection is using a proxy.
        See Also:
        HttpURLConnection.usingProxy()
      • connect

        public void connect()
                     throws java.io.IOException
        Specified by:
        connect in interface HttpConnection
        Throws:
        java.io.IOException
        See Also:
        URLConnection.connect()
      • setHostnameVerifier

        public void setHostnameVerifier​(javax.net.ssl.HostnameVerifier hostnameverifier)
        Description copied from interface: HttpConnection
        Set the HostnameVerifier used during https communication
        Specified by:
        setHostnameVerifier in interface HttpConnection
      • configure

        public void configure​(javax.net.ssl.KeyManager[] km,
                              javax.net.ssl.TrustManager[] tm,
                              java.security.SecureRandom random)
                       throws java.security.NoSuchAlgorithmException,
                              java.security.KeyManagementException
        Description copied from interface: HttpConnection
        Configure the connection so that it can be used for https communication.
        Specified by:
        configure in interface HttpConnection
        Parameters:
        km - the keymanager managing the key material used to authenticate the local SSLSocket to its peer
        tm - the trustmanager responsible for managing the trust material that is used when making trust decisions, and for deciding whether credentials presented by a peer should be accepted.
        random - the source of randomness for this generator or null. See SSLContext.init(KeyManager[], TrustManager[], SecureRandom)
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.KeyManagementException