use of org.eclipse.jetty.server.Connector in project jetty.project by eclipse.
the class DebugHandler method doStart.
/* (non-Javadoc)
* @see org.eclipse.jetty.server.handler.HandlerWrapper#doStart()
*/
@Override
protected void doStart() throws Exception {
if (_out == null)
_out = new RolloverFileOutputStream("./logs/yyyy_mm_dd.debug.log", true);
_print = new PrintStream(_out);
for (Connector connector : getServer().getConnectors()) if (connector instanceof AbstractConnector)
((AbstractConnector) connector).addBean(this, false);
super.doStart();
}
use of org.eclipse.jetty.server.Connector in project jetty.project by eclipse.
the class DoSFilterJMXTest method testDoSFilterJMX.
@Test
public void testDoSFilterJMX() throws Exception {
Server server = new Server();
Connector connector = new ServerConnector(server);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
DoSFilter filter = new DoSFilter();
FilterHolder holder = new FilterHolder(filter);
String name = "dos";
holder.setName(name);
holder.setInitParameter(DoSFilter.MANAGED_ATTR_INIT_PARAM, "true");
context.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST));
context.setInitParameter(ServletContextHandler.MANAGED_ATTRIBUTES, name);
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
MBeanContainer mbeanContainer = new MBeanContainer(mbeanServer);
server.addBean(mbeanContainer);
server.start();
String domain = DoSFilter.class.getPackage().getName();
Set<ObjectName> mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(domain + ":*"), null);
Assert.assertEquals(1, mbeanNames.size());
ObjectName objectName = mbeanNames.iterator().next();
boolean value = (Boolean) mbeanServer.getAttribute(objectName, "enabled");
mbeanServer.setAttribute(objectName, new Attribute("enabled", !value));
Assert.assertEquals(!value, filter.isEnabled());
String whitelist = (String) mbeanServer.getAttribute(objectName, "whitelist");
String address = "127.0.0.1";
Assert.assertFalse(whitelist.contains(address));
boolean result = (Boolean) mbeanServer.invoke(objectName, "addWhitelistAddress", new Object[] { address }, new String[] { String.class.getName() });
Assert.assertTrue(result);
whitelist = (String) mbeanServer.getAttribute(objectName, "whitelist");
Assert.assertTrue(whitelist.contains(address));
result = (Boolean) mbeanServer.invoke(objectName, "removeWhitelistAddress", new Object[] { address }, new String[] { String.class.getName() });
Assert.assertTrue(result);
whitelist = (String) mbeanServer.getAttribute(objectName, "whitelist");
Assert.assertFalse(whitelist.contains(address));
server.stop();
}
use of org.eclipse.jetty.server.Connector in project dropwizard by dropwizard.
the class DefaultServerFactory method buildAdminConnectors.
private List<Connector> buildAdminConnectors(MetricRegistry metricRegistry, Server server) {
// threadpool is shared between all the connectors, so it should be managed by the server instead of the
// individual connectors
final QueuedThreadPool threadPool = new QueuedThreadPool(adminMaxThreads, adminMinThreads);
threadPool.setName("dw-admin");
server.addBean(threadPool);
final List<Connector> connectors = new ArrayList<>();
for (ConnectorFactory factory : adminConnectors) {
final Connector connector = factory.build(server, metricRegistry, "admin", threadPool);
if (connector instanceof ContainerLifeCycle) {
((ContainerLifeCycle) connector).unmanage(threadPool);
}
connectors.add(connector);
}
return connectors;
}
use of org.eclipse.jetty.server.Connector in project dropwizard by dropwizard.
the class DefaultServerFactory method buildRoutingHandler.
private RoutingHandler buildRoutingHandler(MetricRegistry metricRegistry, Server server, Handler applicationHandler, Handler adminHandler) {
final List<Connector> appConnectors = buildAppConnectors(metricRegistry, server);
final List<Connector> adConnectors = buildAdminConnectors(metricRegistry, server);
final Map<Connector, Handler> handlers = new LinkedHashMap<>();
for (Connector connector : appConnectors) {
server.addConnector(connector);
handlers.put(connector, applicationHandler);
}
for (Connector connector : adConnectors) {
server.addConnector(connector);
handlers.put(connector, adminHandler);
}
return new RoutingHandler(handlers);
}
use of org.eclipse.jetty.server.Connector in project dropwizard by dropwizard.
the class SimpleServerFactory method build.
@Override
public Server build(Environment environment) {
// ensures that the environment is configured before the server is built
configure(environment);
printBanner(environment.getName());
final ThreadPool threadPool = createThreadPool(environment.metrics());
final Server server = buildServer(environment.lifecycle(), threadPool);
final Handler applicationHandler = createAppServlet(server, environment.jersey(), environment.getObjectMapper(), environment.getValidator(), environment.getApplicationContext(), environment.getJerseyServletContainer(), environment.metrics());
final Handler adminHandler = createAdminServlet(server, environment.getAdminContext(), environment.metrics(), environment.healthChecks());
final Connector conn = connector.build(server, environment.metrics(), environment.getName(), null);
server.addConnector(conn);
final ContextRoutingHandler routingHandler = new ContextRoutingHandler(ImmutableMap.of(applicationContextPath, applicationHandler, adminContextPath, adminHandler));
final Handler gzipHandler = buildGzipHandler(routingHandler);
server.setHandler(addStatsHandler(addRequestLog(server, gzipHandler, environment.getName())));
return server;
}
Aggregations