com.github.ignition.support.http
Class IgnitedHttp

java.lang.Object
  extended by com.github.ignition.support.http.IgnitedHttp

public class IgnitedHttp
extends Object


Field Summary
static String DEFAULT_HTTP_USER_AGENT
           
static int DEFAULT_MAX_CONNECTIONS
           
static int DEFAULT_SOCKET_TIMEOUT
           
static int DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT
           
static String ENCODING_GZIP
           
static String HEADER_ACCEPT_ENCODING
           
 
Constructor Summary
IgnitedHttp()
           
IgnitedHttp(android.content.Context context)
           
 
Method Summary
 IgnitedHttpRequest delete(String url)
           
 void disableResponseCache(boolean wipe)
          Disables caching of HTTP responses.
 void enableResponseCache(android.content.Context context, int initialCapacity, long expirationInMinutes, int maxConcurrentThreads, int diskCacheStorageDevice)
          Enables caching of HTTP responses.
 void enableResponseCache(int initialCapacity, long expirationInMinutes, int maxConcurrentThreads)
          Enables caching of HTTP responses.
 IgnitedHttpRequest get(String url)
           
 IgnitedHttpRequest get(String url, boolean cached)
           
 HashMap<String,String> getDefaultHeaders()
           
 org.apache.http.impl.client.AbstractHttpClient getHttpClient()
           
 HttpResponseCache getResponseCache()
           
 void listenForConnectivityChanges(android.content.Context context)
          Registers a broadcast receiver with the application context that will take care of updating proxy settings when failing over between 3G and Wi-Fi.
 IgnitedHttpRequest post(String url)
           
 IgnitedHttpRequest post(String url, org.apache.http.HttpEntity payload)
           
 IgnitedHttpRequest put(String url)
           
 IgnitedHttpRequest put(String url, org.apache.http.HttpEntity payload)
           
 void setConnectionTimeout(int connectionTimeout)
          Adjust the connection timeout, i.e.
 void setDefaultHeader(String header, String value)
           
 void setGzipEncodingEnabled(boolean enabled)
           
 void setHttpClient(org.apache.http.impl.client.AbstractHttpClient httpClient)
           
 void setMaximumConnections(int maxConnections)
           
 void setPortForScheme(String scheme, int port)
           
 void setSocketTimeout(int socketTimeout)
          Adjust the socket timeout, i.e.
protected  void setupHttpClient()
           
 void updateProxySettings(android.content.Context context)
          Updates the underlying HTTP client's proxy settings with what the user has entered in the APN settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_CONNECTIONS

public static final int DEFAULT_MAX_CONNECTIONS
See Also:
Constant Field Values

DEFAULT_SOCKET_TIMEOUT

public static final int DEFAULT_SOCKET_TIMEOUT
See Also:
Constant Field Values

DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT

public static final int DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT
See Also:
Constant Field Values

DEFAULT_HTTP_USER_AGENT

public static final String DEFAULT_HTTP_USER_AGENT
See Also:
Constant Field Values

HEADER_ACCEPT_ENCODING

public static final String HEADER_ACCEPT_ENCODING
See Also:
Constant Field Values

ENCODING_GZIP

public static final String ENCODING_GZIP
See Also:
Constant Field Values
Constructor Detail

IgnitedHttp

public IgnitedHttp()

IgnitedHttp

public IgnitedHttp(android.content.Context context)
Method Detail

setupHttpClient

protected void setupHttpClient()

listenForConnectivityChanges

public void listenForConnectivityChanges(android.content.Context context)
Registers a broadcast receiver with the application context that will take care of updating proxy settings when failing over between 3G and Wi-Fi. This requires the Manifest.permission#ACCESS_NETWORK_STATE permission.

Parameters:
context - the context used to retrieve the app context

setGzipEncodingEnabled

public void setGzipEncodingEnabled(boolean enabled)

enableResponseCache

public void enableResponseCache(int initialCapacity,
                                long expirationInMinutes,
                                int maxConcurrentThreads)
Enables caching of HTTP responses. This will only enable the in-memory cache. If you also want to enable the disk cache, see enableResponseCache(Context, int, long, int, int) .

Parameters:
initialCapacity - the initial element size of the cache
expirationInMinutes - time in minutes after which elements will be purged from the cache
maxConcurrentThreads - how many threads you think may at once access the cache; this need not be an exact number, but it helps in fragmenting the cache properly
See Also:
HttpResponseCache

enableResponseCache

public void enableResponseCache(android.content.Context context,
                                int initialCapacity,
                                long expirationInMinutes,
                                int maxConcurrentThreads,
                                int diskCacheStorageDevice)
Enables caching of HTTP responses. This will also enable the disk cache.

Parameters:
context - the current context
initialCapacity - the initial element size of the cache
expirationInMinutes - time in minutes after which elements will be purged from the cache (NOTE: this only affects the memory cache, the disk cache does currently NOT handle element TTLs!)
maxConcurrentThreads - how many threads you think may at once access the cache; this need not be an exact number, but it helps in fragmenting the cache properly
diskCacheStorageDevice - where files should be cached persistently ( AbstractCache.DISK_CACHE_INTERNAL, AbstractCache.DISK_CACHE_SDCARD )
See Also:
HttpResponseCache

disableResponseCache

public void disableResponseCache(boolean wipe)
Disables caching of HTTP responses. You may also choose to wipe any files that may have been written to disk.


getResponseCache

public HttpResponseCache getResponseCache()
Returns:
the response cache, if enabled, otherwise null

setHttpClient

public void setHttpClient(org.apache.http.impl.client.AbstractHttpClient httpClient)

getHttpClient

public org.apache.http.impl.client.AbstractHttpClient getHttpClient()

updateProxySettings

public void updateProxySettings(android.content.Context context)
Updates the underlying HTTP client's proxy settings with what the user has entered in the APN settings. This will be called automatically if listenForConnectivityChanges(Context) has been called. This requires the Manifest.permission#ACCESS_NETWORK_STATE permission.

Parameters:
context - the current context

get

public IgnitedHttpRequest get(String url)

get

public IgnitedHttpRequest get(String url,
                              boolean cached)

post

public IgnitedHttpRequest post(String url)

post

public IgnitedHttpRequest post(String url,
                               org.apache.http.HttpEntity payload)

put

public IgnitedHttpRequest put(String url)

put

public IgnitedHttpRequest put(String url,
                              org.apache.http.HttpEntity payload)

delete

public IgnitedHttpRequest delete(String url)

setMaximumConnections

public void setMaximumConnections(int maxConnections)

setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)
Adjust the connection timeout, i.e. the amount of time that may pass in order to establish a connection with the server. Time unit is milliseconds.

Parameters:
connectionTimeout - the timeout in milliseconds
See Also:
CoreConnectionPNames.CONNECTION_TIMEOUT

setSocketTimeout

public void setSocketTimeout(int socketTimeout)
Adjust the socket timeout, i.e. the amount of time that may pass when waiting for data coming in from the server. Time unit is milliseconds.

Parameters:
socketTimeout - the timeout in milliseconds
See Also:
CoreConnectionPNames.SO_TIMEOUT

setDefaultHeader

public void setDefaultHeader(String header,
                             String value)

getDefaultHeaders

public HashMap<String,String> getDefaultHeaders()

setPortForScheme

public void setPortForScheme(String scheme,
                             int port)


Copyright © 2012. All Rights Reserved.