Package org.eclipse.jgit.transport.http
Class JDKHttpConnection
- java.lang.Object
-
- org.eclipse.jgit.transport.http.JDKHttpConnection
-
- All Implemented Interfaces:
HttpConnection
public class JDKHttpConnection extends Object implements HttpConnection
AHttpConnection
which simply delegates every call to aHttpURLConnection
. This is the default implementation used by JGit- Since:
- 3.3
-
-
Field Summary
-
Fields inherited from interface org.eclipse.jgit.transport.http.HttpConnection
HTTP_11_MOVED_PERM, HTTP_11_MOVED_TEMP, HTTP_FORBIDDEN, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_OK, HTTP_SEE_OTHER, HTTP_UNAUTHORIZED
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JDKHttpConnection(URL url)
Constructor for JDKHttpConnection.protected
JDKHttpConnection(URL url, Proxy proxy)
Constructor for JDKHttpConnection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(KeyManager[] km, TrustManager[] tm, SecureRandom random)
Configure the connection so that it can be used for https communication.void
connect()
Connectint
getContentLength()
Get content lengthString
getContentType()
Get content typeString
getHeaderField(String name)
Get header field.Map<String,List<String>>
getHeaderFields()
Get map of header fieldsList<String>
getHeaderFields(String name)
Get all values of given header field.InputStream
getInputStream()
Get input streamOutputStream
getOutputStream()
Get output streamString
getRequestMethod()
Get request methodint
getResponseCode()
Get response codeString
getResponseMessage()
Get response messageURL
getURL()
Get URLvoid
setChunkedStreamingMode(int chunklen)
Set chunked streaming modevoid
setConnectTimeout(int timeout)
Set connect timeoutvoid
setDoOutput(boolean dooutput)
Set if to do outputvoid
setFixedLengthStreamingMode(int contentLength)
Set fixed length streaming modevoid
setHostnameVerifier(HostnameVerifier hostnameverifier)
Set theHostnameVerifier
used during https communicationvoid
setInstanceFollowRedirects(boolean followRedirects)
Set whether or not to follow HTTP redirects.void
setReadTimeout(int timeout)
Set read timeoutvoid
setRequestMethod(String method)
Set request methodvoid
setRequestProperty(String key, String value)
Set request propertyvoid
setUseCaches(boolean usecaches)
Set if to use cachesboolean
usingProxy()
Whether we use a proxy
-
-
-
Constructor Detail
-
JDKHttpConnection
protected JDKHttpConnection(URL url) throws MalformedURLException, IOException
Constructor for JDKHttpConnection.- Parameters:
url
- aURL
object.- Throws:
MalformedURLException
IOException
-
JDKHttpConnection
protected JDKHttpConnection(URL url, Proxy proxy) throws MalformedURLException, IOException
Constructor for JDKHttpConnection.- Parameters:
url
- aURL
object.proxy
- aProxy
object.- Throws:
MalformedURLException
IOException
-
-
Method Detail
-
getResponseCode
public int getResponseCode() throws IOException
Get response code- Specified by:
getResponseCode
in interfaceHttpConnection
- Returns:
- the HTTP Status-Code, or -1
- Throws:
IOException
- See Also:
HttpURLConnection.getResponseCode()
-
getURL
public URL getURL()
Get URL- Specified by:
getURL
in interfaceHttpConnection
- Returns:
- the URL.
- See Also:
URLConnection.getURL()
-
getResponseMessage
public String getResponseMessage() throws IOException
Get response message- Specified by:
getResponseMessage
in interfaceHttpConnection
- Returns:
- the HTTP response message, or
null
- Throws:
IOException
- See Also:
HttpURLConnection.getResponseMessage()
-
getHeaderFields
public Map<String,List<String>> getHeaderFields()
Get map of header fields- Specified by:
getHeaderFields
in interfaceHttpConnection
- Returns:
- a Map of header fields
- See Also:
URLConnection.getHeaderFields()
-
setRequestProperty
public void setRequestProperty(String key, String value)
Set request property- Specified by:
setRequestProperty
in interfaceHttpConnection
- 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(String method) throws ProtocolException
Set request method- Specified by:
setRequestMethod
in interfaceHttpConnection
- Parameters:
method
- the HTTP method- Throws:
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)
Set if to use caches- Specified by:
setUseCaches
in interfaceHttpConnection
- Parameters:
usecaches
- aboolean
indicating whether or not to allow caching- See Also:
URLConnection.setUseCaches(boolean)
-
setConnectTimeout
public void setConnectTimeout(int timeout)
Set connect timeout- Specified by:
setConnectTimeout
in interfaceHttpConnection
- Parameters:
timeout
- anint
that specifies the connect timeout value in milliseconds- See Also:
URLConnection.setConnectTimeout(int)
-
setReadTimeout
public void setReadTimeout(int timeout)
Set read timeout- Specified by:
setReadTimeout
in interfaceHttpConnection
- Parameters:
timeout
- anint
that specifies the timeout value to be used in milliseconds- See Also:
URLConnection.setReadTimeout(int)
-
getContentType
public String getContentType()
Get content type- Specified by:
getContentType
in interfaceHttpConnection
- Returns:
- the content type of the resource that the URL references, or
null
if not known. - See Also:
URLConnection.getContentType()
-
getInputStream
public InputStream getInputStream() throws IOException
Get input stream- Specified by:
getInputStream
in interfaceHttpConnection
- Returns:
- an input stream that reads from this open connection.
- Throws:
IOException
- if an I/O error occurs while creating the input stream.- See Also:
URLConnection.getInputStream()
-
getHeaderField
public String getHeaderField(@NonNull String name)
Get header field. According to {@link 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 useHttpConnection.getHeaderFields(String)
- Specified by:
getHeaderField
in interfaceHttpConnection
- 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)
-
getHeaderFields
public List<String> getHeaderFields(@NonNull String name)
Description copied from interface:HttpConnection
Get all values of given header field. According to {@link 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.- Specified by:
getHeaderFields
in interfaceHttpConnection
- Parameters:
name
- the name of a header field.- Returns:
- the list of values of the named header field
-
getContentLength
public int getContentLength()
Get content length- Specified by:
getContentLength
in interfaceHttpConnection
- 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)
Set whether or not to follow HTTP redirects.- Specified by:
setInstanceFollowRedirects
in interfaceHttpConnection
- Parameters:
followRedirects
- aboolean
indicating whether or not to follow HTTP redirects.- See Also:
HttpURLConnection.setInstanceFollowRedirects(boolean)
-
setDoOutput
public void setDoOutput(boolean dooutput)
Set if to do output- Specified by:
setDoOutput
in interfaceHttpConnection
- Parameters:
dooutput
- the new value.- See Also:
URLConnection.setDoOutput(boolean)
-
setFixedLengthStreamingMode
public void setFixedLengthStreamingMode(int contentLength)
Set fixed length streaming mode- Specified by:
setFixedLengthStreamingMode
in interfaceHttpConnection
- Parameters:
contentLength
- The number of bytes which will be written to the OutputStream.- See Also:
HttpURLConnection.setFixedLengthStreamingMode(int)
-
getOutputStream
public OutputStream getOutputStream() throws IOException
Get output stream- Specified by:
getOutputStream
in interfaceHttpConnection
- Returns:
- an output stream that writes to this connection.
- Throws:
IOException
- See Also:
URLConnection.getOutputStream()
-
setChunkedStreamingMode
public void setChunkedStreamingMode(int chunklen)
Set chunked streaming mode- Specified by:
setChunkedStreamingMode
in interfaceHttpConnection
- 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 String getRequestMethod()
Get request method- Specified by:
getRequestMethod
in interfaceHttpConnection
- Returns:
- the HTTP request method
- See Also:
HttpURLConnection.getRequestMethod()
-
usingProxy
public boolean usingProxy()
Whether we use a proxy- Specified by:
usingProxy
in interfaceHttpConnection
- Returns:
- a boolean indicating if the connection is using a proxy.
- See Also:
HttpURLConnection.usingProxy()
-
connect
public void connect() throws IOException
Connect- Specified by:
connect
in interfaceHttpConnection
- Throws:
IOException
- See Also:
URLConnection.connect()
-
setHostnameVerifier
public void setHostnameVerifier(HostnameVerifier hostnameverifier)
Set theHostnameVerifier
used during https communication- Specified by:
setHostnameVerifier
in interfaceHttpConnection
- Parameters:
hostnameverifier
- aHostnameVerifier
object.
-
configure
public void configure(KeyManager[] km, TrustManager[] tm, SecureRandom random) throws NoSuchAlgorithmException, KeyManagementException
Configure the connection so that it can be used for https communication.- Specified by:
configure
in interfaceHttpConnection
- Parameters:
km
- the keymanager managing the key material used to authenticate the local SSLSocket to its peertm
- 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. SeeSSLContext.init(KeyManager[], TrustManager[], SecureRandom)
- Throws:
NoSuchAlgorithmException
KeyManagementException
-
-