Top Description Fields Methods
org.eclipse.jgit.transport.http

public Interface HttpConnection

Known Direct Implementers
org.eclipse.jgit.transport.http.JDKHttpConnection
Imports
java.io.IOException, .InputStream, .OutputStream, java.net.HttpURLConnection, .ProtocolException, .URL, java.security.KeyManagementException, .NoSuchAlgorithmException, .SecureRandom, java.util.List, .Map, javax.net.ssl.HostnameVerifier, .KeyManager, .TrustManager, org.eclipse.jgit.annotations.NonNull

The interface of connections used during HTTP communication. This interface is that subset of the interface exposed by java.net.HttpURLConnection which is used by JGit
Since
3.3

Field Summary

Modifier and TypeField and Description
public static final int
HTTP_11_MOVED_PERM

HTTP 1.1 additional "permanent redirect" status code; value = 308.

public static final int
HTTP_11_MOVED_TEMP

HTTP 1.1 additional "temporary redirect" status code; value = 307.

public static final int
HTTP_FORBIDDEN

HttpURLConnection#HTTP_FORBIDDEN

public static final int
HTTP_MOVED_PERM

HttpURLConnection#HTTP_MOVED_PERM

public static final int
HTTP_MOVED_TEMP

HttpURLConnection#HTTP_MOVED_TEMP

public static final int
HTTP_NOT_AUTHORITATIVE

HttpURLConnection#HTTP_NOT_AUTHORITATIVE

public static final int
HTTP_NOT_FOUND

HttpURLConnection#HTTP_NOT_FOUND

public static final int
HTTP_OK

HttpURLConnection#HTTP_OK

public static final int
HTTP_SEE_OTHER

HttpURLConnection#HTTP_SEE_OTHER

public static final int
HTTP_UNAUTHORIZED

HttpURLConnection#HTTP_UNAUTHORIZED

Method Summary

Modifier and TypeMethod and Description
public void
configure(KeyManager[]
the keymanager managing the key material used to authenticate the local SSLSocket to its peer
km
,
TrustManager[]
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.
tm
,
SecureRandom
the source of randomness for this generator or null. See javax.net.ssl.SSLContext#init(KeyManager[], TrustManager[], SecureRandom)
random
)

Configure the connection so that it can be used for https communication.

public void
connect()

Connect

public int

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.
getContentLength
()

Get content length

public String

Returns:

the content type of the resource that the URL references, or null if not known.
getContentType
()

Get content type

public String

Returns:

the value of the named header field, or null if there is no such field in the header.
getHeaderField
(String
the name of a header field.
name
)

Get header field.

public Map<String, List<String>>

Returns:

a Map of header fields
getHeaderFields
()

Get map of header fields

public List<String>

Returns:

the list of values of the named header field
getHeaderFields
(String
the name of a header field.
name
)

Get all values of given header field.

public InputStream

Returns:

an input stream that reads from this open connection.
getInputStream
()

Get input stream

public OutputStream

Returns:

an output stream that writes to this connection.
getOutputStream
()

Get output stream

public String

Returns:

the HTTP request method
getRequestMethod
()

Get request method

public int

Returns:

the HTTP Status-Code, or -1
getResponseCode
()

Get response code

public String

Returns:

the HTTP response message, or null
getResponseMessage
()

Get response message

public URL

Returns:

the URL.
getURL
()

Get URL

public void
setChunkedStreamingMode(int
The number of bytes to write in each chunk. If chunklen is less than or equal to zero, a default value will be used.
chunklen
)

Set chunked streaming mode

public void
setConnectTimeout(int
an int that specifies the connect timeout value in milliseconds
timeout
)

Set connect timeout

public void
setDoOutput(boolean
the new value.
dooutput
)

Set if to do output

public void
setFixedLengthStreamingMode(int
The number of bytes which will be written to the OutputStream.
contentLength
)

Set fixed length streaming mode

public void
setHostnameVerifier(HostnameVerifier hostnameverifier)

Set the javax.net.ssl.HostnameVerifier used during https communication

public void
setInstanceFollowRedirects(boolean
a boolean indicating whether or not to follow HTTP redirects.
followRedirects
)

Set whether or not to follow HTTP redirects.

public void
setReadTimeout(int
an int that specifies the timeout value to be used in milliseconds
timeout
)

Set read timeout

public void
setRequestMethod(String
the HTTP method
method
)

Set request method

public void
setRequestProperty(String
the keyword by which the request is known (e.g., " Accept").
key
,
String
the value associated with it.
value
)

Set request property

public void
setUseCaches(boolean
a boolean indicating whether or not to allow caching
usecaches
)

Set if to use caches

public boolean

Returns:

a boolean indicating if the connection is using a proxy.
usingProxy
()

Whether we use a proxy

Field Detail

HTTP_11_MOVED_PERMback to summary
public static final int HTTP_11_MOVED_PERM

HTTP 1.1 additional "permanent redirect" status code; value = 308.

Since
5.8
See Also
HTTP_MOVED_TEMP, RFC 7538, section 3: 308 Permanent Redirect
HTTP_11_MOVED_TEMPback to summary
public static final int HTTP_11_MOVED_TEMP

HTTP 1.1 additional "temporary redirect" status code; value = 307.

Since
4.9
See Also
HTTP_MOVED_TEMP, RFC 7231, section 6.4.7: 307 Temporary Redirect
HTTP_FORBIDDENback to summary
public static final int HTTP_FORBIDDEN

HttpURLConnection#HTTP_FORBIDDEN

See Also
HttpURLConnection#HTTP_FORBIDDEN
HTTP_MOVED_PERMback to summary
public static final int HTTP_MOVED_PERM

HttpURLConnection#HTTP_MOVED_PERM

Since
4.7
See Also
HttpURLConnection#HTTP_MOVED_PERM
HTTP_MOVED_TEMPback to summary
public static final int HTTP_MOVED_TEMP

HttpURLConnection#HTTP_MOVED_TEMP

Since
4.9
See Also
HttpURLConnection#HTTP_MOVED_TEMP
HTTP_NOT_AUTHORITATIVEback to summary
public static final int HTTP_NOT_AUTHORITATIVE

HttpURLConnection#HTTP_NOT_AUTHORITATIVE

Since
5.8
See Also
HttpURLConnection#HTTP_NOT_AUTHORITATIVE
HTTP_NOT_FOUNDback to summary
public static final int HTTP_NOT_FOUND

HttpURLConnection#HTTP_NOT_FOUND

See Also
HttpURLConnection#HTTP_NOT_FOUND
HTTP_OKback to summary
public static final int HTTP_OK

HttpURLConnection#HTTP_OK

See Also
HttpURLConnection#HTTP_OK
HTTP_SEE_OTHERback to summary
public static final int HTTP_SEE_OTHER

HttpURLConnection#HTTP_SEE_OTHER

Since
4.9
See Also
HttpURLConnection#HTTP_SEE_OTHER
HTTP_UNAUTHORIZEDback to summary
public static final int HTTP_UNAUTHORIZED

HttpURLConnection#HTTP_UNAUTHORIZED

See Also
HttpURLConnection#HTTP_UNAUTHORIZED

Method Detail

configureback to summary
public void configure(KeyManager[] km, TrustManager[] tm, SecureRandom random) throws NoSuchAlgorithmException, KeyManagementException

Configure the connection so that it can be used for https communication.

Parameters
km:KeyManager[]

the keymanager managing the key material used to authenticate the local SSLSocket to its peer

tm:TrustManager[]

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:SecureRandom

the source of randomness for this generator or null. See javax.net.ssl.SSLContext#init(KeyManager[], TrustManager[], SecureRandom)

Exceptions
NoSuchAlgorithmException:
if algorithm isn't available
KeyManagementException:
if key management failed
connectback to summary
public void connect() throws IOException

Connect

Exceptions
IOException:
if an IO error occurred
See Also
HttpURLConnection#connect()
getContentLengthback to summary
public int getContentLength()

Get content length

Returns:int

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
HttpURLConnection#getContentLength()
getContentTypeback to summary
public String getContentType()

Get content type

Returns:String

the content type of the resource that the URL references, or null if not known.

See Also
HttpURLConnection#getContentType()
getHeaderFieldback to summary
public String getHeaderField(String name)

Get header field. According to RFC 2616 header field names are case insensitive. Header fields defined as a comma separated list can have multiple header fields with the same field name. This method only returns one of these header fields. If you want the union of all values of all multiple header fields with the same field name then use getHeaderFields(String)

Parameters
name:String

the name of a header field.

Returns:String

the value of the named header field, or null if there is no such field in the header.

See Also
HttpURLConnection#getHeaderField(String)
getHeaderFieldsback to summary
public Map<String, List<String>> getHeaderFields()

Get map of header fields

Returns:Map<String, List<String>>

a Map of header fields

See Also
HttpURLConnection#getHeaderFields()
getHeaderFieldsback to summary
public List<String> getHeaderFields(String name)

Get all values of given header field. According to RFC 2616 header field names are case insensitive. Header fields defined as a comma separated list can have multiple header fields with the same field name. This method does not validate if the given header field is defined as a comma separated list.

Parameters
name:String

the name of a header field.

Returns:List<String>

the list of values of the named header field

Since
5.2
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Get input stream

Returns:InputStream

an input stream that reads from this open connection.

Exceptions
IOException:
  • if an I/O error occurs while creating the input stream.
  • if an IO error occurred
See Also
HttpURLConnection#getInputStream()
getOutputStreamback to summary
public OutputStream getOutputStream() throws IOException

Get output stream

Returns:OutputStream

an output stream that writes to this connection.

Exceptions
IOException:
if an IO error occurred
See Also
HttpURLConnection#getOutputStream()
getRequestMethodback to summary
public String getRequestMethod()

Get request method

Returns:String

the HTTP request method

See Also
HttpURLConnection#getRequestMethod()
getResponseCodeback to summary
public int getResponseCode() throws IOException

Get response code

Returns:int

the HTTP Status-Code, or -1

Exceptions
IOException:
if an IO error occurred
See Also
HttpURLConnection#getResponseCode()
getResponseMessageback to summary
public String getResponseMessage() throws IOException

Get response message

Returns:String

the HTTP response message, or null

Exceptions
IOException:
if an IO error occurred
See Also
HttpURLConnection#getResponseMessage()
getURLback to summary
public URL getURL()

Get URL

Returns:URL

the URL.

See Also
HttpURLConnection#getURL()
setChunkedStreamingModeback to summary
public void setChunkedStreamingMode(int chunklen)

Set chunked streaming mode

Parameters
chunklen:int

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)
setConnectTimeoutback to summary
public void setConnectTimeout(int timeout)

Set connect timeout

Parameters
timeout:int

an int that specifies the connect timeout value in milliseconds

See Also
HttpURLConnection#setConnectTimeout(int)
setDoOutputback to summary
public void setDoOutput(boolean dooutput)

Set if to do output

Parameters
dooutput:boolean

the new value.

See Also
HttpURLConnection#setDoOutput(boolean)
setFixedLengthStreamingModeback to summary
public void setFixedLengthStreamingMode(int contentLength)

Set fixed length streaming mode

Parameters
contentLength:int

The number of bytes which will be written to the OutputStream.

See Also
HttpURLConnection#setFixedLengthStreamingMode(int)
setHostnameVerifierback to summary
public void setHostnameVerifier(HostnameVerifier hostnameverifier) throws NoSuchAlgorithmException, KeyManagementException

Set the javax.net.ssl.HostnameVerifier used during https communication

Parameters
hostnameverifier:HostnameVerifier

a javax.net.ssl.HostnameVerifier object.

Exceptions
NoSuchAlgorithmException:
if algorithm isn't available
KeyManagementException:
if key management failed
setInstanceFollowRedirectsback to summary
public void setInstanceFollowRedirects(boolean followRedirects)

Set whether or not to follow HTTP redirects.

Parameters
followRedirects:boolean

a boolean indicating whether or not to follow HTTP redirects.

See Also
HttpURLConnection#setInstanceFollowRedirects(boolean)
setReadTimeoutback to summary
public void setReadTimeout(int timeout)

Set read timeout

Parameters
timeout:int

an int that specifies the timeout value to be used in milliseconds

See Also
HttpURLConnection#setReadTimeout(int)
setRequestMethodback to summary
public void setRequestMethod(String method) throws ProtocolException

Set request method

Parameters
method:String

the HTTP method

Exceptions
ProtocolException:
  • if the method cannot be reset or if the requested method isn't valid for HTTP.
  • if any.
See Also
HttpURLConnection#setRequestMethod(String)
setRequestPropertyback to summary
public void setRequestProperty(String key, String value)

Set request property

Parameters
key:String

the keyword by which the request is known (e.g., " Accept").

value:String

the value associated with it.

See Also
HttpURLConnection#setRequestProperty(String, String)
setUseCachesback to summary
public void setUseCaches(boolean usecaches)

Set if to use caches

Parameters
usecaches:boolean

a boolean indicating whether or not to allow caching

See Also
HttpURLConnection#setUseCaches(boolean)
usingProxyback to summary
public boolean usingProxy()

Whether we use a proxy

Returns:boolean

a boolean indicating if the connection is using a proxy.

See Also
HttpURLConnection#usingProxy()