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);
}
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();
}
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());
}
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);
}
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();
}
Aggregations