@Override public Resource getResource(String path) { if (!once[0]) { once[0] = true; Object attr = request.getRequest().getAttribute("**"); File file; if (attr != null) { file = new File(PHttpResourceHandler.this.file, "/" + attr); } else { file = new File(PHttpResourceHandler.this.file); } if (file.exists()) { return new PathResource(file.getAbsoluteFile()); } else { return null; } } else { return null; } } };
new PathResource(new File("./src/main/resources").toPath().toRealPath())); context.addServlet(DefaultServlet.class, "/"); server.start();
new PathResource(new File("./src/main/resources").toPath().toRealPath())); context.addServlet(DefaultServlet.class, "/"); server.start();
/** * @return the resource associated with the configured properties file, creating it if necessary */ public Resource getConfigResource() { if (_configPath == null) return null; return new PathResource(_configPath); }
/** * Construct a Resource from provided path * * @param path the path * @return the Resource for the provided path * @since 9.4.10 */ public static Resource newResource(Path path) { return new PathResource(path); }
public static Resource newResource(File file) { return new PathResource(file.toPath()); }
@Override public Resource addPath(final String subpath) throws IOException { String cpath = URIUtil.canonicalPath(subpath); if ((cpath == null) || (cpath.length() == 0)) throw new MalformedURLException(subpath); if ("/".equals(cpath)) return this; // subpaths are always under PathResource // compensate for input subpaths like "/subdir" // where default resolve behavior would be // to treat that like an absolute path return new PathResource(this, subpath); }
resource=resource.substring(2); File file=new File(resource).getCanonicalFile(); return new PathResource(file);
return new PathResource(url);
/** * @return the resource associated with the configured properties file, creating it if necessary * @throws IOException if unable to get the resource */ public Resource getConfigResource() throws IOException { if (_configResource == null) { _configResource = new PathResource(_configPath); } return _configResource; }
/** * @return the resource associated with the configured properties file, creating it if necessary * @throws IOException if unable to get the resource */ public Resource getConfigResource() throws IOException { if (_configPath==null) return null; return new PathResource(_configPath); }
public static Resource newResource(File file) { return new PathResource(file.toPath()); }
@Override public Resource addPath(String apath) throws IOException, MalformedURLException { return new PathResource(this.path.getFileSystem().getPath(path.toString(), apath)); }
@Override public Resource addPath(final String subpath) throws IOException { String cpath = URIUtil.canonicalPath(subpath); if ((cpath == null) || (cpath.length() == 0)) throw new MalformedURLException(subpath); if ("/".equals(cpath)) return this; // subpaths are always under PathResource // compensate for input subpaths like "/subdir" // where default resolve behavior would be // to treat that like an absolute path return new PathResource(this, subpath); }
public static void main(String[] args) throws Exception { Server server = new Server(8080); Path webRootPath = new File("webapps/static-root/").toPath().toRealPath(); System.err.println("WebRoot is " + webRootPath); ResourceHandler handler = new ResourceHandler(); handler.setBaseResource(new PathResource(webRootPath)); handler.setDirectoriesListed(true); server.setHandler(handler); server.start(); server.join(); } }
new PathResource(getCustomPath(filename)) }; final Resource resource = Arrays.stream(possiblePropertiesResources) .filter(Resource::exists).reduce((previous, current) -> current).get();
gzip.setHandler(context); context.setContextPath("/"); context.setBaseResource(new PathResource(webRootPath)); context.setWelcomeFiles(new String[]{"index.html"});
public static void main(String[] args) throws Exception { Server server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setPort(8080); server.addConnector(connector); HandlerList handlers = new HandlerList(); server.setHandler(handlers); // Add Rewrite / Redirect handlers + Rules RewriteHandler rewriteHandler = new RewriteHandler(); MovedPermanentlyRule movedRule = new MovedPermanentlyRule(); movedRule.setRegex("http://www.company.com/dump/.*"); movedRule.setReplacement("https://api.company.com/dump/"); rewriteHandler.addRule(movedRule); handlers.addHandler(rewriteHandler); Path webRootPath = new File("webapps/alt-root/").toPath().toRealPath(); ServletContextHandler context = new ServletContextHandler(); handlers.addHandler(context); context.setContextPath("/"); context.setBaseResource(new PathResource(webRootPath)); context.setWelcomeFiles(new String[]{"index.html"}); context.addServlet(DumpServlet.class, "/dump/*"); server.start(); server.join(); } }
context.setBaseResource(new PathResource(webRootPath)); context.setWelcomeFiles(new String[]{"index.html"}); server.setHandler(context);
return new PathResource(url);