Search in sources :

Example 1 with ResourceLoaders

use of org.eclipse.scout.rt.ui.html.res.loader.ResourceLoaders in project scout.rt by eclipse.

the class ResourceRequestHandler method handleGet.

@Override
public boolean handleGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String pathInfoEx = resolvePathInfoEx(req);
    // Create loader for the requested resource type
    IResourceLoader resourceLoader = null;
    for (ResourceLoaders f : m_resourceLoaders) {
        resourceLoader = f.create(req, pathInfoEx);
        if (resourceLoader != null) {
            break;
        }
    }
    if (resourceLoader == null) {
        return false;
    }
    HttpCacheObject resource = resolveResourceFromCache(req, pathInfoEx, resourceLoader);
    // check resource existence (also ignore resources without content, to prevent invalid "content-length" header and NPE in write() method)
    if (resource == null || resource.getResource() == null || resource.getResource().getContent() == null) {
        return false;
    }
    // cached in browser? -> returns 304 if the resource has not been modified
    if (m_httpCacheControl.checkAndSetCacheHeaders(req, resp, resource)) {
        return true;
    }
    BinaryResource binaryResource = resource.getResource();
    // set the resp headers only if no 304 (according to spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5)
    setHttpResponseHeaders(resp, binaryResource);
    // Apply response interceptors
    resource.applyHttpResponseInterceptors(req, resp);
    if (!"HEAD".equals(req.getMethod())) {
        resp.getOutputStream().write(binaryResource.getContent());
    }
    return true;
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) IResourceLoader(org.eclipse.scout.rt.ui.html.res.loader.IResourceLoader) ResourceLoaders(org.eclipse.scout.rt.ui.html.res.loader.ResourceLoaders) HttpCacheObject(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject)

Aggregations

BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)1 HttpCacheObject (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject)1 IResourceLoader (org.eclipse.scout.rt.ui.html.res.loader.IResourceLoader)1 ResourceLoaders (org.eclipse.scout.rt.ui.html.res.loader.ResourceLoaders)1