org.eclipse.jetty.util.resource.FileResource Java Examples
The following examples show how to use
org.eclipse.jetty.util.resource.FileResource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetaInfFolderConfiguration.java From logsniffer with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void preConfigure(final WebAppContext context) throws Exception { super.preConfigure(context); // let original MetaInfConfiguration do // it's thing first // Now add directory classpath resources final ArrayList<Resource> resources = new ArrayList<Resource>(); ClassLoader cl = ClassLoader.getSystemClassLoader(); URL[] urls = ((URLClassLoader)cl).getURLs(); for(URL url: urls){ Resource r= new FileResource(url); if (r.isDirectory()) { resources.add(r); } } scanJars(context, resources, false); }
Example #2
Source File: AudioResourceServlet.java From BeyondUPnP with Apache License 2.0 | 6 votes |
@Override public Resource getResource(String pathInContext) { Resource resource = null; Log.i(AudioResourceServlet.class.getSimpleName(),"Path:" + pathInContext); try { String id = Utils.parseResourceId(pathInContext); Log.i(AudioResourceServlet.class.getSimpleName(),"Id:" + id); Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, Long.parseLong(id)); Cursor cursor = BeyondApplication.getApplication().getContentResolver().query( uri, null,null, null, null); cursor.moveToFirst(); String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)); File file = new File(path); if (file.exists()) { resource = FileResource.newResource(file); } } catch (Exception e) { e.printStackTrace(); } return resource; }
Example #3
Source File: VideoResourceServlet.java From BeyondUPnP with Apache License 2.0 | 6 votes |
@Override public Resource getResource(String pathInContext) { Resource resource = null; Log.i(VideoResourceServlet.class.getSimpleName(), "Path:" + pathInContext); try { String id = Utils.parseResourceId(pathInContext); Log.i(VideoResourceServlet.class.getSimpleName(), "Id:" + id); Uri uri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, Long.parseLong(id)); Cursor cursor = BeyondApplication.getApplication().getContentResolver().query( uri, null, null, null, null); cursor.moveToFirst(); String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); File file = new File(path); if (file.exists()) { resource = FileResource.newResource(file); } } catch (Exception e) { e.printStackTrace(); } return resource; }
Example #4
Source File: GerritRestClientTest.java From gerrit-rest-java-client with Apache License 2.0 | 5 votes |
public String startJetty(Class<? extends HttpServlet> loginServletClass) throws Exception { Server server = new Server(0); ResourceHandler resourceHandler = new ResourceHandler(); MimeTypes mimeTypes = new MimeTypes(); mimeTypes.addMimeMapping("json", "application/json"); resourceHandler.setMimeTypes(mimeTypes); URL url = this.getClass().getResource("."); resourceHandler.setBaseResource(new FileResource(url)); resourceHandler.setWelcomeFiles(new String[] {"changes.json", "projects.json", "account.json"}); ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.addServlet(loginServletClass, "/login/"); ServletContextHandler basicAuthContextHandler = new ServletContextHandler(ServletContextHandler.SECURITY); basicAuthContextHandler.setSecurityHandler(basicAuth("foo", "bar", "Gerrit Auth")); basicAuthContextHandler.setContextPath("/a"); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] { servletContextHandler, resourceHandler, basicAuthContextHandler }); server.setHandler(handlers); server.start(); Connector connector = server.getConnectors()[0]; String host = "localhost"; int port = connector.getLocalPort(); return String.format("http://%s:%s", host, port); }