info.aduna.net.http
Class HttpClientUtil

java.lang.Object
  extended by info.aduna.net.http.HttpClientUtil

public class HttpClientUtil
extends Object


Constructor Summary
HttpClientUtil()
           
 
Method Summary
static String appendParameter(String url, String parameterName, String parameterValue)
          Append a properly encoded parameter to the query string of the specified URL.
static String encodeParameter(String parameterName, String parameterValue)
          Encode a parameter for use in a URL.
static String formUrlEncode(String s)
          Encodes a string according to RFC 1738 : Uniform Resource locators (URL).
static void formUrlEncode(String s, StringBuilder buf)
          Encodes a string according to RFC 1738 : Uniform Resource locators (URL).
static InputStream getInputStream(URLConnection conn)
          Gets the InputStream for reading the response from a server.
static boolean is2xx(int statusCode)
          Checks whether the specified status code is in the 2xx-range, indicating a successfull request.
static void setAcceptGZIPEncoding(URLConnection conn)
          Sets a request property on the supplied connection indicating that a server can respond with gzip-encoded data if it wants to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpClientUtil

public HttpClientUtil()
Method Detail

formUrlEncode

public static void formUrlEncode(String s,
                                 StringBuilder buf)
Encodes a string according to RFC 1738 : Uniform Resource locators (URL). According to this spec, any characters outside the range 0x20 - 0x7E must be escaped because they are not printable characters. Within the range a number of characters are deemed unsafe or are marked as reserved. In short: According to the spec only the alphanumerics and the special characters from $-_.+!*'(), can be left unencoded. To be safe, this method will encode all characters that are not alphanumerics.


formUrlEncode

public static String formUrlEncode(String s)
Encodes a string according to RFC 1738 : Uniform Resource locators (URL). According to this spec, any characters outside the range 0x20 - 0x7E must be escaped because they are not printable characters. Within the range a number of characters are deemed unsafe or are marked as reserved. In short: According to the spec only the alphanumerics and the special characters from $-_.+!*'(), can be left unencoded. To be safe, this method will encode all characters that are not alphanumerics.


appendParameter

public static final String appendParameter(String url,
                                           String parameterName,
                                           String parameterValue)
Append a properly encoded parameter to the query string of the specified URL.

Parameters:
url - the URL to append to
parameterName - the name of parameter to append
parameterValue - the value to append
Returns:
the URL with the specified parameter appended to it

encodeParameter

public static String encodeParameter(String parameterName,
                                     String parameterValue)
Encode a parameter for use in a URL.

Parameters:
parameterName - the name of the parameter
parameterValue - the value
Returns:
the encoded parameter

setAcceptGZIPEncoding

public static void setAcceptGZIPEncoding(URLConnection conn)
Sets a request property on the supplied connection indicating that a server can respond with gzip-encoded data if it wants to.


getInputStream

public static InputStream getInputStream(URLConnection conn)
                                  throws IOException
Gets the InputStream for reading the response from a server. This method handles any encoding-related decoding of the data, e.g. gzip.

Throws:
IOException

is2xx

public static boolean is2xx(int statusCode)
Checks whether the specified status code is in the 2xx-range, indicating a successfull request.

Returns:
true if the status code is in the 2xx range.


Copyright © 1997-2008 Aduna. All Rights Reserved.