/** * Second Weblet entry point the service stream method is used internally for Weblets 1.1 by our asynchronous reporting interface <p/> It basically does the * same as service but must be servlet independend (aka it cannot rely on a base servlet or the external request of the weblet request object <p/> If you do * not trigger the reporting subengine then you can omit this interface it is not used internally * * @param pathInfo * @param mimetype * @return * @throws IOException * @throws WebletException */ public InputStream serviceStream(String pathInfo, String mimetype) throws IOException, WebletException { String resourcePath = _resourceRoot + pathInfo; // lets build up our filter chain which in our case is a binary filter for standard // processing and our text processing filter for text resources with included // weblet: functions CopyStrategy copyProvider = new CopyStrategyImpl(); URL url = WebletResourceloadingUtils.getInstance().getResourceUrl(resourcePath); if (url == null) return null; // our utils should handle the standard case URLConnection conn = url.openConnection(); long lastmodified = conn.getLastModified(); if (mimetype == null) mimetype = getWebletConfig().getMimeType(resourcePath); return copyProvider.wrapInputStream(getWebletConfig().getWebletName(), mimetype, conn.getInputStream()); // To change body of implemented methods use // File | Settings | File Templates. }
/** * 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); }
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); }
String mimeType = webConfig.getMimeType(pathInfo); if(mimeType != null) { response.setDefaultContentType(mimeType);