public class HttpClientConnection extends java.lang.Object implements HttpConnection
HttpConnection
which uses
HttpClient
Modifier and Type | Field and Description |
---|---|
(package private) org.apache.http.client.HttpClient |
client |
(package private) javax.net.ssl.SSLContext |
ctx |
private TemporaryBufferEntity |
entity |
private java.lang.Boolean |
followRedirects |
private javax.net.ssl.HostnameVerifier |
hostnameverifier |
private boolean |
isUsingProxy |
(package private) java.lang.String |
method |
private java.net.Proxy |
proxy |
private java.lang.Integer |
readTimeout |
(package private) org.apache.http.client.methods.HttpUriRequest |
req |
(package private) org.apache.http.HttpResponse |
resp |
private java.lang.Integer |
timeout |
(package private) java.net.URL |
url |
HTTP_11_MOVED_TEMP, HTTP_FORBIDDEN, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_NOT_FOUND, HTTP_OK, HTTP_SEE_OTHER, HTTP_UNAUTHORIZED
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
void |
configure(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.
|
void |
connect()
Connect
|
private void |
execute() |
private org.apache.http.client.HttpClient |
getClient() |
int |
getContentLength()
Get content length
|
java.lang.String |
getContentType()
Get content type
|
java.lang.String |
getHeaderField(java.lang.String name)
Get header field.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getHeaderFields()
Get map of header fields
|
java.util.List<java.lang.String> |
getHeaderFields(java.lang.String name)
Get all values of given header field.
|
java.io.InputStream |
getInputStream()
Get input stream
|
java.io.OutputStream |
getOutputStream()
Get output stream
|
java.lang.String |
getRequestMethod()
Get request method
|
int |
getResponseCode()
Get response code
|
java.lang.String |
getResponseMessage()
Get response message
|
private javax.net.ssl.SSLContext |
getSSLContext() |
java.net.URL |
getURL()
Get URL
|
void |
setBuffer(TemporaryBuffer buffer)
Sets the buffer from which to take the request body
|
void |
setChunkedStreamingMode(int chunklen)
Set chunked streaming mode
|
void |
setConnectTimeout(int timeout)
Set connect timeout
|
void |
setDoOutput(boolean dooutput)
Set if to do output
|
void |
setFixedLengthStreamingMode(int contentLength)
Set fixed length streaming mode
|
void |
setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameverifier)
Set the
HostnameVerifier used during https
communication |
void |
setInstanceFollowRedirects(boolean followRedirects)
Set whether or not to follow HTTP redirects.
|
void |
setReadTimeout(int readTimeout)
Set read timeout
|
void |
setRequestMethod(java.lang.String method)
Set request method
|
void |
setRequestProperty(java.lang.String name,
java.lang.String value)
Set request property
|
void |
setUseCaches(boolean usecaches)
Set if to use caches
|
boolean |
usingProxy()
Whether we use a proxy
|
org.apache.http.client.HttpClient client
java.net.URL url
org.apache.http.client.methods.HttpUriRequest req
org.apache.http.HttpResponse resp
java.lang.String method
private TemporaryBufferEntity entity
private boolean isUsingProxy
private java.net.Proxy proxy
private java.lang.Integer timeout
private java.lang.Integer readTimeout
private java.lang.Boolean followRedirects
private javax.net.ssl.HostnameVerifier hostnameverifier
javax.net.ssl.SSLContext ctx
public HttpClientConnection(java.lang.String urlStr) throws java.net.MalformedURLException
urlStr
- java.net.MalformedURLException
public HttpClientConnection(java.lang.String urlStr, java.net.Proxy proxy) throws java.net.MalformedURLException
urlStr
- proxy
- java.net.MalformedURLException
public HttpClientConnection(java.lang.String urlStr, java.net.Proxy proxy, org.apache.http.client.HttpClient cl) throws java.net.MalformedURLException
urlStr
- proxy
- cl
- java.net.MalformedURLException
private org.apache.http.client.HttpClient getClient()
private javax.net.ssl.SSLContext getSSLContext()
public void setBuffer(TemporaryBuffer buffer)
buffer
- public int getResponseCode() throws java.io.IOException
getResponseCode
in interface HttpConnection
java.io.IOException
HttpURLConnection.getResponseCode()
public java.net.URL getURL()
getURL
in interface HttpConnection
URLConnection.getURL()
public java.lang.String getResponseMessage() throws java.io.IOException
getResponseMessage
in interface HttpConnection
null
java.io.IOException
HttpURLConnection.getResponseMessage()
private void execute() throws java.io.IOException, org.apache.http.client.ClientProtocolException
java.io.IOException
org.apache.http.client.ClientProtocolException
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaderFields()
getHeaderFields
in interface HttpConnection
URLConnection.getHeaderFields()
public void setRequestProperty(java.lang.String name, java.lang.String value)
setRequestProperty
in interface HttpConnection
name
- the keyword by which the request is known (e.g., "
Accept
").value
- the value associated with it.URLConnection.setRequestProperty(String, String)
public void setRequestMethod(java.lang.String method) throws java.net.ProtocolException
setRequestMethod
in interface HttpConnection
method
- the HTTP methodjava.net.ProtocolException
- if the method cannot be reset or if the requested method
isn't valid for HTTP.HttpURLConnection.setRequestMethod(String)
public void setUseCaches(boolean usecaches)
setUseCaches
in interface HttpConnection
usecaches
- a boolean
indicating whether or not to allow
cachingURLConnection.setUseCaches(boolean)
public void setConnectTimeout(int timeout)
setConnectTimeout
in interface HttpConnection
timeout
- an int
that specifies the connect timeout value
in millisecondsURLConnection.setConnectTimeout(int)
public void setReadTimeout(int readTimeout)
setReadTimeout
in interface HttpConnection
readTimeout
- an int
that specifies the timeout value to be
used in millisecondsURLConnection.setReadTimeout(int)
public java.lang.String getContentType()
getContentType
in interface HttpConnection
null
if not known.URLConnection.getContentType()
public java.io.InputStream getInputStream() throws java.io.IOException
getInputStream
in interface HttpConnection
java.io.IOException
- if an I/O error occurs while creating the input stream.URLConnection.getInputStream()
public java.lang.String getHeaderField(@NonNull java.lang.String name)
HttpConnection.getHeaderFields(String)
getHeaderField
in interface HttpConnection
name
- the name of a header field.null
if
there is no such field in the header.URLConnection.getHeaderField(String)
public java.util.List<java.lang.String> getHeaderFields(@NonNull java.lang.String name)
HttpConnection
getHeaderFields
in interface HttpConnection
name
- the name of a header field.public int getContentLength()
getContentLength
in interface HttpConnection
-1
if the content length is not known, or if
the content length is greater than Integer.MAX_VALUE.URLConnection.getContentLength()
public void setInstanceFollowRedirects(boolean followRedirects)
setInstanceFollowRedirects
in interface HttpConnection
followRedirects
- a boolean
indicating whether or not to follow
HTTP redirects.HttpURLConnection.setInstanceFollowRedirects(boolean)
public void setDoOutput(boolean dooutput)
setDoOutput
in interface HttpConnection
dooutput
- the new value.URLConnection.setDoOutput(boolean)
public void setFixedLengthStreamingMode(int contentLength)
setFixedLengthStreamingMode
in interface HttpConnection
contentLength
- The number of bytes which will be written to the OutputStream.HttpURLConnection.setFixedLengthStreamingMode(int)
public java.io.OutputStream getOutputStream() throws java.io.IOException
getOutputStream
in interface HttpConnection
java.io.IOException
URLConnection.getOutputStream()
public void setChunkedStreamingMode(int chunklen)
setChunkedStreamingMode
in interface HttpConnection
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.HttpURLConnection.setChunkedStreamingMode(int)
public java.lang.String getRequestMethod()
getRequestMethod
in interface HttpConnection
HttpURLConnection.getRequestMethod()
public boolean usingProxy()
usingProxy
in interface HttpConnection
HttpURLConnection.usingProxy()
public void connect() throws java.io.IOException
connect
in interface HttpConnection
java.io.IOException
URLConnection.connect()
public void setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameverifier)
HostnameVerifier
used during https
communicationsetHostnameVerifier
in interface HttpConnection
hostnameverifier
- a HostnameVerifier
object.public void configure(javax.net.ssl.KeyManager[] km, javax.net.ssl.TrustManager[] tm, java.security.SecureRandom random) throws java.security.KeyManagementException
configure
in interface HttpConnection
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. See
SSLContext.init(KeyManager[], TrustManager[], SecureRandom)
java.security.KeyManagementException