org.apache.shindig.gadgets.servlet
Class ServletUtil

java.lang.Object
  extended by org.apache.shindig.gadgets.servlet.ServletUtil

public final class ServletUtil
extends Object

Jtility routines for dealing with servlets.

Since:
2.0.0

Field Summary
static String DATA_URI_KEY
           
static String REMOTE_ADDR_KEY
           
 
Method Summary
static HttpResponse convertToJsonResponse(HttpResponse response)
          Converts the given HttpResponse into JSON form, with at least one field, dataUri, containing a Data URI that can be inlined into an HTML page.
static void copyResponseToServlet(HttpResponse response, javax.servlet.http.HttpServletResponse servletResponse)
           
static HttpResponse errorResponse(GadgetException e)
           
static HttpRequest fromHttpServletRequest(javax.servlet.http.HttpServletRequest servletReq)
          Returns an HttpRequest object encapsulating the servlet request.
static void setCachingHeaders(HttpResponseBuilder response, int ttl, boolean noProxy)
           
static void setXForwardedForHeader(HttpRequest inboundRequest, HttpRequest req)
          Sets standard forwarding headers on the proxied request.
static void setXForwardedForHeader(javax.servlet.http.HttpServletRequest inboundRequest, HttpRequest req)
           
static Uri validateUrl(Uri urlToValidate)
          Validates and normalizes the given url, ensuring that it is non-null, has scheme http or https, and has a path value of some kind.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REMOTE_ADDR_KEY

public static final String REMOTE_ADDR_KEY
See Also:
Constant Field Values

DATA_URI_KEY

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

fromHttpServletRequest

public static HttpRequest fromHttpServletRequest(javax.servlet.http.HttpServletRequest servletReq)
                                          throws IOException
Returns an HttpRequest object encapsulating the servlet request. NOTE: Request parameters are not explicitly taken care of, instead we copy the InputStream and query parameters separately.

Parameters:
servletReq - The http servlet request.
Returns:
An HttpRequest object with all the information provided by the servlet request.
Throws:
IOException - In case of errors.

setCachingHeaders

public static void setCachingHeaders(HttpResponseBuilder response,
                                     int ttl,
                                     boolean noProxy)

copyResponseToServlet

public static void copyResponseToServlet(HttpResponse response,
                                         javax.servlet.http.HttpServletResponse servletResponse)
                                  throws IOException
Throws:
IOException

validateUrl

public static Uri validateUrl(Uri urlToValidate)
                       throws GadgetException
Validates and normalizes the given url, ensuring that it is non-null, has scheme http or https, and has a path value of some kind.

Returns:
A URI representing a validated form of the url.
Throws:
GadgetException - If the url is not valid.

setXForwardedForHeader

public static void setXForwardedForHeader(HttpRequest inboundRequest,
                                          HttpRequest req)
                                   throws GadgetException
Sets standard forwarding headers on the proxied request.

Parameters:
inboundRequest -
req -
Throws:
GadgetException

setXForwardedForHeader

public static void setXForwardedForHeader(javax.servlet.http.HttpServletRequest inboundRequest,
                                          HttpRequest req)
                                   throws GadgetException
Throws:
GadgetException

errorResponse

public static HttpResponse errorResponse(GadgetException e)
Returns:
An HttpResponse object wrapping the given GadgetException.

convertToJsonResponse

public static HttpResponse convertToJsonResponse(HttpResponse response)
                                          throws IOException
Converts the given HttpResponse into JSON form, with at least one field, dataUri, containing a Data URI that can be inlined into an HTML page. Any metadata on the given HttpResponse is also added as fields.

Parameters:
response - Input HttpResponse to convert to JSON.
Returns:
JSON-containing HttpResponse.
Throws:
IOException - If there are problems reading from response.


Copyright © 2007-2012. All Rights Reserved.