|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.funambol.platform.HttpConnectionAdapter
public class HttpConnectionAdapter
This class is a simple HttpConnection class that wraps the underlying standard edition HttpURLConnection. Requests/responses can be written/read accessing the corresponding input and output streams. A portable code must use this class only to perform http connections, and must take care of closing the connection when not used anymore.
Example: void httpConnectionExample(String url) throws IOException { HttpConnectionAdapter conn = new HttpConnectionAdapter(); // Open the connection conn.open(url); conn.setRequestMethod(HttpConnectionAdapter.POST); conn.setRequestProperty("CUSTOM-HEADER", "CUSTOM-VALUE"); OutputStream os = conn.openOutputStream(); os.write("TEST"); os.close(); // Suppose the answer is bound to 1KB byte anwser[] = new byte[1024]; InputStream is = conn.openInputStream(); is.read(answer); is.close(); // Close the connection conn.close();
Constructor Summary | |
---|---|
HttpConnectionAdapter()
|
Method Summary | |
---|---|
void |
close()
This method closes this connection. |
java.lang.String |
getHeaderField(java.lang.String key)
Returns the value of the named header field. |
java.lang.String |
getHeaderFieldKey(int num)
Returns the key for the nth header field. |
int |
getLength()
Returns the answer length (excluding headers. |
int |
getResponseCode()
Returns the HTTP response status code. |
java.lang.String |
getResponseMessage()
Returns the HTTP response message. |
void |
open(java.lang.String url)
Open the connection to the given url. |
java.io.InputStream |
openInputStream()
Open the input stream. |
java.io.OutputStream |
openOutputStream()
Open the output stream. |
void |
setChunkedStreamingMode(int chunkLength)
Set chunked encoding for the file to be uploaded. |
void |
setRequestMethod(java.lang.String method)
Set the method for the URL request, one of: GET POST HEAD are legal, subject to protocol restrictions. |
void |
setRequestProperty(java.lang.String key,
java.lang.String value)
Sets the general request property. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static int HTTP_ACCEPTED
public static int HTTP_BAD_GATEWAY
public static int HTTP_BAD_METHOD
public static int HTTP_BAD_REQUEST
public static int HTTP_CLIENT_TIMEOUT
public static int HTTP_CONFLICT
public static int HTTP_CREATED
public static int HTTP_ENTITY_TOO_LARGE
public static int HTTP_FORBIDDEN
public static int HTTP_GATEWAY_TIMEOUT
public static int HTTP_GONE
public static int HTTP_INTERNAL_ERROR
public static int HTTP_LENGTH_REQUIRED
public static int HTTP_MOVED_PERM
public static int HTTP_MOVED_TEMP
public static int HTTP_MULT_CHOICE
public static int HTTP_NO_CONTENT
public static int HTTP_NOT_ACCEPTABLE
public static int HTTP_NOT_AUTHORITATIVE
public static int HTTP_NOT_FOUND
public static int HTTP_NOT_IMPLEMENTED
public static int HTTP_NOT_MODIFIED
public static int HTTP_OK
public static int HTTP_PARTIAL
public static int HTTP_PAYMENT_REQUIRED
public static int HTTP_PRECON_FAILED
public static int HTTP_PROXY_AUTH
public static int HTTP_REQ_TOO_LONG
public static int HTTP_RESET
public static int HTTP_SEE_OTHER
public static int HTTP_UNAUTHORIZED
public static int HTTP_UNAVAILABLE
public static int HTTP_UNSUPPORTED_TYPE
public static int HTTP_USE_PROXY
public static int HTTP_VERSION
public static int HTTP_EXPECT_FAILED
public static int HTTP_UNSUPPORTED_RANGE
public static int HTTP_TEMP_REDIRECT
public static final java.lang.String GET
public static final java.lang.String POST
public static final java.lang.String HEAD
Constructor Detail |
---|
public HttpConnectionAdapter()
Method Detail |
---|
public void open(java.lang.String url) throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
java.io.IOException
- if the connection cannot be closedpublic java.io.InputStream openInputStream() throws java.io.IOException
java.io.IOException
- if the input stream cannot be opened.public java.io.OutputStream openOutputStream() throws java.io.IOException
java.io.IOException
- if the output stream cannot be opened.public int getResponseCode() throws java.io.IOException
java.io.IOException
public java.lang.String getResponseMessage() throws java.io.IOException
java.io.IOException
public void setRequestMethod(java.lang.String method) throws java.io.IOException
java.io.IOException
public void setChunkedStreamingMode(int chunkLength) throws java.io.IOException
chunkLength
- the length of the single chunk
java.io.IOException
public void setRequestProperty(java.lang.String key, java.lang.String value) throws java.io.IOException
key
- the keyword by which the request is known (e.g., "accept").value
- the value associated with it.
java.io.IOException
public java.lang.String getHeaderField(java.lang.String key) throws java.io.IOException
key
- name of a header field.
java.io.IOException
- if an error occurred connecting to the server.public java.lang.String getHeaderFieldKey(int num) throws java.io.IOException
java.io.IOException
public int getLength() throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |