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;
}
Aggregations