de.enough.polish.io
Class PostRedirectHttpConnection

java.lang.Object
  extended by de.enough.polish.io.RedirectHttpConnection
      extended by de.enough.polish.io.PostRedirectHttpConnection
All Implemented Interfaces:
Connection, ContentConnection, HttpConnection, InputConnection, OutputConnection, StreamConnection

public class PostRedirectHttpConnection
extends RedirectHttpConnection

Provides a HttpConnection that supports HTTP redirects and allows easy creation of HTTP POST requests. This class is compatible to javax.microedition.io.HttpConnection.

When connecting to an URL and a HTTP redirect is return this class follows the redirect and uses the following HTTP connection. This works over multiple levels. By default five redirects are supported. The number of supported redirects can be tuned by setting the preprocessing variable polish.Browser.MaxRedirects to some integer value.

You can specify a timeout with the PostRedirectHttpConnection( String url, int timeout) or PostRedirectHttpConnection( String url, Hashmap requestProperties, int timeout) constructor. On MIDP and BlackBerry devices this will result in an additional thread being launched that waits for the specific time and then closes the connection in case it has so far not succeeded.

See Also:
HttpRedirectConnection

Field Summary
 
Fields inherited from interface javax.microedition.io.HttpConnection
GET, HEAD, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_EXPECT_FAILED, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_TEMP_REDIRECT, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_RANGE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, POST
 
Constructor Summary
PostRedirectHttpConnection(String url)
          Creates a new http connection that understands redirects.
PostRedirectHttpConnection(String url, HashMap requestProperties)
          Creates a new http connection that understands redirects.
PostRedirectHttpConnection(String url, HashMap requestProperties, int timeout)
          Creates a new http connection that understands redirects.
PostRedirectHttpConnection(String url, int timeout)
          Creates a new http connection that understands redirects.
 
Method Summary
 void addPostParameter(String name, String value)
          Adds a parameter for this post request
protected  void ensureConnectionCreated()
          Makes sure that the http connect got created.
 
Methods inherited from class de.enough.polish.io.RedirectHttpConnection
close, getDate, getEncoding, getExpiration, getFile, getHeaderField, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHost, getLastModified, getLength, getPort, getProtocol, getQuery, getRef, getRequestMethod, getRequestProperty, getResponseCode, getResponseMessage, getType, getURL, openDataInputStream, openDataOutputStream, openInputStream, openOutputStream, setLimitContentLengthParams, setRequestMethod, setRequestProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PostRedirectHttpConnection

public PostRedirectHttpConnection(String url)
                           throws IOException
Creates a new http connection that understands redirects.

Parameters:
url - the url to connect to
Throws:
IOException - when Connector.open() fails

PostRedirectHttpConnection

public PostRedirectHttpConnection(String url,
                                  int timeout)
                           throws IOException
Creates a new http connection that understands redirects.

Parameters:
url - the url to connect to
Throws:
IOException - when Connector.open() fails

PostRedirectHttpConnection

public PostRedirectHttpConnection(String url,
                                  HashMap requestProperties)
                           throws IOException
Creates a new http connection that understands redirects.

Parameters:
url - the url to connect to
requestProperties - the request properties to be set for each http request
Throws:
IOException - when Connector.open() fails

PostRedirectHttpConnection

public PostRedirectHttpConnection(String url,
                                  HashMap requestProperties,
                                  int timeout)
                           throws IOException
Creates a new http connection that understands redirects.

Parameters:
url - the url to connect to
requestProperties - the request properties to be set for each http request
Throws:
IOException - when Connector.open() fails
Method Detail

addPostParameter

public void addPostParameter(String name,
                             String value)
Adds a parameter for this post request

Parameters:
name - the name of the parameter
value - the value

ensureConnectionCreated

protected void ensureConnectionCreated()
                                throws IOException
Description copied from class: RedirectHttpConnection
Makes sure that the http connect got created. This method redirects until the final connection is created.

Overrides:
ensureConnectionCreated in class RedirectHttpConnection
Throws:
IOException - when the connection failed