Search in sources :

Example 91 with Connector

use of org.eclipse.jetty.server.Connector in project pom-manipulation-ext by release-engineering.

the class JettyHttpServer method createAndStartJetty.

private Server createAndStartJetty(Integer port) {
    Server jetty = new Server();
    Connector conn = new SelectChannelConnector();
    conn.setHost("127.0.0.1");
    conn.setPort(this.port);
    jetty.addConnector(conn);
    jetty.setHandler(handler);
    try {
        jetty.start();
    } catch (Exception e) {
        throw new ServerSetupException("Error starting jetty on port " + port, e);
    }
    return jetty;
}
Also used : Connector(org.eclipse.jetty.server.Connector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) ServerSetupException(org.commonjava.maven.ext.io.server.exception.ServerSetupException) Server(org.eclipse.jetty.server.Server) ServerInternalException(org.commonjava.maven.ext.io.server.exception.ServerInternalException) ServerSetupException(org.commonjava.maven.ext.io.server.exception.ServerSetupException)

Example 92 with Connector

use of org.eclipse.jetty.server.Connector in project micrometer by micrometer-metrics.

the class JettySslHandshakeMetricsTest method namedConnectorTagAdded.

@Test
void namedConnectorTagAdded() {
    Connector connector = mock(Connector.class);
    when(connector.getName()).thenReturn("my-connector");
    new JettySslHandshakeMetrics(registry, connector, tags);
    assertThatCode(() -> registry.get("jetty.ssl.handshakes").tags("id", "0", "protocol", "unknown", "ciphersuite", "unknown", "result", "failed", "connector.name", "my-connector").counter()).doesNotThrowAnyException();
}
Also used : Connector(org.eclipse.jetty.server.Connector) Test(org.junit.jupiter.api.Test)

Example 93 with Connector

use of org.eclipse.jetty.server.Connector in project micrometer by micrometer-metrics.

the class JettySslHandshakeMetricsTest method connectorTagAdded.

@Test
void connectorTagAdded() {
    Connector connector = mock(Connector.class);
    new JettySslHandshakeMetrics(registry, connector, tags);
    assertThatCode(() -> registry.get("jetty.ssl.handshakes").tags("id", "0", "protocol", "unknown", "ciphersuite", "unknown", "result", "failed", "connector.name", "unnamed").counter()).doesNotThrowAnyException();
}
Also used : Connector(org.eclipse.jetty.server.Connector) Test(org.junit.jupiter.api.Test)

Example 94 with Connector

use of org.eclipse.jetty.server.Connector in project spark by perwendel.

the class EmbeddedJettyServer method ignite.

/**
 * {@inheritDoc}
 */
@Override
public int ignite(String host, int port, SslStores sslStores, int maxThreads, int minThreads, int threadIdleTimeoutMillis) throws Exception {
    boolean hasCustomizedConnectors = false;
    if (port == 0) {
        try (ServerSocket s = new ServerSocket(0)) {
            port = s.getLocalPort();
        } catch (IOException e) {
            logger.error("Could not get first available port (port set to 0), using default: {}", SPARK_DEFAULT_PORT);
            port = SPARK_DEFAULT_PORT;
        }
    }
    // Create instance of jetty server with either default or supplied queued thread pool
    if (threadPool == null) {
        server = serverFactory.create(maxThreads, minThreads, threadIdleTimeoutMillis);
    } else {
        server = serverFactory.create(threadPool);
    }
    ServerConnector connector;
    if (sslStores == null) {
        connector = SocketConnectorFactory.createSocketConnector(server, host, port, trustForwardHeaders);
    } else {
        connector = SocketConnectorFactory.createSecureSocketConnector(server, host, port, sslStores, trustForwardHeaders);
    }
    Connector[] previousConnectors = server.getConnectors();
    server = connector.getServer();
    if (previousConnectors.length != 0) {
        server.setConnectors(previousConnectors);
        hasCustomizedConnectors = true;
    } else {
        server.setConnectors(new Connector[] { connector });
    }
    ServletContextHandler webSocketServletContextHandler = WebSocketServletContextHandlerFactory.create(webSocketHandlers, webSocketIdleTimeoutMillis);
    // Handle web socket routes
    if (webSocketServletContextHandler == null) {
        server.setHandler(handler);
    } else {
        List<Handler> handlersInList = new ArrayList<>();
        handlersInList.add(handler);
        // WebSocket handler must be the last one
        if (webSocketServletContextHandler != null) {
            handlersInList.add(webSocketServletContextHandler);
        }
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(handlersInList.toArray(new Handler[handlersInList.size()]));
        server.setHandler(handlers);
    }
    logger.info("== {} has ignited ...", NAME);
    if (hasCustomizedConnectors) {
        logger.info(">> Listening on Custom Server ports!");
    } else {
        logger.info(">> Listening on {}:{}", host, port);
    }
    server.start();
    return port;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HandlerList(org.eclipse.jetty.server.handler.HandlerList) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) ArrayList(java.util.ArrayList) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 95 with Connector

use of org.eclipse.jetty.server.Connector in project metrics by dropwizard.

the class ExampleServer method main.

public static void main(String[] args) throws Exception {
    COUNTER_1.inc();
    COUNTER_2.inc();
    final ThreadPool threadPool = new InstrumentedQueuedThreadPool(REGISTRY);
    final Server server = new Server(threadPool);
    final Connector connector = new ServerConnector(server, new InstrumentedConnectionFactory(new HttpConnectionFactory(), REGISTRY.timer("http.connection")));
    server.addConnector(connector);
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/initial");
    context.setAttribute(MetricsServlet.METRICS_REGISTRY, REGISTRY);
    context.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, new HealthCheckRegistry());
    final ServletHolder holder = new ServletHolder(new AdminServlet());
    context.addServlet(holder, "/dingo/*");
    final InstrumentedHandler handler = new InstrumentedHandler(REGISTRY);
    handler.setHandler(context);
    server.setHandler(handler);
    server.start();
    server.join();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) InstrumentedHandler(io.dropwizard.metrics.jetty11.InstrumentedHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) InstrumentedQueuedThreadPool(io.dropwizard.metrics.jetty11.InstrumentedQueuedThreadPool) AdminServlet(io.dropwizard.metrics.servlets.AdminServlet) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) InstrumentedQueuedThreadPool(io.dropwizard.metrics.jetty11.InstrumentedQueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) InstrumentedConnectionFactory(io.dropwizard.metrics.jetty11.InstrumentedConnectionFactory)

Aggregations

Connector (org.eclipse.jetty.server.Connector)228 Server (org.eclipse.jetty.server.Server)110 ServerConnector (org.eclipse.jetty.server.ServerConnector)103 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)51 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)42 IOException (java.io.IOException)40 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)37 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)34 NetworkConnector (org.eclipse.jetty.server.NetworkConnector)34 ArrayList (java.util.ArrayList)33 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)24 Handler (org.eclipse.jetty.server.Handler)23 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)23 Test (org.testng.annotations.Test)23 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)19 Test (org.junit.jupiter.api.Test)19 InetAddress (java.net.InetAddress)18 File (java.io.File)16 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)16 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)16