|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.webkit.gears.HttpRequestAndroid
public final class HttpRequestAndroid
Performs the underlying HTTP/HTTPS GET and POST requests.
These are performed synchronously (blocking). The caller should ensure that it is in a background thread if asynchronous behavior is required. All data is pushed, so there is no need for JNI native callbacks.
This uses the java.net.HttpURLConnection class to perform most of the underlying network activity. The Android brower's cache, android.webkit.CacheManager, is also used when caching is enabled, and updated with new data. The android.webkit.CookieManager is also queried and updated as necessary.
The public interface is designed to be called by native code through JNI, and to simplify coding none of the public methods will surface a checked exception. Unchecked exceptions may still be raised but only if the system is in an ill state, such as out of memory.
TODO: This isn't plumbed into LocalServer yet. Mutually dependent on LocalServer - will attach the two together once both are submitted.
| Field Summary | |
|---|---|
static int |
HEADERS_MAP_INDEX_KEY
The first element of the String[] value in a headers map is the unmodified (case-sensitive) key. |
static int |
HEADERS_MAP_INDEX_VALUE
The second element of the String[] value in a headers map is the associated value. |
static String |
KEY_CONTENT_LENGTH
Case-sensitive header keys |
static String |
KEY_CONTENT_TYPE
|
static String |
KEY_ETAG
|
static String |
KEY_EXPIRES
|
static String |
KEY_LAST_MODIFIED
|
static String |
KEY_LOCATION
|
| Constructor Summary | |
|---|---|
HttpRequestAndroid()
|
|
| Method Summary | |
|---|---|
boolean |
appendCacheResult(byte[] data,
int bytes)
Add data from the response body to the CacheResult created with createCacheResult(). |
boolean |
connectToRemote()
Perform an HTTP request on the network. |
boolean |
createCacheResult(String url,
int responseCode,
String mimeType,
String encoding)
Create a CacheResult for this URL. |
static void |
enableLogging(boolean on)
Turn on/off logging in this class. |
String |
getAllResponseHeaders()
Return all response headers, separated by CR-LF line endings, and ending with a trailing blank line. |
static String |
getCookieForUrl(String url)
Get the cookie for the given URL. |
String |
getRequestHeader(String name)
Returns the value associated with the given request header. |
String |
getResponseHeader(String name)
Returns the value associated with the given response header. |
String |
getResponseLine()
Get the complete response line of the HTTP request. |
void |
initChildThread()
Initialize childThread using the TLS value of Thread.currentThread(). |
void |
interrupt()
Interrupt a blocking IO operation. |
boolean |
open(String method,
String url)
Analagous to the native-side HttpRequest::open() function. |
boolean |
parseHeaders()
Receive all headers from the server and populate responseHeaders. |
int |
receive(byte[] buf)
Receive the next sequential bytes of the response body after successful connection. |
boolean |
saveCacheResult()
Save the completed CacheResult into the CacheManager. |
boolean |
sendPostData(byte[] data,
int bytes)
For POST method requests, send a stream of data provided by the native side in repeated callbacks. |
static void |
setCookieForUrl(String url,
String cookie)
Set the cookie for the given URL. |
void |
setRequestHeader(String name,
String value)
Set a header to send with the HTTP request. |
boolean |
useCacheResult(String url)
Perform a request using the cache result if present. |
boolean |
useLocalServerResult(String url)
Perform a request using LocalServer if possible. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String KEY_CONTENT_LENGTH
public static final String KEY_EXPIRES
public static final String KEY_LAST_MODIFIED
public static final String KEY_ETAG
public static final String KEY_LOCATION
public static final String KEY_CONTENT_TYPE
public static final int HEADERS_MAP_INDEX_KEY
public static final int HEADERS_MAP_INDEX_VALUE
| Constructor Detail |
|---|
public HttpRequestAndroid()
| Method Detail |
|---|
public static void enableLogging(boolean on)
on - Logging enable state.public void initChildThread()
public boolean open(String method,
String url)
method - The HTTP method, e.g GET or POST.url - The URL to open.
public void interrupt()
public void setRequestHeader(String name,
String value)
name - The name of the header, e.g "Set-Cookie".value - The value for this header, e.g "text/html".public String getRequestHeader(String name)
name - The name of the request header, non-null, case-insensitive.
public String getResponseHeader(String name)
name - The name of the response header, non-null, case-insensitive.
public String getAllResponseHeaders()
public String getResponseLine()
public static String getCookieForUrl(String url)
url - The fully qualified URL.
public static void setCookieForUrl(String url,
String cookie)
url - The fully qualified URL.cookie - The new cookie value.public boolean useLocalServerResult(String url)
url - The fully qualified URL to try in LocalServer.
public boolean useCacheResult(String url)
url - The fully qualified URL to try in the cache.
public boolean createCacheResult(String url,
int responseCode,
String mimeType,
String encoding)
url - The fully qualified URL to add to the cache.responseCode - The response code returned for the request, e.g 200.mimeType - The MIME type of the body, e.g "text/plain".encoding - The encoding, e.g "utf-8". Use "" for unknown.
public boolean appendCacheResult(byte[] data,
int bytes)
data - A byte array of the next sequential bytes in the
response body.bytes - The number of bytes to write from the start of
the array.
public boolean saveCacheResult()
public boolean connectToRemote()
public boolean parseHeaders()
public int receive(byte[] buf)
buf - A pre-allocated byte array to receive data into.
public boolean sendPostData(byte[] data,
int bytes)
data - A byte array containing the data to sent, or null
if indicating EOF.bytes - The number of bytes from the start of the array to
send, or 0 if indicating EOF.
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||