public abstract class HttpClientBase
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CONNECTION_TIMEOUT
Default connection timeout for this client, in milliseconds.
|
static int |
DEFAULT_SO_TIMEOUT
Default socket timeout for this client, in milliseconds.
|
protected java.lang.String |
url
The URL stting to execute requests against.
|
Modifier | Constructor and Description |
---|---|
protected |
HttpClientBase(java.lang.String host,
int port,
java.lang.String path,
org.apache.http.conn.HttpClientConnectionManager conMgr,
org.apache.http.client.config.RequestConfig defaultConfig) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected <T> T |
doAction(org.apache.http.HttpResponse response,
boolean consume,
java.util.concurrent.Callable<T> call)
Do a specific action and validate after the action that the status is still OK,
and if not, attempt to extract the actual server side exception.
|
protected <T> T |
doAction(org.apache.http.HttpResponse response,
java.util.concurrent.Callable<T> call)
Same as
doAction(HttpResponse, boolean, Callable) but always do consume at the end. |
protected void |
ensureOpen()
Throws
AlreadyClosedException if this client is already closed. |
protected org.apache.http.HttpResponse |
executeGET(java.lang.String request,
java.lang.String... params)
internal: execute a request and return its result
The
params argument is treated as: name1,value1,name2,value2,... |
protected org.apache.http.HttpResponse |
executePOST(java.lang.String request,
org.apache.http.HttpEntity entity,
java.lang.String... params)
internal: execute a request and return its result
The
params argument is treated as: name1,value1,name2,value2,... |
protected boolean |
isClosed()
Returns true iff this instance was
closed , otherwise
returns false. |
java.io.InputStream |
responseInputStream(org.apache.http.HttpResponse response)
Internal utility: input stream of the provided response
|
java.io.InputStream |
responseInputStream(org.apache.http.HttpResponse response,
boolean consume)
Internal utility: input stream of the provided response, which optionally
consumes the response's resources when the input stream is exhausted.
|
protected void |
throwKnownError(org.apache.http.HttpResponse response,
org.apache.http.StatusLine statusLine) |
protected void |
verifyStatus(org.apache.http.HttpResponse response)
Internal: response status after invocation, and in case or error attempt to read the
exception sent by the server.
|
public static final int DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_SO_TIMEOUT
protected final java.lang.String url
protected HttpClientBase(java.lang.String host, int port, java.lang.String path, org.apache.http.conn.HttpClientConnectionManager conMgr, org.apache.http.client.config.RequestConfig defaultConfig)
conMgr
- connection manager to use for this http client. NOTE:The
provided HttpClientConnectionManager
will not be
HttpClientConnectionManager.shutdown()
by this class.defaultConfig
- the default RequestConfig
to set on the client. If
null
a default config is created w/ the default connection
and socket timeouts.protected final void ensureOpen() throws AlreadyClosedException
AlreadyClosedException
if this client is already closed.AlreadyClosedException
protected void verifyStatus(org.apache.http.HttpResponse response) throws java.io.IOException
java.io.IOException
protected void throwKnownError(org.apache.http.HttpResponse response, org.apache.http.StatusLine statusLine) throws java.io.IOException
java.io.IOException
protected org.apache.http.HttpResponse executePOST(java.lang.String request, org.apache.http.HttpEntity entity, java.lang.String... params) throws java.io.IOException
params
argument is treated as: name1,value1,name2,value2,...java.io.IOException
protected org.apache.http.HttpResponse executeGET(java.lang.String request, java.lang.String... params) throws java.io.IOException
params
argument is treated as: name1,value1,name2,value2,...java.io.IOException
public java.io.InputStream responseInputStream(org.apache.http.HttpResponse response) throws java.io.IOException
java.io.IOException
public java.io.InputStream responseInputStream(org.apache.http.HttpResponse response, boolean consume) throws java.io.IOException
java.io.IOException
protected final boolean isClosed()
protected <T> T doAction(org.apache.http.HttpResponse response, java.util.concurrent.Callable<T> call) throws java.io.IOException
doAction(HttpResponse, boolean, Callable)
but always do consume at the end.java.io.IOException
protected <T> T doAction(org.apache.http.HttpResponse response, boolean consume, java.util.concurrent.Callable<T> call) throws java.io.IOException
consume
parameter.java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
Copyright © 2000–2019 The Apache Software Foundation. All rights reserved.