use of org.eclipse.jetty.server.handler.ResourceHandler in project graphql-java by graphql-java.
the class HttpMain method main.
public static void main(String[] args) throws Exception {
//
// This example uses Jetty as an embedded HTTP server
Server server = new Server(PORT);
//
// In Jetty, handlers are how your get called backed on a request
HttpMain main_handler = new HttpMain();
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(false);
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setResourceBase("./src/test/resources/httpmain");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, main_handler });
server.setHandler(handlers);
server.start();
server.join();
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project selenium_java by sergueik.
the class AngularAndWebDriverTest method before_suite.
@BeforeSuite
public void before_suite() throws Exception {
// Launch Protractor's own test app on http://localhost:8080
((StdErrLog) Log.getRootLogger()).setLevel(StdErrLog.LEVEL_OFF);
webServer = new Server(new QueuedThreadPool(6));
ServerConnector connector = new ServerConnector(webServer, new HttpConnectionFactory());
connector.setPort(8080);
webServer.addConnector(connector);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setResourceBase("src/test/webapp");
HandlerList handlers = new HandlerList();
MovedContextHandler effective_symlink = new MovedContextHandler(webServer, "/lib/angular", "/lib/angular_v1.2.9");
handlers.setHandlers(new Handler[] { effective_symlink, resource_handler, new DefaultHandler() });
webServer.setHandler(handlers);
webServer.start();
setupBrowser("chrome");
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
ngWebDriver = new NgWebDriver(driver);
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project stagen by wiztools.
the class RunnerRun method run.
@Override
public void run(final File baseDir) throws IOException, ExecutorException {
// Generate site:
clean.run(baseDir);
gen.run(baseDir);
// Start monitoring service:
startMonitoring(baseDir);
// Start server:
try {
LOG.log(Level.INFO, "Starting HTTP server at port: {0}", cmd.port);
Server server = new Server(cmd.port);
ResourceHandler rh = new ResourceHandler();
rh.setDirectoriesListed(true);
rh.setWelcomeFiles(new String[] { "index.html" });
rh.setResourceBase(Constants.getOutDir(baseDir).getPath());
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { rh, new DefaultHandler() });
server.setHandler(handlers);
server.start();
server.join();
} catch (Exception ex) {
throw new ExecutorException(ex);
}
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project EventHub by Codecademy.
the class EventHubHandler method main.
public static void main(String[] args) throws Exception {
Properties properties = new Properties();
properties.load(EventHub.class.getClassLoader().getResourceAsStream("hub.properties"));
properties.load(EventHubHandler.class.getClassLoader().getResourceAsStream("web.properties"));
properties.putAll(System.getProperties());
Injector injector = Guice.createInjector(Modules.override(new DmaIdListModule(), new DatedEventIndexModule(), new ShardedEventIndexModule(), new PropertiesIndexModule(), new UserEventIndexModule(), new EventStorageModule(), new UserStorageModule(), new EventHubModule(properties)).with(new Module()));
final EventHubHandler eventHubHandler = injector.getInstance(EventHubHandler.class);
int port = injector.getInstance(Key.get(Integer.class, Names.named("eventhubhandler.port")));
final Server server = new Server(port);
@SuppressWarnings("ConstantConditions") String webDir = EventHubHandler.class.getClassLoader().getResource("frontend").toExternalForm();
HashLoginService loginService = new HashLoginService();
loginService.putUser(properties.getProperty("eventhubhandler.username"), new Password(properties.getProperty("eventhubhandler.password")), new String[] { "user" });
server.addBean(loginService);
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
Constraint constraint = new Constraint();
constraint.setName("auth");
constraint.setAuthenticate(true);
constraint.setRoles(new String[] { "user", "admin" });
ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec("/*");
mapping.setConstraint(constraint);
securityHandler.setConstraintMappings(Collections.singletonList(mapping));
securityHandler.setAuthenticator(new BasicAuthenticator());
securityHandler.setLoginService(loginService);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(false);
resourceHandler.setWelcomeFiles(new String[] { "main.html" });
resourceHandler.setResourceBase(webDir);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { new JsonpCallbackHandler(eventHubHandler), securityHandler });
server.setHandler(handlers);
securityHandler.setHandler(resourceHandler);
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
if (server.isStarted()) {
try {
server.stop();
eventHubHandler.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, "Stop Jetty Hook"));
server.join();
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project saga by timurstrekalov.
the class FileServer method start.
public int start() {
final SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(0);
server.addConnector(connector);
final HandlerCollection handlers = new HandlerCollection();
final ResourceHandler resourceHandler = new ResourceHandler() {
@Override
protected void doResponseHeaders(final HttpServletResponse response, final Resource resource, final String mimeType) {
response.addDateHeader("Expires", 0L);
}
};
resourceHandler.setDirectoriesListed(true);
resourceHandler.setResourceBase(resourceBase);
handlers.addHandler(resourceHandler);
server.setHandler(handlers);
try {
server.start();
logger.info("File server started on port {}", connector.getLocalPort());
} catch (final Exception e) {
throw new RuntimeException(e);
}
return connector.getLocalPort();
}
Aggregations