Search in sources :

Example 41 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class DataConstraintsTest method startServer.

@Before
public void startServer() {
    _server = new Server();
    HttpConnectionFactory http = new HttpConnectionFactory();
    http.getHttpConfiguration().setSecurePort(9999);
    http.getHttpConfiguration().setSecureScheme("BWTP");
    _connector = new LocalConnector(_server, http);
    _connector.setIdleTimeout(300000);
    HttpConnectionFactory https = new HttpConnectionFactory();
    https.getHttpConfiguration().addCustomizer(new HttpConfiguration.Customizer() {

        @Override
        public void customize(Connector connector, HttpConfiguration channelConfig, Request request) {
            request.setScheme(HttpScheme.HTTPS.asString());
            request.setSecure(true);
        }
    });
    _connectorS = new LocalConnector(_server, https);
    _server.setConnectors(new Connector[] { _connector, _connectorS });
    ContextHandler _context = new ContextHandler();
    _session = new SessionHandler();
    _context.setContextPath("/ctx");
    _server.setHandler(_context);
    _context.setHandler(_session);
    _security = new ConstraintSecurityHandler();
    _session.setHandler(_security);
    _security.setHandler(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            response.sendError(404);
        }
    });
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) LocalConnector(org.eclipse.jetty.server.LocalConnector) Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) LocalConnector(org.eclipse.jetty.server.LocalConnector) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Before(org.junit.Before)

Example 42 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class SpecExampleConstraintTest method startServer.

@BeforeClass
public static void startServer() {
    _server = new Server();
    _connector = new LocalConnector(_server);
    _server.setConnectors(new Connector[] { _connector });
    ContextHandler _context = new ContextHandler();
    _session = new SessionHandler();
    TestLoginService _loginService = new TestLoginService(TEST_REALM);
    _loginService.putUser("fred", new Password("password"), IdentityService.NO_ROLES);
    _loginService.putUser("harry", new Password("password"), new String[] { "HOMEOWNER" });
    _loginService.putUser("chris", new Password("password"), new String[] { "CONTRACTOR" });
    _loginService.putUser("steven", new Password("password"), new String[] { "SALESCLERK" });
    _context.setContextPath("/ctx");
    _server.setHandler(_context);
    _context.setHandler(_session);
    _server.addBean(_loginService);
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) Password(org.eclipse.jetty.util.security.Password) BeforeClass(org.junit.BeforeClass)

Example 43 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class ComplianceViolations2616Test method startServer.

@BeforeClass
public static void startServer() throws Exception {
    server = new Server();
    HttpConfiguration config = new HttpConfiguration();
    config.setSendServerVersion(false);
    HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(config, HttpCompliance.RFC2616);
    httpConnectionFactory.setRecordHttpComplianceViolations(true);
    connector = new LocalConnector(server, null, null, null, -1, httpConnectionFactory);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.setWelcomeFiles(new String[] { "index.html", "index.jsp", "index.htm" });
    context.addServlet(DumpRequestHeadersServlet.class, "/dump/*");
    context.addFilter(ReportViolationsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    server.setHandler(context);
    server.addConnector(connector);
    server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) LocalConnector(org.eclipse.jetty.server.LocalConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) BeforeClass(org.junit.BeforeClass)

Example 44 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class DispatcherForwardTest method prepare.

public void prepare() throws Exception {
    server = new Server();
    connector = new LocalConnector(server);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(server, "/");
    context.addServlet(new ServletHolder(servlet1), "/one");
    context.addServlet(new ServletHolder(servlet2), "/two");
    server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector)

Example 45 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project jetty.project by eclipse.

the class ErrorPageTest method init.

@Before
public void init() throws Exception {
    _server = new Server();
    _connector = new LocalConnector(_server);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
    _server.addConnector(_connector);
    _server.setHandler(context);
    context.setContextPath("/");
    context.addServlet(DefaultServlet.class, "/");
    context.addServlet(FailServlet.class, "/fail/*");
    context.addServlet(ErrorServlet.class, "/error/*");
    ErrorPageErrorHandler error = new ErrorPageErrorHandler();
    context.setErrorHandler(error);
    error.addErrorPage(599, "/error/599");
    error.addErrorPage(IllegalStateException.class.getCanonicalName(), "/error/TestException");
    error.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE, "/error/GlobalErrorPage");
    _server.start();
    _stackless = new StacklessLogging(ServletHandler.class);
}
Also used : Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Before(org.junit.Before)

Aggregations

LocalConnector (org.eclipse.jetty.server.LocalConnector)47 Server (org.eclipse.jetty.server.Server)43 Before (org.junit.Before)20 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)13 Test (org.junit.Test)12 Matchers.containsString (org.hamcrest.Matchers.containsString)7 BeforeClass (org.junit.BeforeClass)7 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)6 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)4 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)4 Password (org.eclipse.jetty.util.security.Password)4 File (java.io.File)3 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 HandlerList (org.eclipse.jetty.server.handler.HandlerList)3 Path (java.nio.file.Path)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2