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