use of org.eclipse.jetty.webapp.WebAppContext 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);
}
}
use of org.eclipse.jetty.webapp.WebAppContext in project hadoop by apache.
the class TestHttpFSServer method createHttpFSServer.
private void createHttpFSServer(boolean addDelegationTokenAuthHandler) throws Exception {
File homeDir = TestDirHelper.getTestDir();
Assert.assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir());
HttpFSServerWebApp.setHomeDirForCurrentThread(homeDir.getAbsolutePath());
File secretFile = new File(new File(homeDir, "conf"), "secret");
Writer w = new FileWriter(secretFile);
w.write("secret");
w.close();
//HDFS configuration
File hadoopConfDir = new File(new File(homeDir, "conf"), "hadoop-conf");
hadoopConfDir.mkdirs();
Configuration hdfsConf = TestHdfsHelper.getHdfsConf();
// Http Server's conf should be based on HDFS's conf
Configuration conf = new Configuration(hdfsConf);
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true);
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, true);
File hdfsSite = new File(hadoopConfDir, "hdfs-site.xml");
OutputStream os = new FileOutputStream(hdfsSite);
conf.writeXml(os);
os.close();
//HTTPFS configuration
conf = new Configuration(false);
if (addDelegationTokenAuthHandler) {
conf.set("httpfs.authentication.type", HttpFSKerberosAuthenticationHandlerForTesting.class.getName());
}
conf.set("httpfs.services.ext", MockGroups.class.getName());
conf.set("httpfs.admin.group", HadoopUsersConfTestHelper.getHadoopUserGroups(HadoopUsersConfTestHelper.getHadoopUsers()[0])[0]);
conf.set("httpfs.proxyuser." + HadoopUsersConfTestHelper.getHadoopProxyUser() + ".groups", HadoopUsersConfTestHelper.getHadoopProxyUserGroups());
conf.set("httpfs.proxyuser." + HadoopUsersConfTestHelper.getHadoopProxyUser() + ".hosts", HadoopUsersConfTestHelper.getHadoopProxyUserHosts());
conf.set("httpfs.authentication.signature.secret.file", secretFile.getAbsolutePath());
conf.set("httpfs.hadoop.config.dir", hadoopConfDir.toString());
File httpfsSite = new File(new File(homeDir, "conf"), "httpfs-site.xml");
os = new FileOutputStream(httpfsSite);
conf.writeXml(os);
os.close();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource("webapp");
WebAppContext context = new WebAppContext(url.getPath(), "/webhdfs");
Server server = TestJettyHelper.getJettyServer();
server.setHandler(context);
server.start();
if (addDelegationTokenAuthHandler) {
HttpFSServerWebApp.get().setAuthority(TestJettyHelper.getAuthority());
}
}
use of org.eclipse.jetty.webapp.WebAppContext in project spark by perwendel.
the class ServletTest method setup.
@BeforeClass
public static void setup() throws InterruptedException {
testUtil = new SparkTestUtil(PORT);
final Server server = new Server();
ServerConnector connector = new ServerConnector(server);
// Set some timeout options to make debugging easier.
connector.setIdleTimeout(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(PORT);
server.setConnectors(new Connector[] { connector });
WebAppContext bb = new WebAppContext();
bb.setServer(server);
bb.setContextPath(SOMEPATH);
bb.setWar("src/test/webapp");
server.setHandler(bb);
CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable() {
@Override
public void run() {
try {
LOGGER.info(">>> STARTING EMBEDDED JETTY SERVER for jUnit testing of SparkFilter");
server.start();
latch.countDown();
System.in.read();
LOGGER.info(">>> STOPPING EMBEDDED JETTY SERVER");
server.stop();
server.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(100);
}
}
}).start();
latch.await();
}
use of org.eclipse.jetty.webapp.WebAppContext in project Synthese_2BIN by TheYoungSensei.
the class MyServer method main.
public static void main(String[] args) throws Exception {
// lie le server � un port
Server server = new Server(8000);
// instancie un WebAppContext pour configurer le server
WebAppContext context = new WebAppContext();
// O� se trouvent les fichiers (ils seront servis par un DefaultServlet)
context.setResourceBase("www");
// MaServlet r�pondra aux requ�tes commen�ant par /chemin/
context.addServlet(new ServletHolder(new MachineServlet()), "/Machine");
// Le DefaultServlet sert des fichiers (html, js, css, images, ...). Il est en g�n�ral ajout� en dernier pour que les autres servlets soient prioritaires sur l�interpr�tation des URLs.
context.addServlet(new ServletHolder(new DefaultServlet()), "/");
// ce server utilise ce context
server.setHandler(context);
// allons-y
server.start();
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class Activator method start.
/**
*
* @param context
*/
public void start(BundleContext context) throws Exception {
//Create webappA as a Service and target it at the default server
WebAppContext webapp = new WebAppContext();
webapp.addServlet(new ServletHolder(new TestServlet()), "/mime");
Dictionary props = new Hashtable();
props.put("war", "webappA");
props.put("contextPath", "/acme");
props.put("managedServerName", "defaultJettyServer");
_srA = context.registerService(WebAppContext.class.getName(), webapp, props);
//Create a second webappB as a Service and target it at a custom Server
//deployed by another bundle
WebAppContext webappB = new WebAppContext();
Dictionary propsB = new Hashtable();
propsB.put("war", "webappB");
propsB.put("contextPath", "/acme");
propsB.put("managedServerName", "fooServer");
_srB = context.registerService(WebAppContext.class.getName(), webappB, propsB);
}
Aggregations