Class HttpUtil

java.lang.Object
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

    Fields
    Modifier and Type Field Description
    private static org.apache.commons.lang3.time.FastDateFormat HTTP_DATE_FORMAT  
    private static nl.basjes.parse.useragent.UserAgentAnalyzer userAgentAnalyzer  
  • Constructor Summary

    Constructors
    Constructor Description
    HttpUtil()  
  • Method Summary

    Modifier and Type Method Description
    static nl.basjes.parse.useragent.UserAgent analyzeUserAgent​(String userAgent)
    Parse the User-Agent string from a HTTP request and return information about what it actually means.
    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 String getSummaryOfUserAgent​(String userAgent)
    Get a summary of the user agent: Browser with major version Operating system with version Typy of device (eg. desktop, phone, etc.)
    static void shutdown​(org.apache.http.impl.client.CloseableHttpClient 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 Details

    • HTTP_DATE_FORMAT

      private static final org.apache.commons.lang3.time.FastDateFormat HTTP_DATE_FORMAT
    • userAgentAnalyzer

      private static nl.basjes.parse.useragent.UserAgentAnalyzer userAgentAnalyzer
  • Constructor Details

    • HttpUtil

      public HttpUtil()
  • Method Details

    • 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.impl.client.CloseableHttpClient client)
      Safely shuts down a http client and it's connection manager without trowing an exception. Useful to use in try-catch-finally clauses.
    • analyzeUserAgent

      public static nl.basjes.parse.useragent.UserAgent analyzeUserAgent​(String userAgent)
      Parse the User-Agent string from a HTTP request and return information about what it actually means.
      Since:
      3.12
      See Also:
      https://github.com/nielsbasjes/yauaa
    • getSummaryOfUserAgent

      public static String getSummaryOfUserAgent​(String userAgent)
      Get a summary of the user agent: Browser with major version Operating system with version Typy of device (eg. desktop, phone, etc.)
      Since:
      3.12