Class HttpClientConnection
- java.lang.Object
-
- org.eclipse.jgit.transport.http.apache.HttpClientConnection
-
- All Implemented Interfaces:
HttpConnection
public class HttpClientConnection extends java.lang.Object implements HttpConnection
AHttpConnectionwhich usesHttpClient- Since:
- 3.3
-
-
Field Summary
Fields Modifier and Type Field Description (package private) org.apache.http.client.HttpClientclientprivate javax.net.ssl.SSLContextctxprivate TemporaryBufferEntityentityprivate java.lang.BooleanfollowRedirectsprivate javax.net.ssl.HostnameVerifierhostnameverifierprivate booleanisUsingProxy(package private) java.lang.Stringmethodprivate java.net.Proxyproxyprivate java.lang.IntegerreadTimeout(package private) org.apache.http.client.methods.HttpUriRequestreq(package private) org.apache.http.HttpResponserespprivate org.apache.http.conn.ssl.SSLConnectionSocketFactorysocketFactoryprivate java.lang.Integertimeout(package private) java.net.URLurlprivate booleanusePooling-
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 Constructor Description HttpClientConnection(java.lang.String urlStr)Constructor for HttpClientConnection.HttpClientConnection(java.lang.String urlStr, java.net.Proxy proxy)Constructor for HttpClientConnection.HttpClientConnection(java.lang.String urlStr, java.net.Proxy proxy, org.apache.http.client.HttpClient cl)Constructor for HttpClientConnection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(javax.net.ssl.KeyManager[] km, javax.net.ssl.TrustManager[] tm, java.security.SecureRandom random)Configure the connection so that it can be used for https communication.voidconnect()Connectprivate voidexecute()private org.apache.http.client.HttpClientgetClient()intgetContentLength()Get content lengthjava.lang.StringgetContentType()Get content typejava.lang.StringgetHeaderField(java.lang.String name)Get header field.java.util.Map<java.lang.String,java.util.List<java.lang.String>>getHeaderFields()Get map of header fieldsjava.util.List<java.lang.String>getHeaderFields(java.lang.String name)Get all values of given header field.java.io.InputStreamgetInputStream()Get input streamjava.io.OutputStreamgetOutputStream()Get output streamjava.lang.StringgetRequestMethod()Get request methodintgetResponseCode()Get response codejava.lang.StringgetResponseMessage()Get response messageprivate javax.net.ssl.SSLContextgetSSLContext()private org.apache.http.conn.ssl.SSLConnectionSocketFactorygetSSLSocketFactory()java.net.URLgetURL()Get URLvoidsetBuffer(TemporaryBuffer buffer)Sets the buffer from which to take the request bodyvoidsetChunkedStreamingMode(int chunklen)Set chunked streaming modevoidsetConnectTimeout(int timeout)Set connect timeoutvoidsetDoOutput(boolean dooutput)Set if to do outputvoidsetFixedLengthStreamingMode(int contentLength)Set fixed length streaming modevoidsetHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameverifier)Set theHostnameVerifierused during https communicationvoidsetInstanceFollowRedirects(boolean followRedirects)Set whether or not to follow HTTP redirects.voidsetReadTimeout(int readTimeout)Set read timeoutvoidsetRequestMethod(java.lang.String method)Set request methodvoidsetRequestProperty(java.lang.String name, java.lang.String value)Set request property(package private) voidsetSSLSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory factory, boolean isDefault)voidsetUseCaches(boolean usecaches)Set if to use cachesbooleanusingProxy()Whether we use a proxy
-
-
-
Field Detail
-
client
org.apache.http.client.HttpClient client
-
url
java.net.URL url
-
req
org.apache.http.client.methods.HttpUriRequest req
-
resp
org.apache.http.HttpResponse resp
-
method
java.lang.String method
-
entity
private TemporaryBufferEntity entity
-
isUsingProxy
private boolean isUsingProxy
-
proxy
private java.net.Proxy proxy
-
timeout
private java.lang.Integer timeout
-
readTimeout
private java.lang.Integer readTimeout
-
followRedirects
private java.lang.Boolean followRedirects
-
hostnameverifier
private javax.net.ssl.HostnameVerifier hostnameverifier
-
ctx
private javax.net.ssl.SSLContext ctx
-
socketFactory
private org.apache.http.conn.ssl.SSLConnectionSocketFactory socketFactory
-
usePooling
private boolean usePooling
-
-
Constructor Detail
-
HttpClientConnection
public HttpClientConnection(java.lang.String urlStr) throws java.net.MalformedURLExceptionConstructor for HttpClientConnection.- Parameters:
urlStr-- Throws:
java.net.MalformedURLException
-
HttpClientConnection
public HttpClientConnection(java.lang.String urlStr, java.net.Proxy proxy) throws java.net.MalformedURLExceptionConstructor for HttpClientConnection.- Parameters:
urlStr-proxy-- Throws:
java.net.MalformedURLException
-
HttpClientConnection
public HttpClientConnection(java.lang.String urlStr, java.net.Proxy proxy, org.apache.http.client.HttpClient cl) throws java.net.MalformedURLExceptionConstructor for HttpClientConnection.- Parameters:
urlStr-proxy-cl-- Throws:
java.net.MalformedURLException
-
-
Method Detail
-
getClient
private org.apache.http.client.HttpClient getClient()
-
setSSLSocketFactory
void setSSLSocketFactory(@NonNull org.apache.http.conn.ssl.SSLConnectionSocketFactory factory, boolean isDefault)
-
getSSLSocketFactory
private org.apache.http.conn.ssl.SSLConnectionSocketFactory getSSLSocketFactory()
-
getSSLContext
private javax.net.ssl.SSLContext getSSLContext()
-
setBuffer
public void setBuffer(TemporaryBuffer buffer)
Sets the buffer from which to take the request body- Parameters:
buffer-
-
getResponseCode
public int getResponseCode() throws java.io.IOExceptionGet response code- Specified by:
getResponseCodein interfaceHttpConnection- Returns:
- the HTTP Status-Code, or -1
- Throws:
java.io.IOException- See Also:
HttpURLConnection.getResponseCode()
-
getURL
public java.net.URL getURL()
Get URL- Specified by:
getURLin interfaceHttpConnection- Returns:
- the URL.
- See Also:
URLConnection.getURL()
-
getResponseMessage
public java.lang.String getResponseMessage() throws java.io.IOExceptionGet response message- Specified by:
getResponseMessagein interfaceHttpConnection- Returns:
- the HTTP response message, or
null - Throws:
java.io.IOException- See Also:
HttpURLConnection.getResponseMessage()
-
execute
private void execute() throws java.io.IOException, org.apache.http.client.ClientProtocolException- Throws:
java.io.IOExceptionorg.apache.http.client.ClientProtocolException
-
getHeaderFields
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaderFields()
Get map of header fields- Specified by:
getHeaderFieldsin interfaceHttpConnection- Returns:
- a Map of header fields
- See Also:
URLConnection.getHeaderFields()
-
setRequestProperty
public void setRequestProperty(java.lang.String name, java.lang.String value)Set request property- Specified by:
setRequestPropertyin interfaceHttpConnection- Parameters:
name- 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.ProtocolExceptionSet request method- Specified by:
setRequestMethodin interfaceHttpConnection- 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)
Set if to use caches- Specified by:
setUseCachesin interfaceHttpConnection- Parameters:
usecaches- abooleanindicating whether or not to allow caching- See Also:
URLConnection.setUseCaches(boolean)
-
setConnectTimeout
public void setConnectTimeout(int timeout)
Set connect timeout- Specified by:
setConnectTimeoutin interfaceHttpConnection- Parameters:
timeout- anintthat specifies the connect timeout value in milliseconds- See Also:
URLConnection.setConnectTimeout(int)
-
setReadTimeout
public void setReadTimeout(int readTimeout)
Set read timeout- Specified by:
setReadTimeoutin interfaceHttpConnection- Parameters:
readTimeout- anintthat specifies the timeout value to be used in milliseconds- See Also:
URLConnection.setReadTimeout(int)
-
getContentType
public java.lang.String getContentType()
Get content type- Specified by:
getContentTypein interfaceHttpConnection- Returns:
- the content type of the resource that the URL references, or
nullif not known. - See Also:
URLConnection.getContentType()
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOExceptionGet input stream- Specified by:
getInputStreamin interfaceHttpConnection- 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(@NonNull java.lang.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:
getHeaderFieldin interfaceHttpConnection- Parameters:
name- the name of a header field.- Returns:
- the value of the named header field, or
nullif there is no such field in the header. - See Also:
URLConnection.getHeaderField(String)
-
getHeaderFields
public java.util.List<java.lang.String> getHeaderFields(@NonNull java.lang.String name)
Description copied from interface:HttpConnectionGet 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:
getHeaderFieldsin 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:
getContentLengthin interfaceHttpConnection- Returns:
- the content length of the resource that this connection's URL
references,
-1if 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:
setInstanceFollowRedirectsin interfaceHttpConnection- Parameters:
followRedirects- abooleanindicating 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:
setDoOutputin interfaceHttpConnection- Parameters:
dooutput- the new value.- See Also:
URLConnection.setDoOutput(boolean)
-
setFixedLengthStreamingMode
public void setFixedLengthStreamingMode(int contentLength)
Set fixed length streaming mode- Specified by:
setFixedLengthStreamingModein interfaceHttpConnection- 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.IOExceptionGet output stream- Specified by:
getOutputStreamin interfaceHttpConnection- Returns:
- an output stream that writes to this connection.
- Throws:
java.io.IOException- See Also:
URLConnection.getOutputStream()
-
setChunkedStreamingMode
public void setChunkedStreamingMode(int chunklen)
Set chunked streaming mode- Specified by:
setChunkedStreamingModein 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 java.lang.String getRequestMethod()
Get request method- Specified by:
getRequestMethodin interfaceHttpConnection- Returns:
- the HTTP request method
- See Also:
HttpURLConnection.getRequestMethod()
-
usingProxy
public boolean usingProxy()
Whether we use a proxy- Specified by:
usingProxyin interfaceHttpConnection- Returns:
- a boolean indicating if the connection is using a proxy.
- See Also:
HttpURLConnection.usingProxy()
-
connect
public void connect() throws java.io.IOExceptionConnect- Specified by:
connectin interfaceHttpConnection- Throws:
java.io.IOException- See Also:
URLConnection.connect()
-
setHostnameVerifier
public void setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameverifier)
Set theHostnameVerifierused during https communication- Specified by:
setHostnameVerifierin interfaceHttpConnection- Parameters:
hostnameverifier- aHostnameVerifierobject.
-
configure
public void configure(javax.net.ssl.KeyManager[] km, javax.net.ssl.TrustManager[] tm, java.security.SecureRandom random) throws java.security.KeyManagementExceptionConfigure the connection so that it can be used for https communication.- Specified by:
configurein 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:
java.security.KeyManagementException
-
-