org.openrdf.util.http
Class HttpServerUtil

java.lang.Object
  extended byorg.openrdf.util.http.HttpServerUtil

public class HttpServerUtil
extends Object

Utility methods for HTTP servers/servlets.


Constructor Summary
HttpServerUtil()
           
 
Method Summary
static boolean acceptsGZIPEncoding(HttpServletRequest request)
          Checks whether the sender of the supplied request can handle gzip-encoded data.
static byte[] getBinaryParameter(Map fileItemMap, String paramName)
          Gets the binary value of a request parameter from a Map of FileItem objects, as returned by parseMultipartFormRequest().
static String getParameter(HttpServletRequest request, String paramName)
          Gets the trimmed value of a request parameter as a String.
static String getParameter(HttpServletRequest request, String paramName, String defaultValue)
          Gets the trimmed value of a request parameter as a String.
static String getParameter(Map fileItemMap, String paramName)
          Gets the trimmed value of a request parameter from a Map of FileItem objects, as returned by parseMultipartFormRequest().
static String getParameter(Map fileItemMap, String paramName, String defaultValue)
          Gets the trimmed value of a request parameter from a Map of FileItem objects, as returned by parseMultipartFormRequest().
static InputStream getStreamParameter(Map fileItemMap, String paramName)
          Gets the value of a request parameter as an InputStream from a Map of FileItem objects, as returned by parseMultipartFormRequest().
static boolean isMultipartFormRequest(HttpServletRequest request)
          Checks whether the supplied request is a multipart/form-data POST request.
static OutputStream openGZIPOutputStream(HttpServletResponse response)
          Opens an gzip-encoded output stream for the specified response.
static Map parseMultipartFormRequest(HttpServletRequest request)
          Parses a multipart/form-data POST request and returns its parameters as set of FileItems, mapped using their field name.
static void setNoCacheHeaders(HttpServletResponse response)
          Sets headers on the supplied response that prevent all kinds of browsers to cache it.
static void setTmpDir(File tmpDir)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpServerUtil

public HttpServerUtil()
Method Detail

setTmpDir

public static void setTmpDir(File tmpDir)

isMultipartFormRequest

public static boolean isMultipartFormRequest(HttpServletRequest request)
Checks whether the supplied request is a multipart/form-data POST request.


getParameter

public static String getParameter(HttpServletRequest request,
                                  String paramName)
Gets the trimmed value of a request parameter as a String. If the specified parameter does not exist or if it has a white-space-only value, null will be returned.

Parameters:
request - The request object to get the parameter from.
paramName - The name of the parameter.
Returns:
The trimmed value, or null if the specified parameter does not have a value.

getParameter

public static String getParameter(HttpServletRequest request,
                                  String paramName,
                                  String defaultValue)
Gets the trimmed value of a request parameter as a String. If the specified parameter does not exist or if it has a white-space-only value, the supplied defaultValue will be returned.

Parameters:
request - The request object to get the parameter from.
paramName - The name of the parameter.
defaultValue - The value that should be returned when the specified parameter did not have a value.
Returns:
The trimmed value, or defaultValue if the specified parameter does not have a value.

parseMultipartFormRequest

public static Map parseMultipartFormRequest(HttpServletRequest request)
                                     throws IOException
Parses a multipart/form-data POST request and returns its parameters as set of FileItems, mapped using their field name.

Parameters:
request - The request.
Returns:
a Map of FileItem objects, mapped using their field name (Strings).
Throws:
IOException - If the request could not be read/parsed.

getParameter

public static String getParameter(Map fileItemMap,
                                  String paramName)
Gets the trimmed value of a request parameter from a Map of FileItem objects, as returned by parseMultipartFormRequest(). If the specified parameter does not exist or if it has a white-space-only value, null will be returned. The values are assumed to be using the UTF-8 encoding.

Parameters:
fileItemMap - A Map of FileItem objects, mapped using their field name (Strings).
paramName - The name of the parameter.
Returns:
The trimmed value, or null if the specified parameter does not have a value.

getParameter

public static String getParameter(Map fileItemMap,
                                  String paramName,
                                  String defaultValue)
Gets the trimmed value of a request parameter from a Map of FileItem objects, as returned by parseMultipartFormRequest(). If the specified parameter does not exist or if it has a white-space-only value, the supplied defaultValue will be returned. The values are assumed to be using the UTF-8 encoding.

Parameters:
fileItemMap - A Map of FileItem objects, mapped using their field name (Strings).
paramName - The name of the parameter.
defaultValue - The value that should be returned when the specified parameter did not have a value.
Returns:
The trimmed value, or null if the specified parameter does not have a value.

getBinaryParameter

public static byte[] getBinaryParameter(Map fileItemMap,
                                        String paramName)
Gets the binary value of a request parameter from a Map of FileItem objects, as returned by parseMultipartFormRequest().

Parameters:
fileItemMap - A Map of FileItem objects, mapped using their field name (Strings).
paramName - The name of the parameter.
Returns:
The binary value, or null if the specified parameter does not have a value.

getStreamParameter

public static InputStream getStreamParameter(Map fileItemMap,
                                             String paramName)
                                      throws IOException
Gets the value of a request parameter as an InputStream from a Map of FileItem objects, as returned by parseMultipartFormRequest().

Parameters:
fileItemMap - A Map of FileItem objects, mapped using their field name (Strings).
paramName - The name of the parameter.
Returns:
The value, or null if the specified parameter does not have a value.
Throws:
IOException

setNoCacheHeaders

public static void setNoCacheHeaders(HttpServletResponse response)
Sets headers on the supplied response that prevent all kinds of browsers to cache it.


acceptsGZIPEncoding

public static boolean acceptsGZIPEncoding(HttpServletRequest request)
Checks whether the sender of the supplied request can handle gzip-encoded data.

Parameters:
request - A HTTP request
Returns:
true if the sender of the request can handle gzip-encoded data, false otherwise.

openGZIPOutputStream

public static OutputStream openGZIPOutputStream(HttpServletResponse response)
                                         throws IOException
Opens an gzip-encoded output stream for the specified response. This method also sets the required header(s) to indicate that the response is gzip-encoded.

Throws:
IOException


Copyright © 2002-2006 Aduna BV, GNU LGPL License applies.