public class APIHttpClient extends Object implements IAPIHttpClient
Modifier and Type | Class and Description |
---|---|
static class |
APIHttpClient.Builder
Use this to build instances of APIHttpClient
|
Modifier and Type | Field and Description |
---|---|
protected String |
accept
Types of encodings that are acceptable
|
protected String |
acceptLanguage
Accepted languages
|
static int |
DEFAULT_MAX_PER_ROUTE
Maximum connections per route
|
static int |
DEFAULT_MAX_TOTAL
Maximum connections
|
protected long |
readTimeout
The socket read timeout
|
protected String |
userAgent
The user agent string to use
|
Modifier | Constructor and Description |
---|---|
protected |
APIHttpClient(String userAgent,
long readTimeout,
String accept,
String acceptLanguage,
boolean allowgzip,
boolean allowUntrustedSSL,
String host,
long crawlDelay)
Create a new APIHttpClient instance
|
Modifier and Type | Method and Description |
---|---|
protected org.apache.http.impl.client.CloseableHttpClient |
buildClient(org.apache.http.impl.client.HttpClientBuilder builder)
Build the http client.
|
protected org.apache.http.HttpRequestInterceptor |
createAcceptInterceptor()
Adds Accept, Accept-Language and Accept-Encoding headers to the request.
|
protected org.apache.http.conn.ConnectionKeepAliveStrategy |
createConnectionKeepAliveStrategy()
Retrieve a keep alive strategy.
|
org.apache.http.impl.client.CloseableHttpClient |
createNewClient()
Create a new HttpClient instance to use
|
protected org.apache.http.client.RedirectStrategy |
createRedirectAndRobotsStrategy()
Create a redirect and robots.txt strategy
|
protected org.apache.http.client.config.RequestConfig |
createRequestConfig()
This sets the client cookie spec to CookieSpecs.BROWSER_COMPATIBILITY
|
protected org.apache.http.HttpRequestInterceptor |
createUserAgentInterceptor()
Adds the user agent to the request
|
String |
getAccept()
Retrieve the accept header value
|
String |
getAcceptLanguages()
Retrieve the Accept-Language header value
|
org.apache.http.impl.client.CloseableHttpClient |
getClient()
Retrieve a shared client instance to use
|
long |
getCrawlDelay()
Retrieve the crawl delay
|
org.apache.http.client.utils.URIBuilder |
getHost()
Retrieve the host
|
long |
getReadTimeout()
Retrieve the current socket read timeout value
|
String |
getUserAgent()
Retrieve the user agent
|
boolean |
isGzipAllowed()
Find out if gzip is allowed or not
|
static void |
shutdownConnectionManager()
Shutdown the underlying connection manager
|
public static final int DEFAULT_MAX_TOTAL
public static final int DEFAULT_MAX_PER_ROUTE
protected final String userAgent
protected final long readTimeout
protected final String accept
protected final String acceptLanguage
protected APIHttpClient(String userAgent, long readTimeout, String accept, String acceptLanguage, boolean allowgzip, boolean allowUntrustedSSL, String host, long crawlDelay) throws URISyntaxException
userAgent
- The user agentreadTimeout
- The read timeoutaccept
- The accept header valueacceptLanguage
- The accept language header valueallowgzip
- If gzip is allowedallowUntrustedSSL
- If untrusted ssl is allowedhost
- The host (http://donkey.co)crawlDelay
- some delay to use between requestsURISyntaxException
- If the host is invalidpublic static void shutdownConnectionManager()
public String getUserAgent()
getUserAgent
in interface IAPIHttpClient
public long getReadTimeout()
getReadTimeout
in interface IAPIHttpClient
public String getAccept()
getAccept
in interface IAPIHttpClient
public String getAcceptLanguages()
getAcceptLanguages
in interface IAPIHttpClient
public boolean isGzipAllowed()
isGzipAllowed
in interface IAPIHttpClient
public long getCrawlDelay()
getCrawlDelay
in interface IAPIHttpClient
public org.apache.http.client.utils.URIBuilder getHost()
getHost
in interface IAPIHttpClient
public org.apache.http.impl.client.CloseableHttpClient getClient()
getClient
in interface IAPIHttpClient
public org.apache.http.impl.client.CloseableHttpClient createNewClient() throws IllegalArgumentException, APIException
createNewClient
in interface IAPIHttpClient
IllegalArgumentException
APIException
- If there is a problem creating the client or strategyprotected org.apache.http.conn.ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy()
protected org.apache.http.client.config.RequestConfig createRequestConfig()
protected org.apache.http.client.RedirectStrategy createRedirectAndRobotsStrategy()
protected org.apache.http.HttpRequestInterceptor createUserAgentInterceptor()
protected org.apache.http.HttpRequestInterceptor createAcceptInterceptor()
protected org.apache.http.impl.client.CloseableHttpClient buildClient(org.apache.http.impl.client.HttpClientBuilder builder)
builder
- The client builderCopyright © 2017. All rights reserved.