public class BasicHttpFetcher extends Object implements HttpFetcher
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.http.client.HttpClient |
FETCHER |
| Constructor and Description |
|---|
BasicHttpFetcher(int maxObjSize,
int connectionTimeoutMs,
int readTimeoutMs,
String basicHttpFetcherProxy)
Creates a new fetcher for fetching HTTP objects.
|
BasicHttpFetcher(String basicHttpFetcherProxy)
Creates a new fetcher using the default maximum object size and timeout --
no limit and 5 seconds.
|
| Modifier and Type | Method and Description |
|---|---|
HttpResponse |
fetch(HttpRequest request)
Fetch HTTP content.
|
void |
setConnectionTimeoutMs(int connectionTimeoutMs)
Change the global connection timeout for all new fetchs.
|
void |
setMaxObjectSizeBytes(int maxObjectSizeBytes)
Change the global maximum fetch size (in bytes) for all fetches.
|
void |
setReadTimeoutMs(int readTimeoutMs)
Change the global read timeout for all new fetchs.
|
void |
setSlowResponseWarning(long slowResponseWarning)
Change the global threshold for warning about slow responses
|
protected void |
slowResponseWarning(HttpRequest request,
long started,
long finished)
Called when a request takes too long.
|
byte[] |
toByteArraySafe(org.apache.http.HttpEntity entity)
This method is Safe replica version of org.apache.http.util.EntityUtils.toByteArray.
|
@Inject
public BasicHttpFetcher(@Nullable
String basicHttpFetcherProxy)
basicHttpFetcherProxy - The http proxy to use.public BasicHttpFetcher(int maxObjSize,
int connectionTimeoutMs,
int readTimeoutMs,
String basicHttpFetcherProxy)
maxObjSize - Maximum size, in bytes, of the object we will fetch, 0 if no limit..connectionTimeoutMs - timeout, in milliseconds, for connecting to hosts.readTimeoutMs - timeout, in millseconds, for unresponsive connectionsbasicHttpFetcherProxy - The http proxy to use.public HttpResponse fetch(HttpRequest request) throws GadgetException
HttpFetcherfetch in interface HttpFetcherrequest - The request to fetch.GadgetException - In the event of a failure that can't be mapped to an HTTP result code.protected void slowResponseWarning(HttpRequest request, long started, long finished)
request - the request that generated the slowrequeststarted - the time the request started, in milliseconds.finished - the time the request finished, in milliseconds.@Inject(optional=true) public void setMaxObjectSizeBytes(int maxObjectSizeBytes)
maxObjectSizeBytes - value for maximum number of bytes, or 0 for no limit@Inject(optional=true) public void setSlowResponseWarning(long slowResponseWarning)
slowResponseWarning - time in milliseconds after we issue a warning@Inject(optional=true) public void setConnectionTimeoutMs(int connectionTimeoutMs)
connectionTimeoutMs - new connection timeout in milliseconds@Inject(optional=true) public void setReadTimeoutMs(int readTimeoutMs)
readTimeoutMs - new connection timeout in millisecondspublic byte[] toByteArraySafe(org.apache.http.HttpEntity entity)
throws IOException
entity - IOException - if an error occurs reading the input streamCopyright © 2007-2012. All Rights Reserved.