private void determineContentLength(WebletResponse response, URL url) { try { File f = new File(url.toURI()); response.setContentLength((long) f.length()); } catch (URISyntaxException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
String webletVersion = config.getWebletVersion(); if (!isVersionedWeblet(webletVersion)) { response.setLastModified(lastmodified); response.setContentVersion((webletVersion == null) ? "" : webletVersion, getPast()); } else { response.setLastModified(lastmodified); response.setContentVersion(webletVersion, timeout);
/** * loads a resource from a given url * * @param config * the current weblet config * @param request * the current weblet request * @param response * the current weblet response * @param url * the current url * @param copyProvider * the processing filter chain for the weblet serving */ public void loadFromUrl(WebletConfig config, WebletRequest request, WebletResponse response, URL url, CopyStrategy copyProvider) throws IOException { if (url != null) { URLConnection conn = url.openConnection(); long lastmodified = conn.getLastModified(); //length not really working because the content length can be different //due to the filter post processing we have to cache it in ram first //or use the latest trunks weblets caching before serving //which should go hand in hand with gzipping upfron //determineContentLength(response, url); loadResourceFromStream(config, request, response, copyProvider, conn.getInputStream(), lastmodified); } else { response.setStatus(WebletResponse.SC_NOT_FOUND); } }
if (response.getDefaultContentType() == null) { String mimeType = webConfig.getMimeType(pathInfo); if(mimeType != null) { response.setDefaultContentType(mimeType); response.setContentType(mimeType);
public void service( WebletRequest request, WebletResponse response) throws IOException, WebletException { Weblet weblet = getWeblet(request); String pathInfo = request.getPathInfo(); //enhanced security check if (pathInfo != null && SandboxGuard.isJailBreak(pathInfo)) { throw new WebletException("Security Exception, the " + pathInfo + " breaks out of the resource jail, no resource is served!"); } WebletConfig webConfig = weblet.getWebletConfig(); String mimeType = null; if(!StringUtils.isBlank(pathInfo)) { mimeType = webConfig.getMimeType(pathInfo); } if(mimeType == null) { mimeType = response.getDefaultContentType(); } response.setContentType(mimeType); Set allowedResources = webConfig.getAllowedResources(); if (allowedResources != null) { String filetype = StringUtils.getExtension(pathInfo); if (!allowedResources.contains(filetype.toLowerCase())) { throw new WebletException("Security Exception, the " + pathInfo + " resource cannot be served!"); /* not allowed no content delivered */ } } weblet.service(request, response); }
/** * loads the resource from a given input stream note, this api is under construction we have caching not enabled yet * * @param config * the weblet config to load the resource * @param request * the weblet request * @param response * the weblet response * @param copyProvider * the processing copy provider * @param in * the resource serving input stream * @throws IOException */ public void loadResourceFromStream(WebletConfig config, WebletRequest request, WebletResponse response, CopyStrategy copyProvider, InputStream in) throws IOException { OutputStream out = response.getOutputStream(); String finalMimetype = config.getMimeType(request.getPathInfo()); copyProvider.copy(request.getWebletName(), finalMimetype, in, out); }