Package com.volantis.mcs.context

Examples of com.volantis.mcs.context.ResponseCachingDirectives


        assertEquals(calendar.getTimeInMillis(),
            response.getDateHeader("Expires"));
    }

    public void testApplyCachingDirectivesNoExpires() {
        final ResponseCachingDirectives cachingDirectives =
            envContext.getCachingDirectives();
        cachingDirectives.enable();
        envContext.applyCachingDirectives();
        assertEquals("no-cache", response.getHeader("Pragma"));
        assertEquals("no-cache", response.getHeader("Cache-Control"));
        final Calendar calendar =
            new GregorianCalendar(1990, Calendar.JANUARY, 1);
View Full Code Here


        assertEquals(calendar.getTimeInMillis(),
            response.getDateHeader("Expires"));
    }

    public void testApplyCachingDirectivesWithExpires() {
        final ResponseCachingDirectives cachingDirectives =
            envContext.getCachingDirectives();
        cachingDirectives.enable();
        final long expiresInMilliSeconds = System.currentTimeMillis() + 50000;
        cachingDirectives.setExpires(Time.inMilliSeconds(expiresInMilliSeconds),
            ResponseCachingDirectives.PRIORITY_NORMAL);
        envContext.applyCachingDirectives();

        final String maxAgeValue = response.getHeader("Cache-Control");
        assertTrue(maxAgeValue.startsWith("max-age="));
View Full Code Here

        }
        assertEquals(ServletEnvironmentContext.VARY_HEADER_NAMES, headerNames);
    }

    public void testApplyCachingDirectivesWithMaxAge() {
        final ResponseCachingDirectives cachingDirectives =
            envContext.getCachingDirectives();
        cachingDirectives.enable();
        cachingDirectives.setMaxAge(Period.inSeconds(50),
            ResponseCachingDirectives.PRIORITY_NORMAL);
        envContext.applyCachingDirectives();

        final String maxAgeValue = response.getHeader("Cache-Control");
        assertTrue(maxAgeValue.startsWith("max-age="));
View Full Code Here

        }
        assertEquals(ServletEnvironmentContext.VARY_HEADER_NAMES, headerNames);
    }

    public void testApplyCachingDirectivesDisabled() {
        final ResponseCachingDirectives cachingDirectives =
            envContext.getCachingDirectives();
        cachingDirectives.enable();
        cachingDirectives.setMaxAge(Period.inSeconds(50),
            ResponseCachingDirectives.PRIORITY_NORMAL);
        cachingDirectives.disable();

        envContext.applyCachingDirectives();
        assertEquals("no-cache", response.getHeader("Pragma"));
        assertEquals("no-cache", response.getHeader("Cache-Control"));
        final Calendar calendar =
View Full Code Here

    }

    //javadoc inherited
    public ResponseCachingDirectives getCachingDirectives() {
        if (cachingDirectives == null) {
            cachingDirectives = new ResponseCachingDirectives(
                SystemClock.getDefaultInstance());
        }
        return cachingDirectives;
    }
View Full Code Here

     * the caching directives.
     *
     * @see #getCachingDirectives()
     */
    private void addCachingHeaders() {
        final ResponseCachingDirectives cachingDirectives =
            getCachingDirectives();
        final HttpServletResponse response =
            (HttpServletResponse) requestContext.getResponse();
        if (cachingDirectives != null && cachingDirectives.isEnabled() &&
            cachingDirectives.getExpires() != null) {
            // if enabled, set Expires, Cache-Control/max-age and Vary response
            // headers
            final Time expires = cachingDirectives.getExpires();
            if (expires != Time.NEVER) {
                response.addDateHeader("Expires", expires.inMillis());
                // compute max-age value
                final Period timeToLive = cachingDirectives.getTimeToLive();
                long maxAgeInSeconds = 0;
                if (timeToLive != null) {
                    maxAgeInSeconds =
                        LongHelper.asInt(timeToLive.inMillis() / 1000);
                    if (maxAgeInSeconds < 0) {
                        maxAgeInSeconds = 0;
                    }
                }
                response.addHeader("Cache-Control", "max-age=" + maxAgeInSeconds);
            } else {
                // from the spec:
                // To mark a response as "never expires," an origin server sends
                // an Expires date approximately one year from the time the
                // response is sent. HTTP/1.1 servers SHOULD NOT send Expires
                // dates more than one year in the future.
                final SystemClock clock = cachingDirectives.getClock();
                final long oneYearInSeconds = 365 * 24 * 60 * 60;
                response.addDateHeader("Expires",
                    clock.getCurrentTime().inMillis() + oneYearInSeconds * 1000);
                response.addHeader("Cache-Control", "max-age=" + oneYearInSeconds);
            }
View Full Code Here

            final MarinerRequestContext marinerRequestContext) {
        // set the environment context
        final EnvironmentContextMock environmentContextMock =
            new EnvironmentContextMock("environmentContextMock", expectations);
        cachingDirectives =
            new ResponseCachingDirectives(SystemClock.getDefaultInstance());
        cachingDirectives.enable();
        assertTrue(cachingDirectives.isEnabled());
        environmentContextMock.expects.getCachingDirectives().returns(
            cachingDirectives).any();
        ContextInternals.setEnvironmentContext(marinerRequestContext,
View Full Code Here

            // we need to store the service definintion away in the
            // expression context
            configureServiceDefintion(marinerRequestContext,
                                      environmentContext);
            final ResponseCachingDirectives cachingDirectives =
                environmentContext.getCachingDirectives();
            if (cachingDirectives != null && disableResponseCaching) {
                cachingDirectives.disable();
            }
            processXDIME(marinerRequestContext, xdimeContent, characterSet);
        } catch (MarinerContextException e) {
            logger.error("mariner-context-exception", e);
            throw new ServletException(
View Full Code Here

        try {
            if (context.isFragmentationSupported()) {
                if (!instance.isEmpty()) {
                    final MarinerPageContext pageContext =
                        context.getDeviceLayoutContext().getMarinerPageContext();
                    final ResponseCachingDirectives cachingDirectives =
                        pageContext.getEnvironmentContext().getCachingDirectives();
                    // caching is not supported for fragmented pages
                    if (cachingDirectives != null) {
                        cachingDirectives.disable();
                    }

                    Fragment fragment = (Fragment)instance.getFormat();
                    Format child = fragment.getChildAt(0);
View Full Code Here

    // Javadoc inherited.
    public void updateMarkup(final String css) {
        WritableCSSEntity entity = new GeneratedWritableCSSEntity(css);

        // Generate TTL for CSS Cache Entry (in milliseconds)
        final ResponseCachingDirectives cachingDirectives =
            context.getEnvironmentContext().getCachingDirectives();
        long timeToLive = -1;
        if (cachingDirectives != null) {
            final Period ttl = cachingDirectives.getTimeToLive();
            if (ttl != null) {
                timeToLive = ttl.inMillis();
            }
        }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.context.ResponseCachingDirectives

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.