Search in sources :

Example 1 with LocalConnector

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

the class StatisticsHandlerTest method init.

@Before
public void init() throws Exception {
    _server = new Server();
    _connector = new LocalConnector(_server);
    _statistics = new ConnectionStatistics();
    _connector.addBean(_statistics);
    _server.addConnector(_connector);
    _latchHandler = new LatchHandler();
    _statsHandler = new StatisticsHandler();
    _server.setHandler(_latchHandler);
    _latchHandler.setHandler(_statsHandler);
}
Also used : Server(org.eclipse.jetty.server.Server) ConnectionStatistics(org.eclipse.jetty.io.ConnectionStatistics) LocalConnector(org.eclipse.jetty.server.LocalConnector) Before(org.junit.Before)

Example 2 with LocalConnector

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

the class DataRateLimitedServletTest method init.

@Before
public void init() throws Exception {
    server = new Server();
    connector = new LocalConnector(server);
    connector.getConnectionFactory(HttpConfiguration.ConnectionFactory.class).getHttpConfiguration().setSendServerVersion(false);
    context = new ServletContextHandler();
    context.setContextPath("/context");
    context.setWelcomeFiles(new String[] { "index.html", "index.jsp", "index.htm" });
    File baseResourceDir = testdir.getEmptyPathDir().toFile();
    // Use resolved real path for Windows and OSX
    Path baseResourcePath = baseResourceDir.toPath().toRealPath();
    context.setBaseResource(Resource.newResource(baseResourcePath.toFile()));
    ServletHolder holder = context.addServlet(DataRateLimitedServlet.class, "/stream/*");
    holder.setInitParameter("buffersize", "" + BUFFER);
    holder.setInitParameter("pause", "" + PAUSE);
    server.setHandler(context);
    server.addConnector(connector);
    server.start();
}
Also used : Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) LocalConnector(org.eclipse.jetty.server.LocalConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File) Before(org.junit.Before)

Example 3 with LocalConnector

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

the class ConstraintTest method startServer.

@Before
public void startServer() {
    _server = new Server();
    _connector = new LocalConnector(_server);
    _config = _connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
    _server.setConnectors(new Connector[] { _connector });
    ContextHandler _context = new ContextHandler();
    SessionHandler _session = new SessionHandler();
    TestLoginService _loginService = new TestLoginService(TEST_REALM);
    _loginService.putUser("user0", new Password("password"), new String[] {});
    _loginService.putUser("user", new Password("password"), new String[] { "user" });
    _loginService.putUser("user2", new Password("password"), new String[] { "user" });
    _loginService.putUser("admin", new Password("password"), new String[] { "user", "administrator" });
    _loginService.putUser("user3", new Password("password"), new String[] { "foo" });
    _context.setContextPath("/ctx");
    _server.setHandler(_context);
    _context.setHandler(_session);
    _server.addBean(_loginService);
    _security = new ConstraintSecurityHandler();
    _session.setHandler(_security);
    RequestHandler _handler = new RequestHandler();
    _security.setHandler(_handler);
    _security.setConstraintMappings(getConstraintMappings(), getKnownRoles());
}
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) Before(org.junit.Before)

Example 4 with LocalConnector

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

the class AbstractRuleTestCase method start.

protected void start(final boolean isSecure) throws Exception {
    _connector = new LocalConnector(_server);
    _connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().addCustomizer(new HttpConfiguration.Customizer() {

        @Override
        public void customize(Connector connector, HttpConfiguration channelConfig, Request request) {
            request.setSecure(isSecure);
        }
    });
    _server.setConnectors(new Connector[] { _connector });
    _server.setHandler(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            _request = baseRequest;
            _response = _request.getResponse();
            try {
                _latch.await();
            } catch (InterruptedException e) {
                throw new ServletException(e);
            }
        }
    });
    _server.start();
    _latch = new CountDownLatch(1);
    _connector.executeRequest("GET / HTTP/1.0\nCookie: set=already\n\n");
    while (_response == null) Thread.sleep(1);
}
Also used : LocalConnector(org.eclipse.jetty.server.LocalConnector) Connector(org.eclipse.jetty.server.Connector) LocalConnector(org.eclipse.jetty.server.LocalConnector) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException)

Example 5 with LocalConnector

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

the class ResourceHandlerTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    File dir = MavenTestingUtils.getTargetFile("test-classes/simple");
    File bigger = new File(dir, "bigger.txt");
    File big = new File(dir, "big.txt");
    try (OutputStream out = new FileOutputStream(bigger)) {
        for (int i = 0; i < 100; i++) {
            try (InputStream in = new FileInputStream(big)) {
                IO.copy(in, out);
            }
        }
    }
    bigger.deleteOnExit();
    // determine how the SCM of choice checked out the big.txt EOL
    // we can't just use whatever is the OS default.
    // because, for example, a windows system using git can be configured for EOL handling using
    // local, remote, file lists, patterns, etc, rendering assumptions about the OS EOL choice
    // wrong for unit tests.
    LN = System.getProperty("line.separator");
    try (BufferedReader reader = Files.newBufferedReader(big.toPath(), StandardCharsets.UTF_8)) {
        // a buffer large enough to capture at least 1 EOL
        char[] cbuf = new char[128];
        reader.read(cbuf);
        String sample = new String(cbuf);
        if (sample.contains("\r\n")) {
            LN = "\r\n";
        } else if (sample.contains("\n\r")) {
            LN = "\n\r";
        } else {
            LN = "\n";
        }
    }
    _server = new Server();
    _config = new HttpConfiguration();
    _config.setOutputBufferSize(2048);
    _connector = new ServerConnector(_server, new HttpConnectionFactory(_config));
    _local = new LocalConnector(_server);
    _server.setConnectors(new Connector[] { _connector, _local });
    _resourceHandler = new ResourceHandler();
    _resourceHandler.setResourceBase(MavenTestingUtils.getTargetFile("test-classes/simple").getAbsolutePath());
    _resourceHandler.setWelcomeFiles(new String[] { "welcome.txt" });
    _contextHandler = new ContextHandler("/resource");
    _contextHandler.setHandler(_resourceHandler);
    _server.setHandler(_contextHandler);
    _server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) LocalConnector(org.eclipse.jetty.server.LocalConnector) Matchers.containsString(org.hamcrest.Matchers.containsString) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) FileInputStream(java.io.FileInputStream) ServerConnector(org.eclipse.jetty.server.ServerConnector) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) File(java.io.File) BeforeClass(org.junit.BeforeClass)

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