Package com.volantis.shared.net.url.http

Examples of com.volantis.shared.net.url.http.CachedHttpContentState


        builder.setMethodAccessor(accessor);

        Time t = Time.inMilliSeconds(System.currentTimeMillis());
        builder.setRequestTime(t);
        builder.setResponseTime(t);
        final CachedHttpContentState state = builder.build();

        // A mock Representation that adds a "default" timeout to local and
        // non-http image sources.
        return new Representation() {
View Full Code Here


    public ProviderResult retrieve(final SystemClock clock,
                                   final Object key,
                                   final CacheEntry entry) {

        HttpContent httpContent;
        CachedHttpContentState state = null;
        HTTPResponseAccessor accessor;
        boolean cacheable = false;
        ProviderResult result = null;
        try {
            // check if validation headers can be added
            if (entry != null) {
                final CachedHttpContentState existingState =
                    (CachedHttpContentState) entry.getExtensionObject();
                if (existingState != null) {
                    // this is a validation
                    // set the If-Modified-Since header using the stored
                    // last modified value (if there is any)
                    final Time lastModified = existingState.getLastModified();
                    if (lastModified != null) {
                        final String lastModifiedAsString;
                        // SimpleDateFormat is not thread safe
                        synchronized (RFC1123) {
                            lastModifiedAsString = RFC1123.format(
                                new Date(lastModified.inMillis()));
                        }
                        final Header header =
                            new HeaderImpl(HeaderNames.IF_MODIFIED_SINCE_HEADER);
                        header.setValue(lastModifiedAsString);
                        executor.addRequestHeader(header);
                    }

                    // set the If-None-Match header with the eTag value, if
                    // there is any
                    final String eTag = existingState.getETag();
                    if (eTag != null && eTag.trim().length() > 0) {
                        final Header header =
                            new HeaderImpl(HeaderNames.IF_NONE_MATCH_HEADER);
                        header.setValue(eTag);
                        executor.addRequestHeader(header);
View Full Code Here

        try {
            // get the content
            final URLContent content =
                contentRetriever.retrieve(url, timeout, httpConfig);
            // store the cache entry state in the result
            final CachedHttpContentState state =
                contentRetriever.getCacheState();
            result =
                new ProviderResult(content, group, state.isCacheable(), state);
        } catch (IOException e) {
            result = new ProviderResult(e, group, false, null);
        }
        return result;
    }
View Full Code Here

        }

        // javadoc inherited
        protected void preExecute(final HttpMethod method) {
            if (entry != null) {
                final CachedHttpContentState existingState =
                    (CachedHttpContentState) entry.getExtensionObject();
                if (existingState != null) {
                    // this is a validation
                    // set the If-Modified-Since header using the stored
                    // last modified value (if there is any)
                    final Time lastModified = existingState.getLastModified();
                    if (lastModified != null) {
                        final String lastModifiedAsString;
                        // SimpleDateFormat is not thread safe so create a
                        // new instance
                        DateFormat RFC1123 = DateFormats.RFC_1123_GMT.create();

                        lastModifiedAsString = RFC1123.format(
                            new Date(lastModified.inMillis()));

                        method.setRequestHeader(HEADER_IF_MODIFIED_SINCE,
                            lastModifiedAsString);
                    }

                    // set the If-None-Match header with the eTag value, if
                    // there is any
                    final String eTag = existingState.getETag();
                    if (eTag != null && eTag.trim().length() > 0) {
                        method.setRequestHeader(HEADER_IF_NONE_MATCH, eTag);
                    }
                }
            }
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.url.http.CachedHttpContentState

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.