org.apache.shindig.gadgets.servlet
Class AccelHandler

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

public class AccelHandler
extends Object

Handles requests for accel servlet. The objective is to accelerate web pages.

Since:
2.0.0

Field Summary
protected  ResponseRewriterRegistry contentRewriterRegistry
           
protected  boolean remapInternalServerError
           
protected  RequestPipeline requestPipeline
           
protected  AccelUriManager uriManager
           
 
Constructor Summary
AccelHandler(RequestPipeline requestPipeline, ResponseRewriterRegistry contentRewriterRegistry, AccelUriManager accelUriManager, Boolean remapInternalServerError)
           
 
Method Summary
protected  HttpRequest buildHttpRequest(HttpRequest request, ProxyUriManager.ProxyUri uriToProxyOrRewrite)
          Build an HttpRequest object encapsulating the request details as requested by the user.
protected  HttpResponse fetch(HttpRequest request)
           
 ProxyUriManager.ProxyUri getProxyUri(HttpRequest httpRequest)
          Returns the proxy uri encapsulating the request uri.
protected  HttpResponse handleErrors(HttpResponse results)
          Process errors when fetching uri using request pipeline and return the error response to be returned to the user if any.
protected  boolean isRecoverable(HttpRequest req, HttpResponse results, RewritingException exception)
          Returns true in case the error encountered while rewriting the content is recoverable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestPipeline

protected final RequestPipeline requestPipeline

contentRewriterRegistry

protected final ResponseRewriterRegistry contentRewriterRegistry

uriManager

protected final AccelUriManager uriManager

remapInternalServerError

protected final boolean remapInternalServerError
Constructor Detail

AccelHandler

@Inject
public AccelHandler(RequestPipeline requestPipeline,
                           ResponseRewriterRegistry contentRewriterRegistry,
                           AccelUriManager accelUriManager,
                           Boolean remapInternalServerError)
Method Detail

fetch

protected HttpResponse fetch(HttpRequest request)
                      throws IOException,
                             GadgetException
Throws:
IOException
GadgetException

getProxyUri

public ProxyUriManager.ProxyUri getProxyUri(HttpRequest httpRequest)
                                     throws GadgetException
Returns the proxy uri encapsulating the request uri.

Parameters:
httpRequest - The http request.
Returns:
The proxy uri encapsulating the request uri.
Throws:
GadgetException - In case of errors.

isRecoverable

protected boolean isRecoverable(HttpRequest req,
                                HttpResponse results,
                                RewritingException exception)
Returns true in case the error encountered while rewriting the content is recoverable. The rationale behind it is that errors should be thrown only in case of serious grave errors (defined to be un recoverable). It should always be preferred to handle errors and return the original content at least. TODO: Think through all cases which are recoverable to enforce minimal possible set of constraints. TODO: Log the exception and context around it.

Parameters:
req - The http request for fetching the resource.
results - The result of rewriting.
exception - Exception caught.
Returns:
True if the error is recoverable, false otherwise.

buildHttpRequest

protected HttpRequest buildHttpRequest(HttpRequest request,
                                       ProxyUriManager.ProxyUri uriToProxyOrRewrite)
                                throws GadgetException
Build an HttpRequest object encapsulating the request details as requested by the user.

Parameters:
request - The http request.
uriToProxyOrRewrite - The parsed uri to proxy or rewrite through accel servlet.
Returns:
Remote content request based on the parameters sent from the client.
Throws:
GadgetException - In case the data could not be fetched.

handleErrors

protected HttpResponse handleErrors(HttpResponse results)
Process errors when fetching uri using request pipeline and return the error response to be returned to the user if any.

Parameters:
results - The http response returned by request pipeline.
Returns:
An HttpResponse instance encapsulating error message and status code to be returned to the user in case of errors, null otherwise.


Copyright © 2007-2012. All Rights Reserved.