use of org.eclipse.jetty.server.handler.ResourceHandler in project pulsar by yahoo.
the class WebService method addStaticResources.
public void addStaticResources(String basePath, String resourcePath) {
ContextHandler capHandler = new ContextHandler();
capHandler.setContextPath(basePath);
ResourceHandler resHandler = new ResourceHandler();
resHandler.setBaseResource(Resource.newClassPathResource(resourcePath));
resHandler.setEtags(true);
resHandler.setCacheControl(WebService.HANDLER_CACHE_CONTROL);
capHandler.setHandler(resHandler);
handlers.add(capHandler);
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project hadoop by apache.
the class SLSWebApp method start.
public void start() throws Exception {
// static files
final ResourceHandler staticHandler = new ResourceHandler();
staticHandler.setMimeTypes(new MimeTypes());
staticHandler.setResourceBase("html");
Handler handler = new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
// timeunit
// second, divide millionsecond / 1000
int timeunit = 1000;
String timeunitLabel = "second";
if (request.getParameter("u") != null && request.getParameter("u").equalsIgnoreCase("m")) {
timeunit = 1000 * 60;
timeunitLabel = "minute";
}
// http request
if (target.equals("/")) {
printPageIndex(request, response);
} else if (target.equals("/simulate")) {
printPageSimulate(request, response, timeunit, timeunitLabel);
} else if (target.equals("/track")) {
printPageTrack(request, response, timeunit, timeunitLabel);
} else // js/css request
if (target.startsWith("/js") || target.startsWith("/css")) {
response.setCharacterEncoding("utf-8");
staticHandler.handle(target, baseRequest, request, response);
} else // json request
if (target.equals("/simulateMetrics")) {
printJsonMetrics(request, response);
} else if (target.equals("/trackMetrics")) {
printJsonTrack(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
server = new Server(port);
server.setHandler(handler);
server.start();
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project bnd by bndtools.
the class HttpConnectorTest method startJetty.
private static Server startJetty() throws Exception {
Server server = new Server();
// Create the login service
String REQUIRED_ROLE = "users";
HashLoginService loginSvc = new HashLoginService(REQUIRED_ROLE, USER_ROLE_FILE);
server.addBean(loginSvc);
// Start HTTP and HTTPS connectors
SelectChannelConnector httpConnector = new SelectChannelConnector();
httpConnector.setPort(0);
httpConnector.setHost(LOCALHOST);
server.addConnector(httpConnector);
SslSelectChannelConnector sslConnector = new SslSelectChannelConnector();
sslConnector.setPort(0);
sslConnector.setHost(LOCALHOST);
SslContextFactory contextFactory = sslConnector.getSslContextFactory();
contextFactory.setKeyStorePath(KEYSTORE_PATH);
contextFactory.setKeyStorePassword(KEYSTORE_PASS);
server.addConnector(sslConnector);
// Create the resource handler to serve files
ResourceHandler resourceHandler = new ETaggingResourceHandler();
resourceHandler.setResourceBase(RESOURCE_BASE);
resourceHandler.setDirectoriesListed(true);
// Setup user role constraints
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { REQUIRED_ROLE });
constraint.setAuthenticate(true);
// Map constraints to the secured directory
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec(SECURED_PATH);
// Setup the constraint handler
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.setAuthMethod("BASIC");
securityHandler.setHandler(resourceHandler);
securityHandler.setLoginService(loginSvc);
securityHandler.setConstraintMappings(new ConstraintMapping[] { cm });
// Finally!! Start the server
server.setHandler(securityHandler);
server.start();
while (!server.isRunning()) {
Thread.sleep(10);
}
HTTP_PORT = httpConnector.getLocalPort();
HTTPS_PORT = sslConnector.getLocalPort();
assertNotSame(Integer.valueOf(0), Integer.valueOf(HTTP_PORT));
assertNotSame(Integer.valueOf(-1), Integer.valueOf(HTTP_PORT));
assertNotSame(Integer.valueOf(0), Integer.valueOf(HTTPS_PORT));
assertNotSame(Integer.valueOf(-1), Integer.valueOf(HTTPS_PORT));
assertNotSame(Integer.valueOf(HTTP_PORT), Integer.valueOf(HTTPS_PORT));
return server;
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project nifi by apache.
the class AtlasAPIV2ServerEmulator method createServer.
private void createServer() throws Exception {
server = new Server();
final ContextHandlerCollection handlerCollection = new ContextHandlerCollection();
final ServletContextHandler staticContext = new ServletContextHandler();
staticContext.setContextPath("/");
final ServletContextHandler atlasApiV2Context = new ServletContextHandler();
atlasApiV2Context.setContextPath("/api/atlas/v2/");
handlerCollection.setHandlers(new Handler[] { staticContext, atlasApiV2Context });
server.setHandler(handlerCollection);
final ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setBaseResource(Resource.newClassPathResource("public", false, false));
staticContext.setHandler(resourceHandler);
final ServletHandler servletHandler = new ServletHandler();
atlasApiV2Context.insertHandler(servletHandler);
httpConnector = new ServerConnector(server);
httpConnector.setPort(21000);
server.setConnectors(new Connector[] { httpConnector });
servletHandler.addServletWithMapping(TypeDefsServlet.class, "/types/typedefs/");
servletHandler.addServletWithMapping(EntityBulkServlet.class, "/entity/bulk/");
servletHandler.addServletWithMapping(EntityGuidServlet.class, "/entity/guid/*");
servletHandler.addServletWithMapping(SearchByUniqueAttributeServlet.class, "/entity/uniqueAttribute/type/*");
servletHandler.addServletWithMapping(SearchBasicServlet.class, "/search/basic/");
servletHandler.addServletWithMapping(LineageServlet.class, "/debug/lineage/");
notificationServerEmulator = new AtlasNotificationServerEmulator();
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project traccar by tananaev.
the class WebServer method initWebApp.
private void initWebApp() {
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(config.getString("web.path"));
if (config.getBoolean("web.debug")) {
resourceHandler.setWelcomeFiles(new String[] { "debug.html", "index.html" });
// avoid locking files on Windows
resourceHandler.setMinMemoryMappedContentLength(-1);
} else {
String cache = config.getString("web.cacheControl");
if (cache != null && !cache.isEmpty()) {
resourceHandler.setCacheControl(cache);
}
resourceHandler.setWelcomeFiles(new String[] { "release.html", "index.html" });
}
handlers.addHandler(resourceHandler);
}
Aggregations