Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.google.sitebricks;
 

Author(s):
Dhanji R. Prasanna (dhanji@gmail.com)
class SitebricksFilter implements Filter {
  private final RoutingDispatcher dispatcher;
  private final Provider<Bootstrapperbootstrapper;
  private final Provider<Shutdownerteardowner;
  private final Provider<RequestrequestProvider;
  public SitebricksFilter(RoutingDispatcher dispatcherProvider<Bootstrapperbootstrapper,
                          Provider<ShutdownerteardownerProvider<RequestrequestProvider,
                          ReplyBasedHeadlessRenderer headlessRenderer) {
    this. = dispatcher;
    this. = bootstrapper;
    this. = teardowner;
    this. = requestProvider;
    this. = headlessRenderer;
  }
  public void init(FilterConfig filterConfigthrows ServletException {
    .get().start();
  }
  public void doFilter(ServletRequest servletRequestServletResponse servletResponse,
                       FilterChain filterChain)
      throws IOExceptionServletException {
    HttpServletRequest request = (HttpServletRequestservletRequest;
    HttpServletResponse response = (HttpServletResponseservletResponse;
    //dispatch
    Object respondObject = .dispatch(this..get(), .);
    //was there any matching page? (if it was a headless response, we don't need to do anything).
    // Also we do not do anything if the page elected to do nothing.
    if (null != respondObject && null == request.getAttribute(.)) {
      // Only use the string rendering pipeline if this is not a headless request.
      if (respondObject instanceof Respond) {
        Respond respond = (RespondrespondObject;
      
        //do we need to redirect or was this a successful render?
        final String redirect = respond.getRedirect();
        if (null != redirect) {
          response.sendRedirect(redirect);
        } else { //successful render
          // by checking if a content type was set, we allow users to override content-type
          //  on an arbitrary basis
          if (null == response.getContentType()) {
            response.setContentType(respond.getContentType());
          }
          response.getWriter().write(respond.toString());
        }
      } else { // It must be a headless Reply. Render the headless response.
        .render(responserespondObject);
      }
    } else {
      //continue down filter-chain
      filterChain.doFilter(requestresponse);
    }
  }
  public void destroy() {
  }
New to GrepCode? Check out our FAQ X