Search in sources :

Example 41 with Connector

use of org.eclipse.jetty.server.Connector in project athenz by yahoo.

the class AthenzJettyContainerTest method initContainerOnlyHTTPSPort.

@Test
public void initContainerOnlyHTTPSPort() {
    System.setProperty(AthenzConsts.ATHENZ_PROP_HOME, "/tmp/ATHENZ_server");
    System.setProperty(AthenzConsts.ATHENZ_PROP_HTTP_PORT, "0");
    System.setProperty(AthenzConsts.ATHENZ_PROP_HTTPS_PORT, "4443");
    System.setProperty("yahoo.zms.debug.user_authority", "true");
    AthenzJettyContainer container = AthenzJettyContainer.createJettyContainer();
    assertNotNull(container);
    Server server = container.getServer();
    Connector[] connectors = server.getConnectors();
    assertEquals(connectors.length, 1);
    assertTrue(connectors[0].getProtocols().contains("http/1.1"));
    assertTrue(connectors[0].getProtocols().contains("ssl"));
}
Also used : Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) Test(org.testng.annotations.Test)

Example 42 with Connector

use of org.eclipse.jetty.server.Connector in project athenz by yahoo.

the class AthenzJettyContainerTest method initContainerInvalidHTTPPort.

@Test
public void initContainerInvalidHTTPPort() {
    System.setProperty(AthenzConsts.ATHENZ_PROP_HOME, "/tmp/ATHENZ_server");
    System.setProperty(AthenzConsts.ATHENZ_PROP_HTTP_PORT, "-10");
    System.setProperty(AthenzConsts.ATHENZ_PROP_HTTPS_PORT, "4443");
    AthenzJettyContainer container = AthenzJettyContainer.createJettyContainer();
    assertNotNull(container);
    Server server = container.getServer();
    Connector[] connectors = server.getConnectors();
    assertEquals(connectors.length, 2);
    assertTrue(connectors[0].getProtocols().contains("http/1.1"));
    assertTrue(connectors[1].getProtocols().contains("http/1.1"));
    assertTrue(connectors[1].getProtocols().contains("ssl"));
}
Also used : Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) Test(org.testng.annotations.Test)

Example 43 with Connector

use of org.eclipse.jetty.server.Connector in project athenz by yahoo.

the class AthenzJettyContainerTest method initContainerValidPorts.

@Test
public void initContainerValidPorts() {
    System.setProperty(AthenzConsts.ATHENZ_PROP_HOME, "/tmp/ATHENZ_server");
    System.setProperty(AthenzConsts.ATHENZ_PROP_HTTP_PORT, "4080");
    System.setProperty(AthenzConsts.ATHENZ_PROP_HTTPS_PORT, "4443");
    AthenzJettyContainer container = AthenzJettyContainer.createJettyContainer();
    assertNotNull(container);
    Server server = container.getServer();
    Connector[] connectors = server.getConnectors();
    assertEquals(connectors.length, 2);
    assertTrue(connectors[0].getProtocols().contains("http/1.1"));
    assertTrue(connectors[1].getProtocols().contains("http/1.1"));
    assertTrue(connectors[1].getProtocols().contains("ssl"));
}
Also used : Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) Test(org.testng.annotations.Test)

Example 44 with Connector

use of org.eclipse.jetty.server.Connector in project camel by apache.

the class JettyHttpComponent method connect.

/**
     * Connects the URL specified on the endpoint to the specified processor.
     */
@Override
public void connect(HttpConsumer consumer) throws Exception {
    // Make sure that there is a connector for the requested endpoint.
    JettyHttpEndpoint endpoint = (JettyHttpEndpoint) consumer.getEndpoint();
    String connectorKey = getConnectorKey(endpoint);
    synchronized (CONNECTORS) {
        ConnectorRef connectorRef = CONNECTORS.get(connectorKey);
        if (connectorRef == null) {
            Server server = createServer();
            Connector connector = getConnector(server, endpoint);
            if ("localhost".equalsIgnoreCase(endpoint.getHttpUri().getHost())) {
                LOG.warn("You use localhost interface! It means that no external connections will be available." + " Don't you want to use 0.0.0.0 instead (all network interfaces)? " + endpoint);
            }
            if (endpoint.isEnableJmx()) {
                enableJmx(server);
            }
            server.addConnector(connector);
            connectorRef = new ConnectorRef(server, connector, createServletForConnector(server, connector, endpoint.getHandlers(), endpoint));
            // must enable session before we start
            if (endpoint.isSessionSupport()) {
                enableSessionSupport(connectorRef.server, connectorKey);
            }
            connectorRef.server.start();
            CONNECTORS.put(connectorKey, connectorRef);
        } else {
            if (endpoint.getHandlers() != null && !endpoint.getHandlers().isEmpty()) {
                // As the server is started, we need to stop the server for a while to add the new handler
                connectorRef.server.stop();
                addJettyHandlers(connectorRef.server, endpoint.getHandlers());
                connectorRef.server.start();
            }
            // ref track the connector
            connectorRef.increment();
        }
        // check the session support
        if (endpoint.isSessionSupport()) {
            enableSessionSupport(connectorRef.server, connectorKey);
        }
        if (endpoint.isEnableMultipartFilter()) {
            enableMultipartFilter(endpoint, connectorRef.server, connectorKey);
        }
        if (endpoint.getFilters() != null && endpoint.getFilters().size() > 0) {
            setFilters(endpoint, connectorRef.server, connectorKey);
        }
        connectorRef.servlet.connect(consumer);
    }
}
Also used : AbstractConnector(org.eclipse.jetty.server.AbstractConnector) Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) MBeanServer(javax.management.MBeanServer)

Example 45 with Connector

use of org.eclipse.jetty.server.Connector in project camel by apache.

the class ExplicitHttpsRouteTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() throws URISyntaxException {
            // START SNIPPET: e1
            // create SSL select channel connectors for port 9080 and 9090
            Map<Integer, Connector> connectors = new HashMap<Integer, Connector>();
            connectors.put(port1, createSslSocketConnector(port1));
            connectors.put(port2, createSslSocketConnector(port2));
            JettyHttpComponent jetty = getContext().getComponent("jetty", JettyHttpComponent.class);
            jetty.setSslSocketConnectors(connectors);
            // END SNIPPET: e1
            from("jetty:https://localhost:" + port1 + "/test").to("mock:a");
            Processor proc = new Processor() {

                public void process(Exchange exchange) throws Exception {
                    exchange.getOut().setBody("<b>Hello World</b>");
                }
            };
            from("jetty:https://localhost:" + port1 + "/hello").process(proc);
            from("jetty:https://localhost:" + port2 + "/test").to("mock:b");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Connector(org.eclipse.jetty.server.Connector) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) HashMap(java.util.HashMap)

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