2.17.2: 2011-06-17

net.sf.basedb.util
Class HttpUtil

java.lang.Object
  extended by net.sf.basedb.util.HttpUtil

public class HttpUtil
extends Object

Useful methods related to HTTP stuff in general and Apache HTTP components in particular.

Since:
2.16
Author:
Nicklas
Last modified
$Date$

Field Summary
private static SimpleDateFormat HTTP_DATE_FORMAT
           
 
Constructor Summary
HttpUtil()
           
 
Method Summary
static long getContentLength(org.apache.http.HttpResponse response)
          Get the content length from the headers in the response.
static String getContentType(org.apache.http.HttpResponse response)
          Get the content type of the content from the headers in the response.
static Date getDate(org.apache.http.HttpResponse response, String header, Date defaultValue)
           
static Date getLastModified(org.apache.http.HttpResponse response)
          Get the date the content was last modified from the headers in the response.
static Long getLong(org.apache.http.HttpResponse response, String header, Long defaultValue)
           
static String getString(org.apache.http.HttpResponse response, String header, String defaultValue)
           
static void shutdown(org.apache.http.client.HttpClient client)
          Safely shuts down a http client and it's connection manager without trowing an exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_DATE_FORMAT

private static final SimpleDateFormat HTTP_DATE_FORMAT
Constructor Detail

HttpUtil

public HttpUtil()
Method Detail

getContentLength

public static long getContentLength(org.apache.http.HttpResponse response)
Get the content length from the headers in the response.

Parameters:
response - The response from a HTTP request
Returns:
The value of the "Content-Length" header or -1 if not present if it is unparsable

getLastModified

public static Date getLastModified(org.apache.http.HttpResponse response)
Get the date the content was last modified from the headers in the response.

Parameters:
response - The response from a HTTP request
Returns:
The value of the "Last-Modified" header or null if not present if it is unparsable

getContentType

public static String getContentType(org.apache.http.HttpResponse response)
Get the content type of the content from the headers in the response.

Parameters:
response - The response from a HTTP request
Returns:
The value of the "Content-Type" header or null if not present if it is unparsable

getString

public static String getString(org.apache.http.HttpResponse response,
                               String header,
                               String defaultValue)

getLong

public static Long getLong(org.apache.http.HttpResponse response,
                           String header,
                           Long defaultValue)

getDate

public static Date getDate(org.apache.http.HttpResponse response,
                           String header,
                           Date defaultValue)

shutdown

public static void shutdown(org.apache.http.client.HttpClient client)
Safely shuts down a http client and it's connection manager without trowing an exception. Useful to use in try-catch-finally clauses.


2.17.2: 2011-06-17