Search in sources :

Example 51 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project tycho by eclipse.

the class ProxySupportTest method startHttpServer.

private void startHttpServer() throws Exception {
    httpServer = new Server();
    Connector connector = new SocketConnector();
    httpServerPort = findFreePort();
    connector.setPort(httpServerPort);
    httpServer.addConnector(connector);
    ContextHandler context = new ContextHandler(httpServer, "/test");
    context.setResourceBase(new File(baseDir, "repo").getAbsolutePath());
    context.setHandler(new ResourceHandler());
    httpServer.setHandler(context);
    httpServer.start();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SocketConnector(org.eclipse.jetty.server.bio.SocketConnector) Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) ProxyServer(org.sonatype.jettytestsuite.ProxyServer) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) SocketConnector(org.eclipse.jetty.server.bio.SocketConnector) File(java.io.File)

Example 52 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project incubator-gobblin by apache.

the class AdminWebServer method buildStaticResourceHandler.

private ResourceHandler buildStaticResourceHandler() {
    ResourceHandler staticResourceHandler = new ResourceHandler();
    staticResourceHandler.setDirectoriesListed(true);
    staticResourceHandler.setWelcomeFiles(new String[] { "index.html" });
    String staticDir = getClass().getClassLoader().getResource("static").toExternalForm();
    staticResourceHandler.setResourceBase(staticDir);
    return staticResourceHandler;
}
Also used : ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler)

Example 53 with ResourceHandler

use of org.eclipse.jetty.server.handler.ResourceHandler in project Universal-G-Code-Sender by winder.

the class PendantUI method start.

/**
 * Launches the local web server.
 *
 * @return the url for the pendant interface
 */
public List<PendantURLBean> start() {
    server = new Server(port);
    ResourceHandler staticResourceHandler = new ResourceHandler();
    staticResourceHandler.setDirectoriesListed(true);
    staticResourceHandler.setWelcomeFiles(new String[] { "index.html" });
    staticResourceHandler.setBaseResource(getBaseResource("/resources/ugs-pendant"));
    ContextHandler staticResourceHandlerContext = new ContextHandler();
    staticResourceHandlerContext.setContextPath("/");
    staticResourceHandlerContext.setHandler(staticResourceHandler);
    // Create a servlet servletContextHandler
    ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    servletContextHandler.setContextPath("/api");
    ServletHolder servletHolder = servletContextHandler.addServlet(ServletContainer.class, "/*");
    servletHolder.setInitOrder(1);
    servletHolder.setInitParameter("javax.ws.rs.Application", AppConfig.class.getCanonicalName());
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { servletContextHandler, staticResourceHandlerContext, new DefaultHandler() });
    server.setHandler(handlers);
    try {
        server.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return getUrlList();
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) SocketException(java.net.SocketException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Aggregations

ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)53 Server (org.eclipse.jetty.server.Server)31 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)20 HandlerList (org.eclipse.jetty.server.handler.HandlerList)20 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)16 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)16 ServerConnector (org.eclipse.jetty.server.ServerConnector)14 File (java.io.File)13 IOException (java.io.IOException)7 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)7 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)7 HashLoginService (org.eclipse.jetty.security.HashLoginService)5 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)5 Constraint (org.eclipse.jetty.util.security.Constraint)5 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)4 Handler (org.eclipse.jetty.server.Handler)4 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)4 Path (java.nio.file.Path)3