public void destroy() { _resourceRoot = null; _packageName = null; super.destroy(); } }
public Weblet getWeblet(String webletName) { Weblet weblet = (Weblet) _weblets.get(webletName); if (weblet == null) { try { WebletConfigImpl config = (WebletConfigImpl) _webletConfigs.get(webletName); ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class webletClass = loader.loadClass(config.getWebletClass()); weblet = (Weblet) webletClass.newInstance(); weblet.init(config); _weblets.put(webletName, weblet); } catch (ClassNotFoundException e) { throw new WebletException(e); } catch (InstantiationException e) { throw new WebletException(e); } catch (IllegalAccessException e) { throw new WebletException(e); } } return weblet; }
WebletConfig webConfig = weblet.getWebletConfig(); if (pathInfo != null) { String mimeType = webConfig.getMimeType(pathInfo); WebletConfig webConfig = weblet.getWebletConfig(); Set allowedResources = webConfig.getAllowedResources(); weblet.service(request, response);
public InputStream getResourceStream(WebletRequest request, String mimeType) throws WebletException { Weblet weblet = (Weblet) _weblets.get(request.getWebletName()); if (weblet == null) return null; try { return weblet.serviceStream(request.getPathInfo(), mimeType); } catch (IOException ex) { return null; } }
public Weblet getWeblet(String webletName) { Weblet weblet = (Weblet) _weblets.get(webletName); if (weblet == null) { try { WebletConfigImpl config = (WebletConfigImpl) _webletConfigs.get(webletName); ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class webletClass = loader.loadClass(config.getWebletClass()); weblet = (Weblet) webletClass.newInstance(); weblet.init(config); _weblets.put(webletName, weblet); } catch (ClassNotFoundException e) { throw new WebletException(e); } catch (InstantiationException e) { throw new WebletException(e); } catch (IllegalAccessException e) { throw new WebletException(e); } } return weblet; }
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); }
public InputStream getResourceStream(WebletRequest request, String mimeType) throws WebletException { Weblet weblet = (Weblet) _weblets.get(request.getWebletName()); if (weblet == null) return null; try { return weblet.serviceStream(request.getPathInfo(), mimeType); } catch (IOException ex) { return null; } }
public void init(WebletConfig config) { super.init(config); String httpAddress = config.getInitParameter("rootaddress"); if (httpAddress == null) { throw new WebletException("Missing either init parameter \"package\" or " + " or init parameter \"resourceRoot\" for " + " Weblet \"" + config.getWebletName() + "\""); } _resourceRoot = httpAddress; }
public void destroy() { _resourceRoot = null; super.destroy(); }
/** * new since 1.1 we now can get the weblet also * as local stream for furhter external processing * if we have our weblet request. * <p/> * We can add a dummy request * * @param request * @return an input stream on our current weblet resource * @throws WebletException * @throws IOException */ public InputStream serviceStream(WebletRequest request, String mimetype) throws WebletException, IOException { Weblet weblet = getWeblet(request); return weblet.serviceStream(request.getPathInfo(), mimetype); }
/** * init method which is called by default to process the parameters * * @param config * the webletconfig to be processed */ public void init(WebletConfig config) { super.init(config); _resourceRoot = config.getInitParameter("resourceRoot"); // init param missing, lets throw an error if (_resourceRoot == null) { throw new WebletException("Missing either init parameter \"package\" or " + " or init parameter \"resourceRoot\" for " + " Weblet \"" + config.getWebletName() + "\""); } }
public void destroy() { _resourceRoot = null; super.destroy(); }
/** * new since 1.1 we now can get the weblet also * as local stream for furhter external processing * if we have our weblet request. * <p/> * We can add a dummy request * * @param request * @return an input stream on our current weblet resource * @throws WebletException * @throws IOException */ public InputStream serviceStream(WebletRequest request, String mimetype) throws WebletException, IOException { Weblet weblet = getWeblet(request); return weblet.serviceStream(request.getPathInfo(), mimetype); }
/** * init method which is called by default to process the parameters * * @param config the webletconfig to be processed */ public void init(WebletConfig config) { super.init(config); // fetch the weblets init param _packageName = config.getInitParameter("package"); // fetch the resource root param /*auto fix path according to the specs the root must begin with a leading /*/ _resourceRoot = config.getInitParameter("resourceRoot"); if (StringUtils.isBlank(_resourceRoot)) _resourceRoot = "/"; _resourceRoot = _resourceRoot.trim(); if (!_resourceRoot.startsWith("/") && !_resourceRoot.startsWith("\\")) _resourceRoot = "/" + _resourceRoot; // init param missing, lets throw an error if (_packageName == null && _resourceRoot == null) { throw new WebletException("Missing either init parameter \"package\" or " + " or init parameter \"resourceRoot\" for " + " Weblet \"" + config.getWebletName() + "\""); } // the init was successful we now have all we need _resourceRoot = (_packageName != null) ? _packageName.replace('.', '/') : _resourceRoot; }
public void destroy() { Iterator i = _weblets.values().iterator(); while (i.hasNext()) { Weblet weblet = (Weblet) i.next(); weblet.destroy(); } _weblets = null; _webletConfigs = null; _webletMappings = null; _webletContextPath = null; }
/** * init method which is called by default to process the parameters * * @param config the webletconfig to be processed */ public void init(WebletConfig config) { super.init(config); // fetch the weblets init param String packageName = config.getInitParameter("package"); // fetch the resource root param String resourceRoot = config.getInitParameter("resourceRoot"); // String cacheTimeout = config.getInitParameter("cachecontrol-timeout"); // init param missing, lets throw an error if (packageName == null && resourceRoot == null) { throw new WebletException("Missing either init parameter \"package\" or " + " or init parameter \"resourceRoot\" for " + " Weblet \"" + config.getWebletName() + "\""); } // the init was successful we now have all we need _resourceRoot = (packageName != null) ? packageName.replace('.', '/') : resourceRoot; // optional init param }
public void destroy() { if(_weblets != null && _weblets.values() != null) { Iterator i = _weblets.values().iterator(); while (i != null && i.hasNext()) { Weblet weblet = (Weblet) i.next(); weblet.destroy(); } } _weblets = null; _webletConfigs = null; _webletMappings = null; _webletContextPath = null; }