use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.
the class Quickstart method main.
public static void main(String... args) throws Exception {
if (args.length < 1)
error("No WAR file or directory given");
//war file or dir to start
String war = args[0];
//optional jetty context xml file to configure the webapp
Resource contextXml = null;
if (args.length > 1)
contextXml = Resource.newResource(args[1]);
Server server = new Server(8080);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoPreconfigure(true);
webapp.setWar(war);
webapp.setContextPath("/");
//apply context xml file
if (contextXml != null) {
// System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
xmlConfiguration.configure(webapp);
}
server.setHandler(webapp);
server.start();
server.join();
}
use of org.eclipse.jetty.util.resource.Resource in project BeyondUPnP by kevinshine.
the class VideoResourceServlet method getResource.
@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;
}
use of org.eclipse.jetty.util.resource.Resource in project BeyondUPnP by kevinshine.
the class AudioResourceServlet method getResource.
@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;
}
use of org.eclipse.jetty.util.resource.Resource in project ninja by ninjaframework.
the class NinjaJetty method buildServerOrApplyConfiguration.
private Server buildServerOrApplyConfiguration(String jettyConfiguration, Server server) throws Exception {
// try local file first
Resource jettyConfigurationFile = Resource.newResource(jettyConfiguration);
if (jettyConfigurationFile == null || !jettyConfigurationFile.exists()) {
// fallback to classpath
jettyConfigurationFile = Resource.newClassPathResource(jettyConfiguration);
if (jettyConfigurationFile == null || !jettyConfigurationFile.exists()) {
throw new FileNotFoundException("Unable to find jetty configuration file either locally or on classpath '" + jettyConfiguration + "'");
}
}
logger.info("Applying jetty configuration '{}'", jettyConfigurationFile);
try (InputStream is = jettyConfigurationFile.getInputStream()) {
XmlConfiguration configuration = new XmlConfiguration(is);
// create or apply to existing
if (server == null) {
return (Server) configuration.configure();
} else {
return (Server) configuration.configure(server);
}
}
}
use of org.eclipse.jetty.util.resource.Resource in project neo4j by neo4j.
the class Jetty9WebServer method loadStaticContent.
private void loadStaticContent(SessionManager sm, String mountPoint) {
String contentLocation = staticContent.get(mountPoint);
try {
SessionHandler sessionHandler = new SessionHandler(sm);
sessionHandler.setServer(getJetty());
final WebAppContext staticContext = new WebAppContext();
staticContext.setServer(getJetty());
staticContext.setContextPath(mountPoint);
staticContext.setSessionHandler(sessionHandler);
staticContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
URL resourceLoc = getClass().getClassLoader().getResource(contentLocation);
if (resourceLoc != null) {
URL url = resourceLoc.toURI().toURL();
final Resource resource = Resource.newResource(url);
staticContext.setBaseResource(resource);
addFiltersTo(staticContext);
staticContext.addFilter(new FilterHolder(new NoCacheHtmlFilter()), "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD));
handlers.addHandler(staticContext);
} else {
log.warn("No static content available for Neo Server at %s, management console may not be available.", jettyAddress);
}
} catch (Exception e) {
log.error("Unknown error loading static content", e);
e.printStackTrace();
throw new RuntimeException(e);
}
}
Aggregations