Search in sources :

Example 51 with Connector

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();
}
Also used : PrintStream(java.io.PrintStream) AbstractConnector(org.eclipse.jetty.server.AbstractConnector) Connector(org.eclipse.jetty.server.Connector) RolloverFileOutputStream(org.eclipse.jetty.util.RolloverFileOutputStream) AbstractConnector(org.eclipse.jetty.server.AbstractConnector)

Example 52 with Connector

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();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) MBeanServer(javax.management.MBeanServer) Server(org.eclipse.jetty.server.Server) Attribute(javax.management.Attribute) ObjectName(javax.management.ObjectName) ServerConnector(org.eclipse.jetty.server.ServerConnector) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 53 with Connector

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;
}
Also used : Connector(org.eclipse.jetty.server.Connector) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) ConnectorFactory(io.dropwizard.jetty.ConnectorFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ArrayList(java.util.ArrayList) ContainerLifeCycle(org.eclipse.jetty.util.component.ContainerLifeCycle)

Example 54 with Connector

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);
}
Also used : Connector(org.eclipse.jetty.server.Connector) RoutingHandler(io.dropwizard.jetty.RoutingHandler) RoutingHandler(io.dropwizard.jetty.RoutingHandler) Handler(org.eclipse.jetty.server.Handler) LinkedHashMap(java.util.LinkedHashMap)

Example 55 with Connector

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;
}
Also used : Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) ContextRoutingHandler(io.dropwizard.jetty.ContextRoutingHandler) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) Handler(org.eclipse.jetty.server.Handler) ContextRoutingHandler(io.dropwizard.jetty.ContextRoutingHandler)

Aggregations

Connector (org.eclipse.jetty.server.Connector)79 Server (org.eclipse.jetty.server.Server)41 ServerConnector (org.eclipse.jetty.server.ServerConnector)25 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)22 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)17 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)15 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)13 IOException (java.io.IOException)12 NetworkConnector (org.eclipse.jetty.server.NetworkConnector)12 Test (org.junit.Test)11 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)10 SelectChannelConnector (org.eclipse.jetty.server.nio.SelectChannelConnector)8 Test (org.testng.annotations.Test)8 Handler (org.eclipse.jetty.server.Handler)7 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)6 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)6 ServletException (javax.servlet.ServletException)5