Examples of GenericResponseWrapper


Examples of grails.plugin.cache.web.GenericResponseWrapper

  }

  protected PageInfo buildPage(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
    // Invoke the next entity in the chain
    SerializableByteArrayOutputStream out = new SerializableByteArrayOutputStream();
    GenericResponseWrapper wrapper = new GenericResponseWrapper(response, out);
    Map<String, Serializable> cacheableRequestAttributes = new HashMap<String, Serializable>();

    // TODO: split the special include handling out into a separate method
    HttpServletResponse originalResponse = null;
    boolean isInclude = WebUtils.isIncludeRequest(request);
    if (isInclude) {
      originalResponse = WrappedResponseHolder.getWrappedResponse();
      WrappedResponseHolder.setWrappedResponse(wrapper);
    }
    try {
      List<String> attributesBefore = toList(request.getAttributeNames());
      chain.doFilter(request, wrapper);
      List<String> attributesAfter = toList(request.getAttributeNames());
      attributesAfter.removeAll(attributesBefore);
      for (String attrName : attributesAfter) {
        Object value = request.getAttribute(attrName);
        if (value instanceof Serializable) {
          cacheableRequestAttributes.put(attrName, (Serializable)value);
        }
      }
    }
    finally {
      if (isInclude) {
        WrappedResponseHolder.setWrappedResponse(originalResponse);
      }
    }
    wrapper.flush();

    long timeToLiveSeconds = Integer.MAX_VALUE; // TODO cacheManager.getEhcache(context.cacheName).cacheConfiguration.timeToLiveSeconds;

    String contentType = wrapper.getContentType();
    if (!StringUtils.hasLength(contentType)) {
      contentType = response.getContentType();
    }

    return new PageInfo(wrapper.getStatus(), contentType, out.toByteArray(),
      false, timeToLiveSeconds, wrapper.getAllHeaders(), wrapper.getCookies(), cacheableRequestAttributes);
  }
View Full Code Here

Examples of grails.plugin.cache.web.GenericResponseWrapper

  }

  protected PageInfo buildPage(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
    // Invoke the next entity in the chain
    SerializableByteArrayOutputStream out = new SerializableByteArrayOutputStream();
    GenericResponseWrapper wrapper = new GenericResponseWrapper(response, out);
    Map<String, Serializable> cacheableRequestAttributes = new HashMap<String, Serializable>();

    // TODO: split the special include handling out into a separate method
    HttpServletResponse originalResponse = null;
    boolean isInclude = WebUtils.isIncludeRequest(request);
    if (isInclude) {
      originalResponse = WrappedResponseHolder.getWrappedResponse();
      WrappedResponseHolder.setWrappedResponse(wrapper);
    }
    try {
      List<String> attributesBefore = toList(request.getAttributeNames());
      chain.doFilter(request, wrapper);
      List<String> attributesAfter = toList(request.getAttributeNames());
      attributesAfter.removeAll(attributesBefore);
      for (String attrName : attributesAfter) {
        Object value = request.getAttribute(attrName);
        if (value instanceof Serializable) {
          cacheableRequestAttributes.put(attrName, (Serializable)value);
        }
      }
    }
    finally {
      if (isInclude) {
        WrappedResponseHolder.setWrappedResponse(originalResponse);
      }
    }
    wrapper.flush();

    long timeToLiveSeconds = Integer.MAX_VALUE; // TODO cacheManager.getEhcache(context.cacheName).cacheConfiguration.timeToLiveSeconds;

    String contentType = wrapper.getContentType();
    if (!StringUtils.hasLength(contentType)) {
      contentType = response.getContentType();
    }

    return new PageInfo(wrapper.getStatus(), contentType, out.toByteArray(),
      false, timeToLiveSeconds, wrapper.getAllHeaders(), wrapper.getCookies(), cacheableRequestAttributes);
  }
View Full Code Here

Examples of net.sf.ehcache.constructs.web.GenericResponseWrapper

  protected PageInfo buildPage(HttpServletRequest request,
      HttpServletResponse response, FilterChain chain)
      throws AlreadyGzippedException, Exception {
    // Invoke the next entity in the chain
        final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
        final GenericResponseWrapper wrapper = new GenericResponseWrapper(response, outstr);
        chain.doFilter(request, wrapper);
        wrapper.flush();
        //
        WidgetConfig widgetConfig = (WidgetConfig) request
        .getAttribute(WidgetConfig.KEY);
        Long timeToLiveSeconds = parseTimeToLiveSeconds(widgetConfig.getCache());
        // Return the page info
        return new PageInfo(wrapper.getStatus(), wrapper.getContentType(),
                wrapper.getCookies(),
                outstr.toByteArray(), false, timeToLiveSeconds, wrapper.getAllHeaders());
  }
View Full Code Here

Examples of net.sf.ehcache.constructs.web.GenericResponseWrapper

        try {
          final ByteArrayOutputStream baos = new ByteArrayOutputStream();
          final HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
          final HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
          pageContext.getRequest().getRequestDispatcher(widgetConfig.getPath())
              .include(request, new GenericResponseWrapper(response, baos));
          //
          value = (baos.toString("UTF-8"));
        } catch (ServletException e) {
          e.printStackTrace();
        } catch (IOException e) {
View Full Code Here

Examples of net.sf.ehcache.constructs.web.GenericResponseWrapper

            // Create a gzip stream
            final ByteArrayOutputStream compressed = new ByteArrayOutputStream();
            final GZIPOutputStream gzout = new GZIPOutputStream(compressed);

            // Handle the request
            final GenericResponseWrapper wrapper = new GenericResponseWrapper(response, gzout);
            chain.doFilter(request, wrapper);
            wrapper.flush();

            gzout.close();

            //return on error or redirect code, because response is already committed
            int statusCode = wrapper.getStatus();
            if (statusCode != HttpServletResponse.SC_OK) {
                return;
            }

            //Saneness checks
            byte[] compressedBytes = compressed.toByteArray();
            boolean shouldGzippedBodyBeZero = ResponseUtil.shouldGzippedBodyBeZero(compressedBytes, request);
            boolean shouldBodyBeZero = ResponseUtil.shouldBodyBeZero(request, wrapper.getStatus());
            if (shouldGzippedBodyBeZero || shouldBodyBeZero) {
                compressedBytes = new byte[0];
            }

            // Write the zipped body
View Full Code Here

Examples of net.sf.ehcache.constructs.web.GenericResponseWrapper

    protected PageInfo buildPage(final HttpServletRequest request, final HttpServletResponse response,
                                 final FilterChain chain) throws AlreadyGzippedException, Exception {

        // Invoke the next entity in the chain
        final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
        final GenericResponseWrapper wrapper = new GenericResponseWrapper(response, outstr);
        chain.doFilter(request, wrapper);
        wrapper.flush();

        // Return the page info
        return new PageInfo(wrapper.getStatus(), wrapper.getContentType(), wrapper.getHeaders(), wrapper.getCookies(),
                outstr.toByteArray(), false);
    }
View Full Code Here

Examples of net.sf.ehcache.constructs.web.GenericResponseWrapper

    protected PageInfo buildPage(final HttpServletRequest request, final HttpServletResponse response,
                                 final FilterChain chain) throws AlreadyGzippedException, Exception {

        // Invoke the next entity in the chain
        final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
        final GenericResponseWrapper wrapper = new GenericResponseWrapper(response, outstr);
        chain.doFilter(request, wrapper);
        wrapper.flush();

        // Return the page info
        return new PageInfo(wrapper.getStatus(), wrapper.getContentType(), wrapper.getHeaders(), wrapper.getCookies(),
                outstr.toByteArray(), true);
    }
View Full Code Here

Examples of org.apache.cactus.sample.servlet.util.GenericResponseWrapper

        // Create a wrapper of the response so that we can later write to
        // the response (add the footer). If we did not do this, we would
        // get an error saying that the response has already been
        // committed.
        GenericResponseWrapper wrapper =
            new GenericResponseWrapper((HttpServletResponse) theResponse);

        theChain.doFilter(theRequest, wrapper);

        out.write(wrapper.getData());
        addFooter(out);
        out.close();
    }
View Full Code Here

Examples of org.apache.cactus.sample.servlet.util.GenericResponseWrapper

        // Create a wrapper of the response so that we can later write to
        // the response (add the footer). If we did not do this, we would
        // get an error saying that the response has already been
        // committed.
        GenericResponseWrapper wrapper =
            new GenericResponseWrapper((HttpServletResponse) theResponse);

        theChain.doFilter(theRequest, wrapper);

        out.write(wrapper.getData());
        addFooter(out);
        out.close();
    }
View Full Code Here

Examples of org.apache.cactus.sample.servlet.util.GenericResponseWrapper

        // Create a wrapper of the response so that we can later write to
        // the response (add the footer). If we did not do this, we would
        // get an error saying that the response has already been
        // committed.
        GenericResponseWrapper wrapper =
            new GenericResponseWrapper((HttpServletResponse) theResponse);

        theChain.doFilter(theRequest, wrapper);

        out.write(wrapper.getData());
        addFooter(out);
        out.close();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.