org.apache.shindig.gadgets.uri
Class UriUtils

java.lang.Object
  extended by org.apache.shindig.gadgets.uri.UriUtils

public final class UriUtils
extends Object

Utility functions related to URI and Http servlet response management.

Since:
2.0.0

Nested Class Summary
static class UriUtils.DisallowedHeaders
          Enum of disallowed response headers that should not be passed on as is to the user.
 
Field Summary
static String CHARSET
           
 
Method Summary
static void copyRequestData(HttpRequest origRequest, HttpRequest req)
          Copies the post data from HttpServletRequest object to HttpRequest object.
static void copyRequestHeaders(HttpRequest origRequest, HttpRequest req, UriUtils.DisallowedHeaders... disallowedRequestHeaders)
          Copies headers from HttpServletRequest object to HttpRequest object.
static void copyResponseHeadersAndStatusCode(HttpResponse data, HttpResponseBuilder resp, boolean remapInternalServerError, boolean setHeaders, UriUtils.DisallowedHeaders... disallowedResponseHeaders)
          Copies the http response headers and status code to the final servlet response.
static String getContentTypeWithoutCharset(String content)
          Parses the value of content-type header and returns the content type header without the 'charset' attribute.
static boolean isValidHeaderName(String name)
          Returns true if the header name is valid.
static boolean isValidHeaderValue(String val)
          Returns true if the header value is valid.
static void maybeRewriteContentType(HttpRequest req, HttpResponseBuilder response)
          Rewrite the content type of the final http response if the request has the rewrite-mime-type param.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARSET

public static final String CHARSET
See Also:
Constant Field Values
Method Detail

isValidHeaderName

public static boolean isValidHeaderName(String name)
Returns true if the header name is valid. NOTE: RFC 822 section 3.1.2 describes the structure of header fields. According to the RFC, a header name (or field-name) must be composed of printable ASCII characters (i.e., characters that have values between 33. and 126. decimal, except colon).

Parameters:
name - The header name.
Returns:
True if the header name is valid, false otherwise.

isValidHeaderValue

public static boolean isValidHeaderValue(String val)
Returns true if the header value is valid. NOTE: RFC 822 section 3.1.2 describes the structure of header fields. According to the RFC, a header value (or field-body) may be composed of any ASCII characters, except CR or LF.

Parameters:
val - The header value.
Returns:
True if the header value is valid, false otherwise.

copyResponseHeadersAndStatusCode

public static void copyResponseHeadersAndStatusCode(HttpResponse data,
                                                    HttpResponseBuilder resp,
                                                    boolean remapInternalServerError,
                                                    boolean setHeaders,
                                                    UriUtils.DisallowedHeaders... disallowedResponseHeaders)
                                             throws IOException
Copies the http response headers and status code to the final servlet response.

Parameters:
data - The http response when fetching the requested accel uri.
resp - The servlet response to return back to client.
remapInternalServerError - If true, then SC_INTERNAL_SERVER_ERROR is remapped to SC_BAD_GATEWAY.
setHeaders - If true, then setHeader method of HttpServletResponse is called, otherwise addHeader is called for every header.
disallowedResponseHeaders - Disallowed response headers to omit from the response returned to the user.
Throws:
IOException - In case the http response was not successful.

copyRequestHeaders

public static void copyRequestHeaders(HttpRequest origRequest,
                                      HttpRequest req,
                                      UriUtils.DisallowedHeaders... disallowedRequestHeaders)
Copies headers from HttpServletRequest object to HttpRequest object.

Parameters:
origRequest - Servlet request to copy headers from.
req - The HttpRequest object to copy headers to.
disallowedRequestHeaders - Disallowed request headers to omit from the servlet request

copyRequestData

public static void copyRequestData(HttpRequest origRequest,
                                   HttpRequest req)
                            throws GadgetException
Copies the post data from HttpServletRequest object to HttpRequest object.

Parameters:
origRequest - Request to copy post data from.
req - The HttpRequest object to copy post data to.
Throws:
GadgetException - In case of errors.

maybeRewriteContentType

public static void maybeRewriteContentType(HttpRequest req,
                                           HttpResponseBuilder response)
Rewrite the content type of the final http response if the request has the rewrite-mime-type param.

Parameters:
req - The http request.
response - The final http response to be returned to user.

getContentTypeWithoutCharset

public static String getContentTypeWithoutCharset(String content)
Parses the value of content-type header and returns the content type header without the 'charset' attribute.

Parameters:
content - The content type header value.
Returns:
Content type header value without charset.


Copyright © 2007-2012. All Rights Reserved.