String webletVersion = webletConfig.getWebletVersion(); String webletPath = matcher.group(1);
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 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); }
/** * 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); }
private long getTimeout(WebletConfig config) { String cacheControlTimeout = config.getInitParameter("cachecontrol-timeout"); long timeout = WebletResourceloadingUtils.getNever(); if (!StringUtils.isBlank(cacheControlTimeout)) { try { timeout = Long.parseLong(cacheControlTimeout); } catch (RuntimeException ex) { Log log = LogFactory.getLog(this.getClass()); log.error("Weblets: Cache control is set but to an invalid value setting now never instead"); } } return timeout; }
String mimeType = webConfig.getMimeType(pathInfo); if(mimeType != null) { response.setDefaultContentType(mimeType); Set allowedResources = webConfig.getAllowedResources();
Matcher matcher = _WEBLET_PATH_PATTERN.matcher(urlPattern); if (matcher.matches()) { String webletVersion = webletConfig.getWebletVersion(); String webletPath = matcher.group(1); StringBuffer buffer = new StringBuffer();
/** * 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 String getResourceUri( String webletName, String pathInfo) throws WebletException { WebletConfig config = (WebletConfig) _webletConfigs.get(webletName); if (config == null) throw new WebletException("Missing Weblet configuration for '" + webletName + "'"); String webletPath = (String) _webletPaths.get(webletName); if (webletPath == null) throw new WebletException("Missing Weblet mapping for '" + webletName + "'"); String webletVersion = config.getWebletVersion(); // URL-syntax /webletPath[$version]/pathInfo StringBuffer buffer = new StringBuffer(); buffer.append(webletPath); if (webletVersion != null) { buffer.append('$'); buffer.append(webletVersion); } if (pathInfo != null) { buffer.append(pathInfo); } String webletURL = buffer.toString(); if (_webletURLFormat != null) webletURL = _webletURLFormat.format(new Object[]{webletURL}); return webletURL; }
/** * 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 String getResourceUri( String webletName, String pathInfo) throws WebletException { WebletConfig config = (WebletConfig) _webletConfigs.get(webletName); if (config == null) throw new WebletException("Missing Weblet configuration for '" + webletName + "'"); String webletPath = (String) _webletPaths.get(webletName); if (webletPath == null) throw new WebletException("Missing Weblet mapping for '" + webletName + "'"); String webletVersion = config.getWebletVersion(); // URL-syntax /webletPath[$version]/pathInfo StringBuffer buffer = new StringBuffer(); buffer.append(webletPath); if (webletVersion != null) { buffer.append('$'); buffer.append(webletVersion); } if (pathInfo != null) { buffer.append(pathInfo); } String webletURL = buffer.toString(); if (_webletURLFormat != null) webletURL = _webletURLFormat.format(new Object[]{webletURL}); return webletURL; }
/** * 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; }
String webletVersion = config.getWebletVersion(); boolean load = false; if (isVersionedWeblet(webletVersion)) {
String webletVersion = config.getWebletVersion(); if (!isVersionedWeblet(webletVersion)) { response.setLastModified(lastmodified);