com.github.ignition.support.http
Class IgnitedHttpRequestBase

java.lang.Object
  extended by com.github.ignition.support.http.IgnitedHttpRequestBase
All Implemented Interfaces:
IgnitedHttpRequest, org.apache.http.client.ResponseHandler<IgnitedHttpResponse>

public abstract class IgnitedHttpRequestBase
extends Object
implements IgnitedHttpRequest, org.apache.http.client.ResponseHandler<IgnitedHttpResponse>


Field Summary
protected  Set<Integer> expectedStatusCodes
           
protected static String HTTP_CONTENT_TYPE_HEADER
           
protected  org.apache.http.impl.client.AbstractHttpClient httpClient
           
protected  IgnitedHttp ignitedHttp
           
protected  int maxRetries
           
protected  org.apache.http.client.methods.HttpUriRequest request
           
 
Method Summary
 IgnitedHttpRequestBase 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()
           
 IgnitedHttpResponse handleResponse(org.apache.http.HttpResponse response)
           
 IgnitedHttpRequestBase retries(int retries)
          Set maximum number of retries for this particular request.
 IgnitedHttpResponse send()
          Sends the current request.
 org.apache.http.client.methods.HttpUriRequest unwrap()
           
 IgnitedHttpRequest withTimeout(int timeout)
          Set the global timeout for this specific request (connection and socket timeout).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_CONTENT_TYPE_HEADER

protected static final String HTTP_CONTENT_TYPE_HEADER
See Also:
Constant Field Values

expectedStatusCodes

protected Set<Integer> expectedStatusCodes

ignitedHttp

protected IgnitedHttp ignitedHttp

httpClient

protected org.apache.http.impl.client.AbstractHttpClient httpClient

request

protected org.apache.http.client.methods.HttpUriRequest request

maxRetries

protected int maxRetries
Method Detail

unwrap

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

getRequestUrl

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

expecting

public IgnitedHttpRequestBase expecting(Integer... statusCodes)
Description copied from interface: IgnitedHttpRequest
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 IgnitedHttpRequest
Parameters:
statusCodes - the set of status codes that you want to manually handle as part of the response
Returns:
this request

retries

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

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

withTimeout

public IgnitedHttpRequest withTimeout(int timeout)
Description copied from interface: IgnitedHttpRequest
Set the global timeout for this specific request (connection and socket timeout).

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

send

public IgnitedHttpResponse send()
                         throws ConnectException
Description copied from interface: IgnitedHttpRequest
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 IgnitedHttpRequest
Throws:
ConnectException

handleResponse

public IgnitedHttpResponse handleResponse(org.apache.http.HttpResponse response)
                                   throws IOException
Specified by:
handleResponse in interface org.apache.http.client.ResponseHandler<IgnitedHttpResponse>
Throws:
IOException


Copyright © 2012. All Rights Reserved.