Java Code Examples for org.eclipse.jetty.server.Connector#getConnectionFactories()

The following examples show how to use org.eclipse.jetty.server.Connector#getConnectionFactories() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThriftOverHttpClientTServletIntegrationTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
private static Server startHttp1() throws Exception {
    final Server server = new Server(0);

    final ServletHandler handler = new ServletHandler();
    handler.addServletWithMapping(newServletHolder(thriftServlet), TSERVLET_PATH);
    handler.addServletWithMapping(newServletHolder(rootServlet), "/");
    handler.addFilterWithMapping(new FilterHolder(new ConnectionCloseFilter()), "/*",
                                 EnumSet.of(DispatcherType.REQUEST));

    server.setHandler(handler);

    for (Connector c : server.getConnectors()) {
        for (ConnectionFactory f : c.getConnectionFactories()) {
            for (String p : f.getProtocols()) {
                if (p.startsWith("h2c")) {
                    fail("Attempted to create a Jetty server without HTTP/2 support, but failed: " +
                         f.getProtocols());
                }
            }
        }
    }

    server.start();
    return server;
}
 
Example 2
Source File: SlackAppServer.java    From java-slack-sdk with MIT License 5 votes vote down vote up
private static void removeServerHeader(Server server) {
    // https://stackoverflow.com/a/15675075/840108
    for (Connector y : server.getConnectors()) {
        for (ConnectionFactory x : y.getConnectionFactories()) {
            if (x instanceof HttpConnectionFactory) {
                ((HttpConnectionFactory) x).getHttpConfiguration().setSendServerVersion(false);
            }
        }
    }
}
 
Example 3
Source File: JettyUtil.java    From warp10-platform with Apache License 2.0 5 votes vote down vote up
public static void setSendServerVersion(Server server, boolean send) {
  //
  // Remove display of Server header
  // @see http://stackoverflow.com/questions/15652902/remove-the-http-server-header-in-jetty-9
  //
  
  for(Connector y : server.getConnectors()) {
    for(ConnectionFactory x  : y.getConnectionFactories()) {
      if(x instanceof HttpConnectionFactory) {
        ((HttpConnectionFactory)x).getHttpConfiguration().setSendServerVersion(send);
      }
    }
  }    
}
 
Example 4
Source File: WebServerTask.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void setSSLContext() {
  for (Connector connector : server.getConnectors()) {
    for (ConnectionFactory connectionFactory : connector.getConnectionFactories()) {
      if (connectionFactory instanceof SslConnectionFactory) {
        runtimeInfo.setSSLContext(((SslConnectionFactory) connectionFactory).getSslContextFactory().getSslContext());
      }
    }
  }
  if (runtimeInfo.getSSLContext() == null) {
    throw new IllegalStateException("Unexpected error, SSLContext is not set for https enabled server");
  }
}
 
Example 5
Source File: JettyHTTPServerEngineFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testMakeSureJetty9ConnectorConfigured() throws Exception {


    URL config = getClass().getResource("server-engine-factory-jetty9-connector.xml");

    bus = new SpringBusFactory().createBus(config, true);

    JettyHTTPServerEngineFactory factory =
        bus.getExtension(JettyHTTPServerEngineFactory.class);

    assertNotNull("EngineFactory is not configured.", factory);

    JettyHTTPServerEngine engine = null;
    engine = factory.createJettyHTTPServerEngine(1234, "http");

    assertNotNull("Engine is not available.", engine);
    assertEquals(1234, engine.getPort());
    assertEquals("Not http", "http", engine.getProtocol());
    Connector connector = engine.getConnector();
    Collection<ConnectionFactory> connectionFactories = connector.getConnectionFactories();
    assertEquals("Has one HttpConnectionFactory", 1, connectionFactories.size());
    ConnectionFactory connectionFactory = connectionFactories.iterator().next();
    assertTrue(connectionFactory instanceof HttpConnectionFactory);
    HttpConfiguration httpConfiguration = ((HttpConnectionFactory)connectionFactory).getHttpConfiguration();
    assertEquals("Has one ForwardedRequestCustomizer", 1, httpConfiguration.getCustomizers().size());
    assertTrue(httpConfiguration.getCustomizers().iterator().next()
               instanceof org.eclipse.jetty.server.ForwardedRequestCustomizer);
}