public class HttpService
extends java.lang.Object
| Modifier and Type | Field and Description | 
|---|---|
static int | 
DEFAULT_CONNECT_TIMEOUT
Default connection timeout used by HttpService if none is given 
 | 
static int | 
DEFAULT_READ_TIMEOUT
Default read timeout used by HttpService if none is given 
 | 
static java.lang.String | 
TAG  | 
| Constructor and Description | 
|---|
HttpService()
When using the default constructor, DEFAULT_CONNECT_TIMEOUT and DEFAULT_READ_TIMEOUT are
 used for the timeout values. 
 | 
HttpService(int connectTimeout,
           int readTimeout)
Provides values for the connection timeout and read timeouts on instantiation. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
static java.net.URI | 
buildURIWithQueryParameters(java.lang.String baseUri,
                           java.util.Map<java.lang.String,java.lang.Object> parameters)
Convenience method to construct a URL object from a base URL string and a Map of query
 string parameters. 
 | 
java.lang.String | 
doGetRequest(java.net.URI uri)
Performs an HTTP GET request using the given URI. 
 | 
java.lang.String | 
doGetRequest(java.net.URI uri,
            java.util.Map<java.lang.String,java.lang.String> headers)
Performs an HTTP GET request using the given URI. 
 | 
android.graphics.Bitmap | 
doImageGetRequest(java.net.URI uri)
Performs and HTTP GET request expecting a bitmap image file in the response. 
 | 
android.graphics.Bitmap | 
doImageGetRequest(java.net.URI uri,
                 int maxWidth,
                 int maxHeight)
Performs and HTTP GET request expecting a bitmap image file in the response. 
 | 
org.json.JSONObject | 
doJSONGetRequest(java.net.URI uri)
Performs an HTTP GET request assuming that the response body will contain a valid JSON
 document. 
 | 
org.json.JSONObject | 
doJSONGetRequest(java.net.URI uri,
                java.util.Map<java.lang.String,java.lang.String> headers)
Performs an HTTP GET request assuming that the response body will contain a valid JSON
 document. 
 | 
org.json.JSONObject | 
doJSONPostRequest(java.net.URI uri)
Performs an HTTP POST request assuming that the response body will contain a valid JSON
 document. 
 | 
org.json.JSONObject | 
doJSONPostRequest(java.net.URI uri,
                 java.util.Map<java.lang.String,java.lang.String> headers)
Performs an HTTP POST request assuming that the response body will contain a valid JSON
 document. 
 | 
java.lang.String | 
doPostRequest(java.net.URI uri)
Performs an HTTP POST request using the given URI. 
 | 
java.lang.String | 
doPostRequest(java.net.URI uri,
             java.util.Map<java.lang.String,java.lang.String> headers)
Performs an HTTP POST request using the given URI. 
 | 
int | 
getConnectTimeout()
Retrieves the connection timeout used by this HttpService. 
 | 
int | 
getReadTimeout()
Retrieves the read timeout used by this HttpService. 
 | 
static java.lang.String | 
inputStreamToString(java.io.InputStream inputStream)
Reads all data from the given InputStream and converts to a String (Uses StringBuilder). 
 | 
static org.json.JSONObject | 
parseToJSONObject(java.lang.String jsonString)
Parses given string containing JSON data into a JSONObject which provides an interface
 for extracting JSON data. 
 | 
static java.lang.String | 
readerToString(java.io.Reader reader)
Reads all data from the given Reader and converts to a String (Uses StringBuilder). 
 | 
public static final java.lang.String TAG
public static final int DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_READ_TIMEOUT
public HttpService()
public HttpService(int connectTimeout,
                   int readTimeout)
connectTimeout - the connection timeout for the underlying HttpURLConnection, in
                       millisecondsreadTimeout - the read timeout for the underlying HttpURLConnection, in millisecondsHttpURLConnectionpublic int getConnectTimeout()
public int getReadTimeout()
public static java.net.URI buildURIWithQueryParameters(java.lang.String baseUri,
                                                       java.util.Map<java.lang.String,java.lang.Object> parameters)
                                                throws java.net.URISyntaxException,
                                                       java.io.UnsupportedEncodingException
baseUri - the scheme, hostname, and path portions of the URI to constructparameters - the query string parameters to be included in the URI (will be URI encoded)java.net.URISyntaxException - if the base URI is malformedjava.io.UnsupportedEncodingExceptionpublic java.lang.String doGetRequest(java.net.URI uri)
                              throws java.io.IOException
uri - the request URIjava.io.IOExceptionpublic java.lang.String doGetRequest(java.net.URI uri,
                                     java.util.Map<java.lang.String,java.lang.String> headers)
                              throws java.io.IOException
uri - the request URIjava.io.IOExceptionpublic java.lang.String doPostRequest(java.net.URI uri)
                               throws java.io.IOException
uri - the request URIjava.io.IOExceptionpublic java.lang.String doPostRequest(java.net.URI uri,
                                      java.util.Map<java.lang.String,java.lang.String> headers)
                               throws java.io.IOException
uri - the request URIjava.io.IOExceptionpublic android.graphics.Bitmap doImageGetRequest(java.net.URI uri)
                                          throws java.io.IOException
uri - the request URIjava.io.IOExceptionpublic android.graphics.Bitmap doImageGetRequest(java.net.URI uri,
                                                 int maxWidth,
                                                 int maxHeight)
                                          throws java.io.IOException
uri - the request URImaxWidth - The maximum width of the target view.maxHeight - The maximum height of the target view.java.io.IOExceptionpublic org.json.JSONObject doJSONGetRequest(java.net.URI uri)
                                     throws java.io.IOException,
                                            org.json.JSONException
uri - the request URIjava.io.IOExceptionorg.json.JSONExceptionpublic org.json.JSONObject doJSONGetRequest(java.net.URI uri,
                                            java.util.Map<java.lang.String,java.lang.String> headers)
                                     throws java.io.IOException,
                                            org.json.JSONException
uri - the request URIheaders - the request headersjava.io.IOExceptionorg.json.JSONExceptionpublic org.json.JSONObject doJSONPostRequest(java.net.URI uri)
                                      throws java.io.IOException,
                                             org.json.JSONException
uri - the request URIjava.io.IOExceptionorg.json.JSONExceptionpublic org.json.JSONObject doJSONPostRequest(java.net.URI uri,
                                             java.util.Map<java.lang.String,java.lang.String> headers)
                                      throws java.io.IOException,
                                             org.json.JSONException
uri - the request URIheaders - the request headersjava.io.IOExceptionorg.json.JSONExceptionpublic static java.lang.String inputStreamToString(java.io.InputStream inputStream)
                                            throws java.io.IOException
inputStream - InputStream from which String should be builtjava.io.IOExceptionpublic static java.lang.String readerToString(java.io.Reader reader)
                                       throws java.io.IOException
reader - Reader from which String should be builtjava.io.IOExceptionpublic static org.json.JSONObject parseToJSONObject(java.lang.String jsonString)
                                             throws org.json.JSONException
jsonString - the JSON object data to be parsed (must not be null or empty)org.json.JSONException - if there are any issues parsing the JSON