com.github.droidfu.http
Class CachedHttpRequest

java.lang.Object
  extended by com.github.droidfu.http.CachedHttpRequest
All Implemented Interfaces:
BetterHttpRequest

public class CachedHttpRequest
extends Object
implements BetterHttpRequest


Constructor Summary
CachedHttpRequest(String url)
           
 
Method Summary
 BetterHttpRequest expecting(Integer... statusCodes)
          Define the set of HTTP status codes which you anticipate to be returned by the server, including error codes you'd like to explicitly handle.
 String getRequestUrl()
           
 BetterHttpRequest retries(int retries)
          Set maximum number of retries for this particular request.
 BetterHttpResponse send()
          Sends the current request.
 org.apache.http.client.methods.HttpUriRequest unwrap()
           
 BetterHttpRequest withTimeout(int timeout)
          Set the socket timeout for this specific request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedHttpRequest

public CachedHttpRequest(String url)
Method Detail

getRequestUrl

public String getRequestUrl()
Specified by:
getRequestUrl in interface BetterHttpRequest
Returns:
the request URL

expecting

public BetterHttpRequest expecting(Integer... statusCodes)
Description copied from interface: BetterHttpRequest
Define the set of HTTP status codes which you anticipate to be returned by the server, including error codes you'd like to explicitly handle. Any status code part of this set will not be treated as an error, but returned to you as a normal server response. Any status codes returned by the server that are not part of this set will be raised as an HttpResponseException. This is very useful when dealing with REST-ful Web services, where it is common to serve error stati that indicate a failure in the application logic (e.g. 404 if a resource doesn't exist). You typically don't want to treat those as connection errors, but gracefully handle them like a normal success code.

Specified by:
expecting in interface BetterHttpRequest
Parameters:
statusCodes - the set of status codes that you want to manually handle as part of the response
Returns:
this request

retries

public BetterHttpRequest retries(int retries)
Description copied from interface: BetterHttpRequest
Set maximum number of retries for this particular request.

Specified by:
retries in interface BetterHttpRequest
Parameters:
retries - the maximum number of retries should the request fail
Returns:
this request

send

public BetterHttpResponse send()
                        throws ConnectException
Description copied from interface: BetterHttpRequest
Sends the current request. This method uses a special retry-logic (on top of that employed by HttpClient, which is better suited to handle network fail-overs when e.g. switching between Wi-Fi and 3G).

Specified by:
send in interface BetterHttpRequest
Throws:
ConnectException

unwrap

public org.apache.http.client.methods.HttpUriRequest unwrap()
Specified by:
unwrap in interface BetterHttpRequest
Returns:
the HttpClient request object wrapped by this request

withTimeout

public BetterHttpRequest withTimeout(int timeout)
Description copied from interface: BetterHttpRequest
Set the socket timeout for this specific request.

Specified by:
withTimeout in interface BetterHttpRequest
Parameters:
timeout - the timeout in milliseconds
Returns:
this request


Copyright © 2011. All Rights Reserved.