List of usage examples for javax.servlet ServletContext getClassLoader
public ClassLoader getClassLoader();
From source file:com.tbodt.jswerve.servlet.JSwerveServlet.java
private void spiderWar(ServletContext ctx, String start, Set<Class<?>> classes) { for (String path : ctx.getResourcePaths(start)) if (ctx.getResourcePaths(path) != null && !ctx.getResourcePaths(path).isEmpty()) spiderWar(ctx, path, classes); else if (path.endsWith(".class")) try { classes.add(ctx.getClassLoader().loadClass(path .substring("/WEB-INF/classes/".length(), path.indexOf(".class")).replace('/', '.'))); } catch (ClassNotFoundException ex) { throw new WTFException("class" + ex.getMessage() + " not found! but I saw it!"); }/* www .j a v a 2s . c om*/ }
From source file:com.google.zxing.web.DecodeServlet.java
@Override public void init(ServletConfig servletConfig) throws ServletException { Logger logger = Logger.getLogger("com.google.zxing"); ServletContext context = servletConfig.getServletContext(); logger.addHandler(new ServletContextLogHandler(context)); File repository = (File) context.getAttribute("javax.servlet.context.tempdir"); FileCleaningTracker fileCleaningTracker = FileCleanerCleanup.getFileCleaningTracker(context); diskFileItemFactory = new DiskFileItemFactory(1 << 16, repository); diskFileItemFactory.setFileCleaningTracker(fileCleaningTracker); URL blockURL = context.getClassLoader().getResource("/private/uri-block-substrings.txt"); if (blockURL == null) { blockedURLSubstrings = Collections.emptyList(); } else {/* www . jav a 2 s.co m*/ try { blockedURLSubstrings = Resources.readLines(blockURL, StandardCharsets.UTF_8); } catch (IOException ioe) { throw new ServletException(ioe); } log.info("Blocking URIs containing: " + blockedURLSubstrings); } }
From source file:password.pwm.http.servlet.resource.ResourceFileServlet.java
private static FileResource handleWebjarURIs(final ServletContext servletContext, final String resourcePathUri) throws PwmUnrecoverableException { if (resourcePathUri.startsWith(WEBJAR_BASE_URL_PATH)) { // This allows us to override a webjar file, if needed. Mostly helpful during development. final File file = new File(servletContext.getRealPath(resourcePathUri)); if (file.exists()) { return new RealFileResource(file); }//from w w w.j av a 2s . c om final String remainingPath = resourcePathUri.substring(WEBJAR_BASE_URL_PATH.length(), resourcePathUri.length()); final String webJarName; final String webJarPath; { final int slashIndex = remainingPath.indexOf("/"); if (slashIndex < 0) { return null; } webJarName = remainingPath.substring(0, slashIndex); webJarPath = remainingPath.substring(slashIndex + 1, remainingPath.length()); } final String versionString = WEB_JAR_VERSION_MAP.get(webJarName); if (versionString == null) { return null; } final String fullPath = WEBJAR_BASE_FILE_PATH + "/" + webJarName + "/" + versionString + "/" + webJarPath; if (WEB_JAR_ASSET_LIST.contains(fullPath)) { final ClassLoader classLoader = servletContext.getClassLoader(); final InputStream inputStream = classLoader.getResourceAsStream(fullPath); if (inputStream != null) { return new InputStreamFileResource(inputStream, fullPath); } } } return null; }