Package ch.entwine.weblounge.common.request

Examples of ch.entwine.weblounge.common.request.ResponseCache


    // Get the servlet that is responsible for the site's content
    Servlet siteServlet = sites.getSiteServlet(site);

    // Get the response cache, if available
    ResponseCache cache = caches.get(site.getIdentifier());

    // Wrap for caching
    if (cache != null) {
      httpResponse = cache.createCacheableResponse(httpRequest, httpResponse);
    }

    // Wrap request and response
    WebloungeRequestImpl request = new WebloungeRequestImpl(httpRequest, siteServlet, environment);
    WebloungeResponseImpl response = new WebloungeResponseImpl(httpResponse);

    // Configure request and response objects
    request.init(site);
    response.setRequest(request);
    response.setResponseCache(cache);
    response.setCharacterEncoding(DEFAULT_RESPONSE_ENCODING);
    response.setHeader("X-Powered-By", POWERED_BY);
    response.setDateHeader("Date", Calendar.getInstance().getTimeInMillis());

    // Notify listeners about starting request
    fireRequestStarted(request, response, site);

    boolean requestServed = false;

    // Ask the registered request handler if they are willing to handle
    // the request.
    try {
      securityService.setSite(site);
      request.setUser(securityService.getUser());
      for (RequestHandler handler : requestHandler) {
        try {
          logger.trace("Asking {} to serve {}", handler, request);
          if (handler.service(request, response)) {
            requestServed = true;
            logger.debug("{} served request {}", handler, request);
            if (response.hasError()) {
              logger.debug("Request processing failed on {}", request);
              fireRequestFailed(request, response, site);
            } else {
              fireRequestDelivered(request, response, site);
            }
            return;
          }
        } catch (Throwable t) {
          response.invalidate();
          String params = RequestUtils.dumpParameters(request);
          if (t.getCause() != null) {
            t = t.getCause();
          }
          logger.error("Request handler '{}' failed to handle {} {}", new Object[] {
              handler,
              request,
              params });
          logger.error(t.getMessage(), t);
          DispatchUtils.sendInternalError(t.getMessage(), request, response);
          break;
        }
      }
    } finally {
      securityService.setSite(null);
      if (requestServed) {
        response.endResponse();
        response.flushBuffer();
        logger.debug("Finished processing of {}", httpRequest.getRequestURI());
      } else {
        logger.debug("No handler found for {}", request);
        DispatchUtils.sendNotFound(request, response);
        if (cache != null)
          cache.invalidate(response);
        fireRequestFailed(request, response, site);
      }
    }
  }
View Full Code Here


   */
  public boolean startResponse(CacheTag[] tags, long expirationTime,
      long revalidationTime) throws IllegalStateException {
    if (!isValid || cache == null)
      return false;
    ResponseCache cache = this.cache.get();
    if (cache == null)
      return false;
    if (cacheHandle != null)
      throw new IllegalStateException("The response is already being cached");

    // Is the response in the cache?
    CacheHandle hdl = cache.startResponse(tags, request.get(), this, expirationTime, revalidationTime);
    if (hdl == null)
      return true;

    // It's not, meaning we need to do the processing ourselves
    cacheHandle = new WeakReference<CacheHandle>(hdl);
View Full Code Here

        submitResponseBuffer();

      // See if there is an active cache transaction
      if (cache == null)
        return;
      ResponseCache cache = this.cache.get();
      if (cache == null)
        return;
      if (cacheHandle == null || cacheHandle.get() == null)
        return;

      // End the response and have the output sent back to the client
      cache.endResponse(this);

    } catch (IOException e) {
      // The client closed the connection
    } finally {
      cacheHandle = null;
View Full Code Here

   * @see ch.entwine.weblounge.common.request.WebloungeResponse#invalidate()
   */
  public void invalidate() {
    isValid = false;
    if (cache != null) {
      ResponseCache c = cache.get();
      if (c != null) {
        c.invalidate(this);
      }
    }
  }
View Full Code Here

    // Delete previews
    deletePreviews(resource);

    // Make sure related stuff gets thrown out of the cache
    ResponseCache cache = getCache();
    if (cache != null && (allRevisions || uri.getVersion() == Resource.LIVE)) {
      cache.invalidate(new CacheTag[] { new CacheTagImpl(CacheTag.Resource, uri.getIdentifier()) }, true);
    }

    return true;

  }
View Full Code Here

          createPreviews(r);
      }
    }

    // Make sure related stuff gets thrown out of the cache
    ResponseCache cache = getCache();
    if (cache != null) {
      cache.invalidate(new CacheTag[] { new CacheTagImpl(CacheTag.Resource, uri.getIdentifier()) }, true);
    }
  }
View Full Code Here

        throw new IllegalStateException("Cannot add content metadata without content");
      index.add(resource);
    }

    // Make sure related stuff gets thrown out of the cache
    ResponseCache cache = getCache();
    if (cache != null && uri.getVersion() == Resource.LIVE) {
      List<CacheTag> tags = new ArrayList<CacheTag>();

      // resource id
      tags.add(new CacheTagImpl(CacheTag.Resource, uri.getIdentifier()));

      // subjects, so that resource lists get updated
      for (String subject : resource.getSubjects())
        tags.add(new CacheTagImpl(CacheTag.Subject, subject));

      cache.invalidate(tags.toArray(new CacheTagImpl[tags.size()]), true);
    }

    // Write the updated resource to disk
    storeResource(resource);
View Full Code Here

    // Create the preview images
    if (connected && !initializing)
      createPreviews(resource);

    // Make sure related stuff gets thrown out of the cache
    ResponseCache cache = getCache();
    if (cache != null) {
      cache.invalidate(new CacheTag[] { new CacheTagImpl(CacheTag.Resource, uri.getIdentifier()) }, true);
    }

    return resource;
  }
View Full Code Here

    // Delete previews
    deletePreviews(resource, content.getLanguage());

    // Make sure related stuff gets thrown out of the cache
    ResponseCache cache = getCache();
    if (cache != null) {
      cache.invalidate(new CacheTag[] { new CacheTagImpl(CacheTag.Resource, uri.getIdentifier()) }, true);
    }

    return resource;
  }
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.request.ResponseCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.