ch.hsr.bieridee.test.http
Class HttpHelper

java.lang.Object
  extended by ch.hsr.bieridee.test.http.HttpHelper

public final class HttpHelper
extends java.lang.Object

A helper class that simplifies HTTP requests. It supports request processors that can be added with addRequestProcessor.


Constructor Summary
HttpHelper()
           
 
Method Summary
 void addRequestProcessor(IRequestProcessor requestProcessor)
          Add a request processor.
 org.apache.http.HttpResponse delete(java.lang.String uri)
          Perform a DELETE request.
 org.apache.http.HttpResponse get(java.lang.String uri)
          Perform a GET request.
 org.apache.http.HttpResponse post(java.lang.String uri)
          Perform a POST request without body data.
 org.apache.http.HttpResponse post(java.lang.String uri, org.apache.http.entity.AbstractHttpEntity data, java.lang.String contentType)
          Perform a POST request with attached entity.
 org.apache.http.HttpResponse post(java.lang.String uri, org.json.JSONObject data)
          Perform a POST request with attached JSONObject entity.
 org.apache.http.HttpResponse put(java.lang.String uri)
          Perform a PUT request without body data.
 org.apache.http.HttpResponse put(java.lang.String uri, org.apache.http.entity.AbstractHttpEntity data, java.lang.String contentType)
          Perform a PUT request with attached entity.
 org.apache.http.HttpResponse put(java.lang.String uri, org.json.JSONObject data)
          Perform a PUT request with attached JSONObject entity.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpHelper

public HttpHelper()
Method Detail

addRequestProcessor

public void addRequestProcessor(IRequestProcessor requestProcessor)
Add a request processor.

Parameters:
requestProcessor - A subclass of IRequestProcessor

get

public org.apache.http.HttpResponse get(java.lang.String uri)
Perform a GET request.

Parameters:
uri - Full URI of the server resource
Returns:
A HttpResponse instance

post

public org.apache.http.HttpResponse post(java.lang.String uri)
Perform a POST request without body data.

Parameters:
uri - Full URI of the server resource
Returns:
A HttpResponse instance

post

public org.apache.http.HttpResponse post(java.lang.String uri,
                                         org.json.JSONObject data)
                                  throws org.json.JSONException,
                                         java.io.UnsupportedEncodingException
Perform a POST request with attached JSONObject entity.

Parameters:
uri - Full URI of the server resource
data - A NameValuePair array containing
Returns:
A HttpResponse instance
Throws:
org.json.JSONException
java.io.UnsupportedEncodingException

post

public org.apache.http.HttpResponse post(java.lang.String uri,
                                         org.apache.http.entity.AbstractHttpEntity data,
                                         java.lang.String contentType)
Perform a POST request with attached entity.

Parameters:
uri - Full URI of the server resource
data - A NameValuePair array containing
contentType - The Content-type string
Returns:
A HttpResponse instance

put

public org.apache.http.HttpResponse put(java.lang.String uri)
Perform a PUT request without body data.

Parameters:
uri - Full URI of the server resource
Returns:
A HttpResponse instance

put

public org.apache.http.HttpResponse put(java.lang.String uri,
                                        org.json.JSONObject data)
                                 throws org.json.JSONException,
                                        java.io.UnsupportedEncodingException
Perform a PUT request with attached JSONObject entity.

Parameters:
uri - Full URI of the server resource
data - A NameValuePair array containing
Returns:
A HttpResponse instance
Throws:
org.json.JSONException
java.io.UnsupportedEncodingException

put

public org.apache.http.HttpResponse put(java.lang.String uri,
                                        org.apache.http.entity.AbstractHttpEntity data,
                                        java.lang.String contentType)
Perform a PUT request with attached entity.

Parameters:
uri - Full URI of the server resource
data - A NameValuePair array containing
contentType - The Content-type string
Returns:
A HttpResponse instance

delete

public org.apache.http.HttpResponse delete(java.lang.String uri)
Perform a DELETE request.

Parameters:
uri - Full URI of the server resource
Returns:
A HttpResponse instance