Refine search
@Autowired ServletContext servletContext; ... myMethod() { File rootDir = new File( servletContext.getRealPath("/WEB-INF/myDIR/") ); }
Map loadManifest() throws IOException { File manifestFile = new File(servletContext.getRealPath(servletContext.getInitParameter("rails.root") + "/public/assets/webpack/manifest.json")); if (!manifestFile.exists()) { throw new RuntimeException("Could not load compiled manifest from 'webpack/manifest.json' - have you run `rake webpack:compile`?"); } Gson gson = new Gson(); Map manifest = gson.fromJson(FileUtils.readFileToString(manifestFile, UTF_8), Map.class); if (manifest.containsKey("errors") && !((List) manifest.get("errors")).isEmpty()) { throw new RuntimeException("There were errors in manifest.json file"); } Map entrypoints = (Map) manifest.get("entrypoints"); if (entrypoints == null) { throw new RuntimeException("Could not find any entrypoints in the manifest.json file."); } return entrypoints; }
/** * Returns the URL of the {@code WEB-INF/classes} folder. * <p> * This finds the URLs using the {@link ServletContext}. * * @return the collection of URLs, not null */ public static URL forWebInfClasses(final ServletContext servletContext) { try { final String path = servletContext.getRealPath("/WEB-INF/classes"); if (path != null) { final File file = new File(path); if (file.exists()) return file.toURL(); } else { return servletContext.getResource("/WEB-INF/classes"); } } catch (MalformedURLException e) { /*fuck off*/ } return null; }
/** * Returns the URL of the {@code WEB-INF/classes} folder. * <p> * This finds the URLs using the {@link ServletContext}. * * @return the collection of URLs, not null */ public static URL forWebInfClasses(final ServletContext servletContext) { try { final String path = servletContext.getRealPath("/WEB-INF/classes"); if (path != null) { final File file = new File(path); if (file.exists()) return file.toURL(); } else { return servletContext.getResource("/WEB-INF/classes"); } } catch (MalformedURLException e) { /*fuck off*/ } return null; }
public void initialize() throws IOException { if (!systemEnvironment.useCompressedJs()) { return; } String assetsDirPath = servletContext.getRealPath(servletContext.getInitParameter("rails.root") + "/public/assets/"); File assetsDir = new File(assetsDirPath); if (!assetsDir.exists()) { throw new RuntimeException(String.format("Assets directory does not exist %s", assetsDirPath)); } Collection files = FileUtils.listFiles(assetsDir, new RegexFileFilter(MANIFEST_FILE_PATTERN), null); if (files.isEmpty()) { throw new RuntimeException(String.format("Manifest json file was not found at %s", assetsDirPath)); } File manifestFile = (File) files.iterator().next(); LOG.info("Found rails assets manifest file named {} ", manifestFile.getName()); String manifest = FileUtils.readFileToString(manifestFile, UTF_8); Gson gson = new Gson(); railsAssetsManifest = gson.fromJson(manifest, RailsAssetsManifest.class); LOG.info("Successfully read rails assets manifest file located at {}", manifestFile.getAbsolutePath()); }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { String absoluteDiskPath = getServletContext().getRealPath(req.getPathInfo()); File requestedFile = new File(absoluteDiskPath); // async-profiler version 1.4 writes 'Started [cpu] profiling' to output file when profiler is running which // gets replaced by final output. If final output is not ready yet, the file size will be <100 bytes (in all modes). if (requestedFile.length() < 100) { LOG.info("{} is incomplete. Sending auto-refresh header..", requestedFile); resp.setHeader("Refresh", "2," + req.getRequestURI()); resp.getWriter().write("This page will auto-refresh every 2 second until output file is ready.."); } else { super.doGet(req, resp); } } }
public String getAppRoot() { String webinf = getServletContext().getRealPath("/WEB-INF/"); if (webinf == null) { log.info("/WEB-INF/ not Found?!"); if (new File("src/main/webapp").exists()) return new File("src/main/webapp").getAbsolutePath(); if (new File("src/main/resources/webapp").exists()) return new File("src/main/resources/webapp").getAbsolutePath(); return "./webapp"; } String root = getServletContext().getRealPath("/").replace('\\', '/'); if (root.endsWith("/")) return root.substring(0, root.length() - 1); else if (root.endsWith("/.")) return root.substring(0, root.length() - 2); return root; }
/** * Parses the http request for the real script or template source file. * * @param request * the http request to analyze * @return a file object using an absolute file path name, or <code>null</code> if the * servlet container cannot translate the virtual path to a real * path for any reason (such as when the content is being made * available from a .war archive). */ protected File getScriptUriAsFile(HttpServletRequest request) { String uri = getScriptUri(request); String real = servletContext.getRealPath(uri); if (real == null) { return null; } return new File(real).getAbsoluteFile(); }
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { ServletContext cntx= req.getServletContext(); // Get the absolute path of the image String filename = cntx.getRealPath("Images/button.png"); // retrieve mimeType dynamically String mime = cntx.getMimeType(filename); if (mime == null) { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } resp.setContentType(mime); File file = new File(filename); resp.setContentLength((int)file.length()); FileInputStream in = new FileInputStream(file); OutputStream out = resp.getOutputStream(); // Copy the contents of the file to the output stream byte[] buf = new byte[1024]; int count = 0; while ((count = in.read(buf)) >= 0) { out.write(buf, 0, count); } out.close(); in.close(); }
protected void generateNamePrefixOnce () { URI uri = null; String realPath = servletContext.getRealPath("/"); if (realPath != null) { uri = new File(realPath).toURI();}//prevent NPE if in .war try { URL res = servletContext.getResource("/"); if (res != null) { uri = res.toURI(); } } catch (MalformedURLException ignore) { } catch (URISyntaxException ignore) { } if (uri != null) { try { namePrefix = uri.toURL().toExternalForm(); return; } catch (MalformedURLException e) { log("generateNamePrefixOnce [ERROR] Malformed URL for base path / == '"+ uri +'\'', e); } } namePrefix = ""; }
String value = (String) env.lookup(name); if(value!=null && value.trim().length()>0) return new FileAndDescription(new File(value.trim()),"JNDI/java:comp/env/"+name); return new FileAndDescription(new File(value.trim()),"JNDI/"+name); } catch (NamingException e) { String root = event.getServletContext().getRealPath("/WEB-INF/workspace"); if(root!=null) { File ws = new File(root.trim());
String filepath = servletContext.getRealPath(path); if (filepath != null) { File file = new File(filepath); if (file.exists()) { return file; if (index < items.size()) { filepath = servletContext.getRealPath(items.get(index)); index++; if (filepath != null) { File file = new File(filepath); while (index < items.size()) { file = new File(file, items.get(index)); index++;
spacing = "true".equals(spacingStr); String path = getServletContext().getRealPath("/WEB-INF/data/models"); for (String classifier : new File(path).list()) { classifiers.add(classifier);
@Override public void init() throws ServletException { pipeline = new StanfordCoreNLP(); String xslPath = getServletContext(). getRealPath("/WEB-INF/data/CoreNLP-to-HTML.xsl"); try { Builder builder = new Builder(); Document stylesheet = builder.build(new File(xslPath)); corenlpTransformer = new XSLTransform(stylesheet); } catch (Exception e) { throw new ServletException(e); } }
String prefix = servletContext.getRealPath("/"); File webapps = new File(prefix); System.setProperty("red5.webapp.root", webapps.getParent()); webapps = null;
File fh = new File(value); dataDirStr = servContext.getRealPath("/data"); LOGGER.info("Falling back to embedded data directory: " + dataDirStr);
String gzipPath = path + ".gz"; if (useGzipCompression(request, response, path, gzipPath)) { File output = new File(getServletContext().getRealPath(gzipPath)); if (output.exists()) { response.addHeader("Content-Encoding", "gzip");
public Object findTemplateSource(String name) throws IOException { String fullPath = subdirPath + name; if (attemptFileAccess) { // First try to open as plain file (to bypass servlet container resource caches). try { String realPath = servletContext.getRealPath(fullPath); if (realPath != null) { File file = new File(realPath); if (file.canRead() && file.isFile()) { return file; } } } catch (SecurityException e) { ;// ignore } } // If it fails, try to open it with servletContext.getResource. URL url = null; try { url = servletContext.getResource(fullPath); } catch (MalformedURLException e) { LOG.warn("Could not retrieve resource " + StringUtil.jQuoteNoXSS(fullPath), e); return null; } return url == null ? null : new URLTemplateSource(url, getURLConnectionUsesCaches()); }
if(testPropertiesFile != null && new File(testPropertiesFile).exists()){ try { String props = IOUtils.stringFromFile(testPropertiesFile); String modelDir = getServletContext().getRealPath("/WEB-INF/data/"+modelNametoDirName.get(model)); testProps.setProperty("patternsWordsDir", modelDir); logger.info("Reading saved model from " + modelDir);
private void scanForCustomAnnotation(Set<Class<?>> atmosphereAnnotatedClasses) throws IOException { handler.flushCoreAnnotations(atmosphereAnnotatedClasses); BytecodeBasedAnnotationProcessor b = new BytecodeBasedAnnotationProcessor(handler); b.configure(framework.getAtmosphereConfig()); String path = framework.getServletContext().getRealPath(framework.getHandlersPath()); if (path != null) { b.scan(new File(path)).destroy(); } else { logger.warn("Unable to scan using File. Scanning classpath"); b.scanAll(); } }