com.dyuproject.util.http
Class SimpleHttpConnector

java.lang.Object
  extended by com.dyuproject.util.http.SimpleHttpConnector
All Implemented Interfaces:
HttpConnector

public final class SimpleHttpConnector
extends Object
implements HttpConnector

Simple http connector using the built-in HttpURLConnection

Author:
David Yu
Date created:
Sep 8, 2008

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.dyuproject.util.http.HttpConnector
HttpConnector.Parameter, HttpConnector.Response
 
Field Summary
static int DEFAULT_BUFFER_SIZE
          THe default buffer size (4096 or the system property "shc.buffer_size")
static int DEFAULT_CONNECT_TIMEOUT
          The default connect timeout (10000 or the system property "shc.connect_timeout")
static boolean DEFAULT_FOLLOW_REDIRECT
          The defualt follow redirect flag (false or the system property "shc.follow_redirects")
 
Fields inherited from interface com.dyuproject.util.http.HttpConnector
CONTENT_LENGTH_HEADER, CONTENT_TYPE_HEADER, DEFAULT_ENCODING, DELETE, GET, HEAD, POST, PUT, X_WWW_FORM_URLENCODED
 
Constructor Summary
SimpleHttpConnector()
           
SimpleHttpConnector(int bufferSize, int connectTimeout, boolean followRedirects)
           
 
Method Summary
 HttpConnector.Response doDELETE(String url, Iterable<HttpConnector.Parameter> headers)
          Makes a DELETE request with the given http headers.
 HttpConnector.Response doDELETE(String url, Iterable<HttpConnector.Parameter> headers, Iterable<HttpConnector.Parameter> parameters)
          Makes a DELETE request with the given http headers, parameters.
 HttpConnector.Response doDELETE(String url, Iterable<HttpConnector.Parameter> headers, Map<?,?> parameters)
          Makes a DELETE request with the given http headers, parameters.
 HttpConnector.Response doDELETE(String url, Map<?,?> headers)
          Makes a DELETE request with the given http headers.
 HttpConnector.Response doDELETE(String url, Map<?,?> headers, Map<?,?> parameters)
          Makes a DELETE request with the given http headers, parameters.
 HttpConnector.Response doGET(String url, Iterable<HttpConnector.Parameter> headers)
          Makes a GET request with the given http headers.
 HttpConnector.Response doGET(String url, Iterable<HttpConnector.Parameter> headers, Iterable<HttpConnector.Parameter> parameters)
          Makes a GET request with the given http headers, parameters.
 HttpConnector.Response doGET(String url, Iterable<HttpConnector.Parameter> headers, Map<?,?> parameters)
          Makes a GET request with the given http headers, parameters.
 HttpConnector.Response doGET(String url, Map<?,?> headers)
          Makes a GET request with the given http headers.
 HttpConnector.Response doGET(String url, Map<?,?> headers, Map<?,?> parameters)
          Makes a GET request with the given http headers, parameters.
 HttpConnector.Response doHEAD(String url, Iterable<HttpConnector.Parameter> headers)
          Makes a HEAD request with the given http headers.
 HttpConnector.Response doHEAD(String url, Map<?,?> headers)
          Makes a HEAD request with the given http headers.
 HttpConnector.Response doPOST(String url, Iterable<HttpConnector.Parameter> headers, Iterable<HttpConnector.Parameter> parameters, String charset)
          Makes a POST request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.
 HttpConnector.Response doPOST(String url, Iterable<HttpConnector.Parameter> headers, Map<?,?> parameters, String charset)
          Makes a POST request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.
 HttpConnector.Response doPOST(String url, Iterable<HttpConnector.Parameter> headers, String contentType, byte[] data)
          Makes a POST request with the given http headers, parameters, contentType and the content data.
 HttpConnector.Response doPOST(String url, Iterable<HttpConnector.Parameter> headers, String contentType, InputStreamReader reader)
          Makes a POST request with the given http headers, parameters, contentType and the content reader as InputStreamReader.
 HttpConnector.Response doPOST(String url, Map<?,?> headers, Iterable<HttpConnector.Parameter> parameters, String charset)
          Makes a POST request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.
 HttpConnector.Response doPOST(String url, Map<?,?> headers, Map<?,?> parameters, String charset)
          Makes a POST request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.
 HttpConnector.Response doPOST(String url, Map<?,?> headers, String contentType, byte[] data)
          Makes a POST request with the given http headers, parameters and the content data.
 HttpConnector.Response doPOST(String url, Map<?,?> headers, String contentType, InputStreamReader reader)
          Makes a POST request with the given http headers, parameters, contentType and the content reader as InputStreamReader.
 HttpConnector.Response doPUT(String url, Iterable<HttpConnector.Parameter> headers, Iterable<HttpConnector.Parameter> parameters, String charset)
          Makes a PUT request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.
 HttpConnector.Response doPUT(String url, Iterable<HttpConnector.Parameter> headers, Map<?,?> parameters, String charset)
          Makes a PUT request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.
 HttpConnector.Response doPUT(String url, Iterable<HttpConnector.Parameter> headers, String contentType, byte[] data)
          Makes a PUT request with the given http headers, parameters and the content data.
 HttpConnector.Response doPUT(String url, Iterable<HttpConnector.Parameter> headers, String contentType, InputStreamReader reader)
          Makes a PUT request with the given http headers, parameters, contentType and the content reader as InputStreamReader.
 HttpConnector.Response doPUT(String url, Map<?,?> headers, Iterable<HttpConnector.Parameter> parameters, String charset)
          Makes a PUT request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.
 HttpConnector.Response doPUT(String url, Map<?,?> headers, Map<?,?> parameters, String charset)
          Makes a PUT request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.
 HttpConnector.Response doPUT(String url, Map<?,?> headers, String contentType, byte[] data)
          Makes a PUT request with the given http headers, parameters and the content data.
 HttpConnector.Response doPUT(String url, Map<?,?> headers, String contentType, InputStreamReader reader)
          Makes a PUT request with the given http headers, parameters, contentType and the content reader as InputStreamReader.
 int getBufferSize()
          Gets the buffer size.
 int getConnectTimeout()
          Gets the connection timeout.
static SimpleHttpConnector getDefault()
          Gets the default instance.
 boolean isFollowRedirects()
          Checks whether this instance follows redirects or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static int DEFAULT_BUFFER_SIZE
THe default buffer size (4096 or the system property "shc.buffer_size")


DEFAULT_CONNECT_TIMEOUT

public static int DEFAULT_CONNECT_TIMEOUT
The default connect timeout (10000 or the system property "shc.connect_timeout")


DEFAULT_FOLLOW_REDIRECT

public static boolean DEFAULT_FOLLOW_REDIRECT
The defualt follow redirect flag (false or the system property "shc.follow_redirects")

Constructor Detail

SimpleHttpConnector

public SimpleHttpConnector()

SimpleHttpConnector

public SimpleHttpConnector(int bufferSize,
                           int connectTimeout,
                           boolean followRedirects)
Method Detail

getDefault

public static SimpleHttpConnector getDefault()
Gets the default instance.


getBufferSize

public int getBufferSize()
Gets the buffer size.


getConnectTimeout

public int getConnectTimeout()
Gets the connection timeout.


isFollowRedirects

public boolean isFollowRedirects()
Checks whether this instance follows redirects or not.


doHEAD

public HttpConnector.Response doHEAD(String url,
                                     Map<?,?> headers)
                              throws IOException
Description copied from interface: HttpConnector
Makes a HEAD request with the given http headers.

Specified by:
doHEAD in interface HttpConnector
Throws:
IOException

doHEAD

public HttpConnector.Response doHEAD(String url,
                                     Iterable<HttpConnector.Parameter> headers)
                              throws IOException
Description copied from interface: HttpConnector
Makes a HEAD request with the given http headers.

Specified by:
doHEAD in interface HttpConnector
Throws:
IOException

doGET

public HttpConnector.Response doGET(String url,
                                    Map<?,?> headers)
                             throws IOException
Description copied from interface: HttpConnector
Makes a GET request with the given http headers.

Specified by:
doGET in interface HttpConnector
Throws:
IOException

doGET

public HttpConnector.Response doGET(String url,
                                    Iterable<HttpConnector.Parameter> headers)
                             throws IOException
Description copied from interface: HttpConnector
Makes a GET request with the given http headers.

Specified by:
doGET in interface HttpConnector
Throws:
IOException

doGET

public HttpConnector.Response doGET(String url,
                                    Map<?,?> headers,
                                    Map<?,?> parameters)
                             throws IOException
Description copied from interface: HttpConnector
Makes a GET request with the given http headers, parameters.

Specified by:
doGET in interface HttpConnector
Throws:
IOException

doGET

public HttpConnector.Response doGET(String url,
                                    Iterable<HttpConnector.Parameter> headers,
                                    Map<?,?> parameters)
                             throws IOException
Description copied from interface: HttpConnector
Makes a GET request with the given http headers, parameters.

Specified by:
doGET in interface HttpConnector
Throws:
IOException

doGET

public HttpConnector.Response doGET(String url,
                                    Iterable<HttpConnector.Parameter> headers,
                                    Iterable<HttpConnector.Parameter> parameters)
                             throws IOException
Description copied from interface: HttpConnector
Makes a GET request with the given http headers, parameters.

Specified by:
doGET in interface HttpConnector
Throws:
IOException

doDELETE

public HttpConnector.Response doDELETE(String url,
                                       Map<?,?> headers)
                                throws IOException
Description copied from interface: HttpConnector
Makes a DELETE request with the given http headers.

Specified by:
doDELETE in interface HttpConnector
Throws:
IOException

doDELETE

public HttpConnector.Response doDELETE(String url,
                                       Iterable<HttpConnector.Parameter> headers)
                                throws IOException
Description copied from interface: HttpConnector
Makes a DELETE request with the given http headers.

Specified by:
doDELETE in interface HttpConnector
Throws:
IOException

doDELETE

public HttpConnector.Response doDELETE(String url,
                                       Map<?,?> headers,
                                       Map<?,?> parameters)
                                throws IOException
Description copied from interface: HttpConnector
Makes a DELETE request with the given http headers, parameters.

Specified by:
doDELETE in interface HttpConnector
Throws:
IOException

doDELETE

public HttpConnector.Response doDELETE(String url,
                                       Iterable<HttpConnector.Parameter> headers,
                                       Map<?,?> parameters)
                                throws IOException
Description copied from interface: HttpConnector
Makes a DELETE request with the given http headers, parameters.

Specified by:
doDELETE in interface HttpConnector
Throws:
IOException

doDELETE

public HttpConnector.Response doDELETE(String url,
                                       Iterable<HttpConnector.Parameter> headers,
                                       Iterable<HttpConnector.Parameter> parameters)
                                throws IOException
Description copied from interface: HttpConnector
Makes a DELETE request with the given http headers, parameters.

Specified by:
doDELETE in interface HttpConnector
Throws:
IOException

doPOST

public HttpConnector.Response doPOST(String url,
                                     Map<?,?> headers,
                                     Map<?,?> parameters,
                                     String charset)
                              throws IOException
Description copied from interface: HttpConnector
Makes a POST request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.

Specified by:
doPOST in interface HttpConnector
Throws:
IOException

doPOST

public HttpConnector.Response doPOST(String url,
                                     Map<?,?> headers,
                                     Iterable<HttpConnector.Parameter> parameters,
                                     String charset)
                              throws IOException
Description copied from interface: HttpConnector
Makes a POST request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.

Specified by:
doPOST in interface HttpConnector
Throws:
IOException

doPOST

public HttpConnector.Response doPOST(String url,
                                     Iterable<HttpConnector.Parameter> headers,
                                     Map<?,?> parameters,
                                     String charset)
                              throws IOException
Description copied from interface: HttpConnector
Makes a POST request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.

Specified by:
doPOST in interface HttpConnector
Throws:
IOException

doPOST

public HttpConnector.Response doPOST(String url,
                                     Iterable<HttpConnector.Parameter> headers,
                                     Iterable<HttpConnector.Parameter> parameters,
                                     String charset)
                              throws IOException
Description copied from interface: HttpConnector
Makes a POST request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.

Specified by:
doPOST in interface HttpConnector
Throws:
IOException

doPOST

public HttpConnector.Response doPOST(String url,
                                     Map<?,?> headers,
                                     String contentType,
                                     byte[] data)
                              throws IOException
Description copied from interface: HttpConnector
Makes a POST request with the given http headers, parameters and the content data.

Specified by:
doPOST in interface HttpConnector
Throws:
IOException

doPOST

public HttpConnector.Response doPOST(String url,
                                     Iterable<HttpConnector.Parameter> headers,
                                     String contentType,
                                     byte[] data)
                              throws IOException
Description copied from interface: HttpConnector
Makes a POST request with the given http headers, parameters, contentType and the content data.

Specified by:
doPOST in interface HttpConnector
Throws:
IOException

doPOST

public HttpConnector.Response doPOST(String url,
                                     Map<?,?> headers,
                                     String contentType,
                                     InputStreamReader reader)
                              throws IOException
Description copied from interface: HttpConnector
Makes a POST request with the given http headers, parameters, contentType and the content reader as InputStreamReader.

Specified by:
doPOST in interface HttpConnector
Throws:
IOException

doPOST

public HttpConnector.Response doPOST(String url,
                                     Iterable<HttpConnector.Parameter> headers,
                                     String contentType,
                                     InputStreamReader reader)
                              throws IOException
Description copied from interface: HttpConnector
Makes a POST request with the given http headers, parameters, contentType and the content reader as InputStreamReader.

Specified by:
doPOST in interface HttpConnector
Throws:
IOException

doPUT

public HttpConnector.Response doPUT(String url,
                                    Map<?,?> headers,
                                    Map<?,?> parameters,
                                    String charset)
                             throws IOException
Description copied from interface: HttpConnector
Makes a PUT request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.

Specified by:
doPUT in interface HttpConnector
Throws:
IOException

doPUT

public HttpConnector.Response doPUT(String url,
                                    Map<?,?> headers,
                                    Iterable<HttpConnector.Parameter> parameters,
                                    String charset)
                             throws IOException
Description copied from interface: HttpConnector
Makes a PUT request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.

Specified by:
doPUT in interface HttpConnector
Throws:
IOException

doPUT

public HttpConnector.Response doPUT(String url,
                                    Iterable<HttpConnector.Parameter> headers,
                                    Map<?,?> parameters,
                                    String charset)
                             throws IOException
Description copied from interface: HttpConnector
Makes a PUT request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.

Specified by:
doPUT in interface HttpConnector
Throws:
IOException

doPUT

public HttpConnector.Response doPUT(String url,
                                    Iterable<HttpConnector.Parameter> headers,
                                    Iterable<HttpConnector.Parameter> parameters,
                                    String charset)
                             throws IOException
Description copied from interface: HttpConnector
Makes a PUT request with the given http headers, parameters and the charset - which will be appended in the Content-Type header.

Specified by:
doPUT in interface HttpConnector
Throws:
IOException

doPUT

public HttpConnector.Response doPUT(String url,
                                    Map<?,?> headers,
                                    String contentType,
                                    byte[] data)
                             throws IOException
Description copied from interface: HttpConnector
Makes a PUT request with the given http headers, parameters and the content data.

Specified by:
doPUT in interface HttpConnector
Throws:
IOException

doPUT

public HttpConnector.Response doPUT(String url,
                                    Iterable<HttpConnector.Parameter> headers,
                                    String contentType,
                                    byte[] data)
                             throws IOException
Description copied from interface: HttpConnector
Makes a PUT request with the given http headers, parameters and the content data.

Specified by:
doPUT in interface HttpConnector
Throws:
IOException

doPUT

public HttpConnector.Response doPUT(String url,
                                    Map<?,?> headers,
                                    String contentType,
                                    InputStreamReader reader)
                             throws IOException
Description copied from interface: HttpConnector
Makes a PUT request with the given http headers, parameters, contentType and the content reader as InputStreamReader.

Specified by:
doPUT in interface HttpConnector
Throws:
IOException

doPUT

public HttpConnector.Response doPUT(String url,
                                    Iterable<HttpConnector.Parameter> headers,
                                    String contentType,
                                    InputStreamReader reader)
                             throws IOException
Description copied from interface: HttpConnector
Makes a PUT request with the given http headers, parameters, contentType and the content reader as InputStreamReader.

Specified by:
doPUT in interface HttpConnector
Throws:
IOException


Copyright © 2008-2013. All Rights Reserved.