com.twitterapime.io
Interface HttpConnection


public interface HttpConnection

This interface defines the necessary methods and constants for an HTTP connection.

Since:
1.0
Version:
1.1
Author:
Ernandes Mourao Junior (ernandes@gmail.com)
See Also:
HttpConnector

Field Summary
static java.lang.String GET
           HTTP Get method.
static java.lang.String HEAD
           HTTP Head method.
static int HTTP_BAD_GATEWAY
           502: The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.
static int HTTP_BAD_REQUEST
           400: The request could not be understood by the server due to malformed syntax.
static int HTTP_FORBIDDEN
           403: The server understood the request, but is refusing to fulfill it.
static int HTTP_INTERNAL_ERROR
           500: The server encountered an unexpected condition which prevented it from fulfilling the request.
static int HTTP_NOT_ACCEPTABLE
           406: The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.
static int HTTP_NOT_FOUND
           404: The server has not found anything matching the Request-URI.
static int HTTP_NOT_MODIFIED
           304: If the client has performed a conditional GET request and access is allowed, but the document has not been modified, the server SHOULD respond with this status code.
static int HTTP_OK
           200: The request has succeeded.
static int HTTP_UNAUTHORIZED
           401: The request requires user authentication.
static int HTTP_UNAVAILABLE
           503: The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.
static java.lang.String POST
           HTTP Post method.
 
Method Summary
 void close()
           Close the connection.
 java.lang.String getHeaderField(java.lang.String name)
           Returns the value of the named header field.
 java.lang.String getRequestProperty(java.lang.String key)
           Returns the value of the named general request property for this connection.
 int getResponseCode()
           Returns the HTTP response status code, e.g., 200 (HTTP_OK).
 void open(java.lang.String url)
           Create and open a Http connection.
 java.io.InputStream openInputStream()
           Open and return an input stream for a connection.
 java.io.OutputStream openOutputStream()
           Open and return an output stream for a connection.
 void setRequestMethod(java.lang.String method)
           Set the method for the URL request, one of: GET, POST or HEAD.
 void setRequestProperty(java.lang.String key, java.lang.String value)
           Sets the general request property.
 

Field Detail

GET

static final java.lang.String GET

HTTP Get method.

See Also:
Constant Field Values

POST

static final java.lang.String POST

HTTP Post method.

See Also:
Constant Field Values

HEAD

static final java.lang.String HEAD

HTTP Head method.

See Also:
Constant Field Values

HTTP_OK

static final int HTTP_OK

200: The request has succeeded.

See Also:
Constant Field Values

HTTP_FORBIDDEN

static final int HTTP_FORBIDDEN

403: The server understood the request, but is refusing to fulfill it.

See Also:
Constant Field Values

HTTP_UNAVAILABLE

static final int HTTP_UNAVAILABLE

503: The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.

See Also:
Constant Field Values

HTTP_NOT_MODIFIED

static final int HTTP_NOT_MODIFIED

304: If the client has performed a conditional GET request and access is allowed, but the document has not been modified, the server SHOULD respond with this status code.

See Also:
Constant Field Values

HTTP_BAD_REQUEST

static final int HTTP_BAD_REQUEST

400: The request could not be understood by the server due to malformed syntax.

See Also:
Constant Field Values

HTTP_UNAUTHORIZED

static final int HTTP_UNAUTHORIZED

401: The request requires user authentication. The response MUST include a WWW-Authenticate header field containing a challenge applicable to the requested resource.

See Also:
Constant Field Values

HTTP_NOT_FOUND

static final int HTTP_NOT_FOUND

404: The server has not found anything matching the Request-URI.

See Also:
Constant Field Values

HTTP_NOT_ACCEPTABLE

static final int HTTP_NOT_ACCEPTABLE

406: The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

See Also:
Constant Field Values

HTTP_INTERNAL_ERROR

static final int HTTP_INTERNAL_ERROR

500: The server encountered an unexpected condition which prevented it from fulfilling the request.

See Also:
Constant Field Values

HTTP_BAD_GATEWAY

static final int HTTP_BAD_GATEWAY

502: The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.

See Also:
Constant Field Values
Method Detail

open

void open(java.lang.String url)
          throws java.io.IOException

Create and open a Http connection.

Parameters:
url - The URL for the connection.
Throws:
java.io.IOException - If an I/O error occurs.

close

void close()
           throws java.io.IOException

Close the connection.

Throws:
java.io.IOException - If an I/O error occurs.

getResponseCode

int getResponseCode()
                    throws java.io.IOException

Returns the HTTP response status code, e.g., 200 (HTTP_OK).

Returns:
the HTTP Status-Code or -1 if no status code can be discerned.
Throws:
java.io.IOException - If an I/O error occurs.

openInputStream

java.io.InputStream openInputStream()
                                    throws java.io.IOException

Open and return an input stream for a connection.

Returns:
An input stream.
Throws:
java.io.IOException - If an I/O error occurs.

openOutputStream

java.io.OutputStream openOutputStream()
                                      throws java.io.IOException

Open and return an output stream for a connection.

Returns:
An output stream.
Throws:
java.io.IOException - If an I/O error occurs.

setRequestMethod

void setRequestMethod(java.lang.String method)
                      throws java.io.IOException

Set the method for the URL request, one of: GET, POST or HEAD.

Parameters:
method - The HTTP method.
Throws:
java.io.IOException - If an I/O error occurs.

setRequestProperty

void setRequestProperty(java.lang.String key,
                        java.lang.String value)
                        throws java.io.IOException

Sets the general request property. If a property with the key already exists, overwrite its value with the new value.

Parameters:
key - The keyword by which the request is known (e.g., "accept").
value - the value associated with it.
Throws:
java.io.IOException - If an I/O error occurs.

getRequestProperty

java.lang.String getRequestProperty(java.lang.String key)
                                    throws java.io.IOException

Returns the value of the named general request property for this connection.

Parameters:
key - The keyword by which the request property is known (e.g., "accept").
Returns:
the value of the named general request property for this connection. If there is no key with the specified name then null is returned.
Throws:
java.io.IOException - If an I/O error occurs.

getHeaderField

java.lang.String getHeaderField(java.lang.String name)
                                throws java.io.IOException

Returns the value of the named header field.

Parameters:
name - Name of a header field.
Returns:
the value of the named header field, or null if there is no such field in the header.
Throws:
java.io.IOException - If an I/O error occurs.


Copyright © 2010 Twitter API ME Team. All Rights Reserved.