use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject in project scout.rt by eclipse.
the class HtmlDocumentParser method getScriptAndFingerprint.
/**
* Returns the external script name including a content-based fingerprint.
*/
protected Pair<HttpCacheObject, String> getScriptAndFingerprint(String internalPath) throws IOException {
ScriptFileLoader scriptLoader = createScriptFileLoader();
HttpCacheKey cacheKey = scriptLoader.createCacheKey(internalPath);
HttpCacheObject script = m_cache.get(cacheKey);
if (script == null) {
// cache miss: try to load script
script = scriptLoader.loadResource(cacheKey);
}
if (script == null) {
// script not found -> no fingerprint
LOG.warn("Failed to locate script referenced in html file '{}': {}", m_params.getHtmlPath(), internalPath);
return null;
}
String fingerprint = Long.toHexString(script.getResource().getFingerprint());
return new ImmutablePair<>(script, fingerprint);
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject in project scout.rt by eclipse.
the class HtmlFileLoader method loadResource.
@Override
public HttpCacheObject loadResource(HttpCacheKey cacheKey) throws IOException {
String pathInfo = cacheKey.getResourcePath();
BinaryResource content = loadResource(pathInfo);
if (content == null) {
return null;
}
// no cache-control, only E-Tag checks to make sure that a session with timeout is correctly
// forwarded to the login using a GET request BEFORE the first json POST request
HttpCacheObject httpCacheObject = new HttpCacheObject(cacheKey, content);
// Suppress automatic "compatibility mode" in IE in intranet zone
httpCacheObject.addHttpResponseInterceptor(new HttpResponseHeaderContributor("X-UA-Compatible", "IE=edge") {
private static final long serialVersionUID = 1L;
@Override
public void intercept(HttpServletRequest req, HttpServletResponse resp) {
HttpClientInfo httpClientInfo = HttpClientInfo.get(req);
if (httpClientInfo.isMshtml()) {
// Send headers only for IE
super.intercept(req, resp);
}
}
});
return httpCacheObject;
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject in project scout.rt by eclipse.
the class PrebuildFiles method buildResources.
/**
* Pre-builds the HTML files and the referenced scripts (JS, CSS) in the HTML document. Each document is put into the
* HTTP resource cache, so we don't have to build them again later. However, we have to make a few assumptions here.
* Since we have no HTTP request or session at this point, we assume:
* <ul>
* <li>the default locale</li>
* <li>the default theme</li>
* <li>minifying is enabled</li>
* <li>caching is enabled</li>
* </ul>
*/
protected void buildResources() {
long t0 = System.nanoTime();
List<String> files = CONFIG.getPropertyValue(UiPrebuildFilesProperty.class);
IHttpResourceCache httpResourceCache = BEANS.get(GlobalHttpResourceCache.class);
for (String file : files) {
LOG.info("Pre-building resource '{}'...", file);
try {
HttpCacheObject cacheObject = loadResource(file);
httpResourceCache.put(cacheObject);
} catch (IOException e) {
LOG.error("Failed to load resource", e);
}
}
LOG.info("Finished pre-building of {} web resources in {} ms", files.size(), StringUtility.formatNanos(System.nanoTime() - t0));
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject in project scout.rt by eclipse.
the class AbstractResourceLoader method loadResource.
@Override
public HttpCacheObject loadResource(HttpCacheKey cacheKey) throws IOException {
String pathInfo = cacheKey.getResourcePath();
BinaryResource content = loadResource(pathInfo);
if (content == null) {
return null;
}
return new HttpCacheObject(cacheKey, content);
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject in project scout.rt by eclipse.
the class HttpCacheControlTest method testCheckAndSet_EnableCaching_IfModifiedSince_NotModifiedAtFidelity.
@Test
public void testCheckAndSet_EnableCaching_IfModifiedSince_NotModifiedAtFidelity() throws Exception {
Mockito.when(req.getPathInfo()).thenReturn("/");
Mockito.when(req.getHeader(HttpCacheControl.ETAG)).thenReturn(null);
Mockito.when(req.getHeader(HttpCacheControl.IF_NONE_MATCH)).thenReturn(null);
Mockito.when(req.getDateHeader(HttpCacheControl.IF_MODIFIED_SINCE)).thenReturn(1000000L);
BinaryResource res = BinaryResources.create().withFilename("a.html").withContent("<html></html>".getBytes("UTF-8")).withCachingAllowed(true).withLastModified(1000000L + HttpCacheControl.IF_MODIFIED_SINCE_FIDELITY).build();
HttpCacheObject obj = new HttpCacheObject(new HttpCacheKey("/"), res);
boolean b = cc.checkAndSetCacheHeaders(req, resp, obj);
Assert.assertTrue(b);
Mockito.verify(req, ANY_TIMES).getPathInfo();
Mockito.verify(req, ANY_TIMES).getAttribute("javax.servlet.forward.path_info");
Mockito.verify(req, ANY_TIMES).getHeader(HttpCacheControl.ETAG);
Mockito.verify(req, ANY_TIMES).getHeader(HttpCacheControl.IF_NONE_MATCH);
Mockito.verify(req, ANY_TIMES).getDateHeader(HttpCacheControl.IF_MODIFIED_SINCE);
Mockito.verify(resp, ONCE).setHeader(HttpCacheControl.CACHE_CONTROL, "private, max-age=0, must-revalidate");
Mockito.verify(resp, ONCE).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
Aggregations