|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.funambol.platform.HttpConnectionAdapter
com.funambol.platform.HttpConnectionAdapterWrapper
public class HttpConnectionAdapterWrapper
This class is a simple HttpConnection class that wraps the underlying microedition HttpConnection. 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();
Field Summary |
---|
Constructor Summary | |
---|---|
HttpConnectionAdapterWrapper()
|
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 |
Constructor Detail |
---|
public HttpConnectionAdapterWrapper()
Method Detail |
---|
public void open(java.lang.String url) throws java.io.IOException
open
in class HttpConnectionAdapter
java.io.IOException
public void close() throws java.io.IOException
close
in class HttpConnectionAdapter
java.io.IOException
- if the connection cannot be closedpublic java.io.InputStream openInputStream() throws java.io.IOException
openInputStream
in class HttpConnectionAdapter
java.io.IOException
- if the input stream cannot be opened or the output
stream has not been closed yet.public java.io.OutputStream openOutputStream() throws java.io.IOException
openOutputStream
in class HttpConnectionAdapter
java.io.IOException
- if the output stream cannot be opened.public int getResponseCode() throws java.io.IOException
getResponseCode
in class HttpConnectionAdapter
java.io.IOException
public java.lang.String getResponseMessage() throws java.io.IOException
getResponseMessage
in class HttpConnectionAdapter
java.io.IOException
public void setRequestMethod(java.lang.String method) throws java.io.IOException
setRequestMethod
in class HttpConnectionAdapter
java.io.IOException
public void setChunkedStreamingMode(int chunkLength) throws java.io.IOException
setChunkedStreamingMode
in class HttpConnectionAdapter
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
setRequestProperty
in class HttpConnectionAdapter
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
getHeaderField
in class HttpConnectionAdapter
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
getHeaderFieldKey
in class HttpConnectionAdapter
java.io.IOException
public int getLength() throws java.io.IOException
getLength
in class HttpConnectionAdapter
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |