org.apache.lucene.replicator.http

## Class HttpClientBase

- java.lang.Object
- - org.apache.lucene.replicator.http.HttpClientBase

All Implemented Interfaces:
  Closeable, AutoCloseable

Direct Known Subclasses:
  HttpReplicator

    public abstract class HttpClientBase
    extends Object
    implements Closeable

Base class for Http clients.

WARNING: This API is experimental and might change in incompatible ways in the next release.

### Field Summary

Fields
`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 String` `url` The URL stting to execute requests against.

### Constructor Summary

Constructors
`protected` `HttpClientBase(String host, int port, String path, org.apache.http.conn.HttpClientConnectionManager conMgr, org.apache.http.client.config.RequestConfig defaultConfig)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `close()`
`protected <T> T` `doAction(org.apache.http.HttpResponse response, boolean consume, 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, 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(String request, 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(String request, org.apache.http.HttpEntity entity, 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.
`InputStream` `responseInputStream(org.apache.http.HttpResponse response)` Internal utility: input stream of the provided response
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DEFAULT_CONNECTION_TIMEOUT

    public static final int DEFAULT_CONNECTION_TIMEOUT

Default connection timeout for this client, in milliseconds.

See Also:
  Constant Field Values

#### DEFAULT_SO_TIMEOUT

    public static final int DEFAULT_SO_TIMEOUT

Default socket timeout for this client, in milliseconds.

See Also:
  Constant Field Values

#### url

    protected final String url

The URL stting to execute requests against.

### Constructor Detail

#### HttpClientBase

    protected HttpClientBase(String host,
                             int port,
                             String path,
                             org.apache.http.conn.HttpClientConnectionManager conMgr,
                             org.apache.http.client.config.RequestConfig defaultConfig)

Parameters:
  `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.

### Method Detail

#### ensureOpen

    protected final void ensureOpen()
                             throws AlreadyClosedException

Throws `AlreadyClosedException` if this client is already closed.

Throws:
  `AlreadyClosedException`

#### verifyStatus

    protected void verifyStatus(org.apache.http.HttpResponse response)
                         throws IOException

Internal: response status after invocation, and in case or error attempt to read the exception sent by the server.

Throws:
  `IOException`

#### throwKnownError

    protected void throwKnownError(org.apache.http.HttpResponse response,
                                   org.apache.http.StatusLine statusLine)
                            throws IOException

Throws:
  `IOException`

#### executePOST

    protected org.apache.http.HttpResponse executePOST(String request,
                                                       org.apache.http.HttpEntity entity,
                                                       String... params)
                                                throws IOException

internal: execute a request and return its result The `params` argument is treated as: name1,value1,name2,value2,...

Throws:
  `IOException`

#### executeGET

    protected org.apache.http.HttpResponse executeGET(String request,
                                                      String... params)
                                               throws IOException

internal: execute a request and return its result The `params` argument is treated as: name1,value1,name2,value2,...

Throws:
  `IOException`

#### responseInputStream

    public InputStream responseInputStream(org.apache.http.HttpResponse response)
                                    throws IOException

Internal utility: input stream of the provided response

Throws:
  `IOException`

#### responseInputStream

    public InputStream responseInputStream(org.apache.http.HttpResponse response,
                                           boolean consume)
                                    throws IOException

Internal utility: input stream of the provided response, which optionally consumes the response's resources when the input stream is exhausted.

Throws:
  `IOException`

#### isClosed

    protected final boolean isClosed()

Returns true iff this instance was `closed`, otherwise returns false. Note that if you override `close()`, you must call `super.close()`, in order for this instance to be properly closed.

#### doAction

    protected <T> T doAction(org.apache.http.HttpResponse response,
                             Callable<T> call)
                      throws IOException

Same as `doAction(HttpResponse, boolean, Callable)` but always do consume at the end.

Throws:
  `IOException`

#### doAction

    protected <T> T doAction(org.apache.http.HttpResponse response,
                             boolean consume,
                             Callable<T> call)
                      throws IOException

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. Optionally release the response at exit, depending on `consume` parameter.

Throws:
  `IOException`

#### close

    public void close()
               throws IOException

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Throws:
  `IOException`