Search in sources :

Example 81 with Connector

use of org.eclipse.jetty.server.Connector in project meteo by pierre.

the class JettyServer method start.

public void start(final Injector injector) throws Exception {
    final long startTime = System.currentTimeMillis();
    server = new Server();
    // Setup JMX
    final MBeanContainer mbContainer = new MBeanContainer(mbeanServer);
    server.getContainer().addEventListener(mbContainer);
    server.addBean(mbContainer);
    mbContainer.addBean(Log.getLog());
    final Connector connector = new SelectChannelConnector();
    connector.setStatsOn(config.isJettyStatsOn());
    connector.setHost(config.getLocalIp());
    connector.setPort(config.getLocalPort());
    server.addConnector(connector);
    server.setStopAtShutdown(true);
    final ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.addEventListener(new GuiceServletContextListener() {

        @Override
        protected Injector getInjector() {
            return injector;
        }
    });
    // Jersey insists on using java.util.logging (JUL)
    final EventListener listener = new SetupJULBridge();
    context.addEventListener(listener);
    // Make sure Guice filter all requests
    final FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
    context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
    // Backend servlet for Guice - never used
    final ServletHolder sh = new ServletHolder(DefaultServlet.class);
    context.addServlet(sh, "/*");
    server.start();
    final long secondsToStart = (System.currentTimeMillis() - startTime) / 1000;
    log.info(String.format("Jetty server started in %d:%02d", secondsToStart / 60, secondsToStart % 60));
}
Also used : Connector(org.eclipse.jetty.server.Connector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) MBeanServer(javax.management.MBeanServer) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Injector(com.google.inject.Injector) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) EventListener(java.util.EventListener) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) GuiceServletContextListener(com.google.inject.servlet.GuiceServletContextListener)

Example 82 with Connector

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

the class AthenzJettyContainerTest method testInitContainerOptionalFeatures.

@Test
public void testInitContainerOptionalFeatures() {
    System.setProperty(AthenzConsts.ATHENZ_PROP_HTTP_PORT, "4080");
    System.setProperty(AthenzConsts.ATHENZ_PROP_HTTPS_PORT, "4443");
    System.setProperty(AthenzConsts.ATHENZ_PROP_DEBUG, "true");
    System.setProperty(AthenzConsts.ATHENZ_PROP_GZIP_SUPPORT, "true");
    System.setProperty(AthenzConsts.ATHENZ_PROP_HEALTH_CHECK_URI_LIST, "/status.html");
    System.setProperty(AthenzConsts.ATHENZ_PROP_PROXY_PROTOCOL, "true");
    System.setProperty(AthenzConsts.ATHENZ_PROP_LISTEN_HOST, "127.0.0.1");
    System.setProperty(AthenzConsts.ATHENZ_PROP_EXCLUDED_PROTOCOLS, "");
    System.setProperty(AthenzConsts.ATHENZ_PROP_KEEP_ALIVE, "false");
    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 83 with Connector

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

the class AthenzJettyContainerTest method testInitContainerValidPorts.

@Test
public void testInitContainerValidPorts() {
    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 84 with Connector

use of org.eclipse.jetty.server.Connector in project apex-malhar by apache.

the class PubSubWebSocketOperatorTest method testPubSubWebSocket.

@Test
@SuppressWarnings("SleepWhileInLoop")
public void testPubSubWebSocket() throws Exception {
    Server server = new Server(0);
    SamplePubSubWebSocketServlet servlet = new SamplePubSubWebSocketServlet();
    ServletHolder sh = new ServletHolder(servlet);
    ServletContextHandler contextHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    contextHandler.addServlet(sh, "/pubsub");
    contextHandler.addServlet(sh, "/*");
    server.start();
    Connector[] connector = server.getConnectors();
    URI uri = PubSubHelper.getURI("localhost:" + connector[0].getLocalPort());
    PubSubWebSocketOutputOperator<Object> outputOperator = new PubSubWebSocketOutputOperator<Object>();
    outputOperator.setUri(uri);
    outputOperator.setTopic("testTopic");
    PubSubWebSocketInputOperator<Object> inputOperator = new PubSubWebSocketInputOperator<Object>();
    inputOperator.setUri(uri);
    inputOperator.setTopic("testTopic");
    CollectorTestSink<Object> sink = new CollectorTestSink<Object>();
    inputOperator.outputPort.setSink(sink);
    inputOperator.setup(null);
    outputOperator.setup(null);
    inputOperator.activate(null);
    long timeout = System.currentTimeMillis() + 3000;
    while (!servlet.hasSubscriber()) {
        Thread.sleep(10);
        if (System.currentTimeMillis() > timeout) {
            throw new TimeoutException("No subscribers connected after 3 seconds");
        }
    }
    inputOperator.beginWindow(1000);
    outputOperator.beginWindow(1000);
    Map<String, String> data = new HashMap<String, String>();
    data.put("hello", "world");
    outputOperator.input.process(data);
    String stringData = "StringMessage";
    outputOperator.input.process(stringData);
    int timeoutMillis = 2000;
    while (sink.collectedTuples.size() < 2 && timeoutMillis > 0) {
        inputOperator.emitTuples();
        timeoutMillis -= 20;
        Thread.sleep(20);
    }
    outputOperator.endWindow();
    inputOperator.endWindow();
    Assert.assertTrue("tuples emitted", sink.collectedTuples.size() > 1);
    @SuppressWarnings("unchecked") Map<String, String> tuple = (Map<String, String>) sink.collectedTuples.get(0);
    Assert.assertEquals("Expects {\"hello\":\"world\"} as data", "world", tuple.get("hello"));
    String stringResult = (String) sink.collectedTuples.get(1);
    Assert.assertEquals("Expects {\"hello\":\"world\"} as data", stringData, stringResult);
    inputOperator.deactivate();
    outputOperator.teardown();
    inputOperator.teardown();
    server.stop();
}
Also used : Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) HashMap(java.util.HashMap) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) SamplePubSubWebSocketServlet(org.apache.apex.malhar.lib.helper.SamplePubSubWebSocketServlet) URI(java.net.URI) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) HashMap(java.util.HashMap) Map(java.util.Map) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 85 with Connector

use of org.eclipse.jetty.server.Connector in project apex-malhar by apache.

the class ApplicationTest method testGetApplication.

/**
 * Test of getApplication method, of class Application.
 */
@Test
public void testGetApplication() throws Exception {
    Configuration conf = new Configuration(false);
    conf.addResource("dt-site-mobile.xml");
    Server server = new Server(0);
    Servlet servlet = new SamplePubSubWebSocketServlet();
    ServletHolder sh = new ServletHolder(servlet);
    ServletContextHandler contextHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    contextHandler.addServlet(sh, "/pubsub");
    contextHandler.addServlet(sh, "/*");
    server.start();
    Connector[] connector = server.getConnectors();
    conf.set("dt.attr.GATEWAY_CONNECT_ADDRESS", "localhost:" + connector[0].getLocalPort());
    URI uri = PubSubHelper.getURI("localhost:" + connector[0].getLocalPort());
    PubSubWebSocketOutputOperator<Object> outputOperator = new PubSubWebSocketOutputOperator<Object>();
    outputOperator.setUri(uri);
    outputOperator.setTopic(conf.get("dt.application.MobileExample.operator.QueryLocation.topic"));
    PubSubWebSocketInputOperator<Map<String, String>> inputOperator = new PubSubWebSocketInputOperator<Map<String, String>>();
    inputOperator.setUri(uri);
    inputOperator.setTopic(conf.get("dt.application.MobileExample.operator.LocationResults.topic"));
    CollectorTestSink<Object> sink = new CollectorTestSink<Object>();
    inputOperator.outputPort.setSink(sink);
    Map<String, String> data = new HashMap<String, String>();
    data.put("command", "add");
    data.put("phone", "5559990");
    Application app = new Application();
    LocalMode lma = LocalMode.newInstance();
    lma.prepareDAG(app, conf);
    LocalMode.Controller lc = lma.getController();
    lc.setHeartbeatMonitoringEnabled(false);
    lc.runAsync();
    Thread.sleep(5000);
    inputOperator.setup(null);
    outputOperator.setup(null);
    inputOperator.activate(null);
    outputOperator.beginWindow(0);
    outputOperator.input.process(data);
    outputOperator.endWindow();
    inputOperator.beginWindow(0);
    int timeoutMillis = 5000;
    while (sink.collectedTuples.size() < 5 && timeoutMillis > 0) {
        inputOperator.emitTuples();
        timeoutMillis -= 20;
        Thread.sleep(20);
    }
    inputOperator.endWindow();
    lc.shutdown();
    inputOperator.teardown();
    outputOperator.teardown();
    server.stop();
    Assert.assertTrue("size of output is 5 ", sink.collectedTuples.size() == 5);
    for (Object obj : sink.collectedTuples) {
        Assert.assertEquals("Expected phone number", "5559990", ((Map<String, String>) obj).get("phone"));
    }
}
Also used : PubSubWebSocketOutputOperator(org.apache.apex.malhar.lib.io.PubSubWebSocketOutputOperator) Connector(org.eclipse.jetty.server.Connector) Configuration(org.apache.hadoop.conf.Configuration) Server(org.eclipse.jetty.server.Server) HashMap(java.util.HashMap) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) SamplePubSubWebSocketServlet(org.apache.apex.malhar.lib.helper.SamplePubSubWebSocketServlet) URI(java.net.URI) PubSubWebSocketInputOperator(org.apache.apex.malhar.lib.io.PubSubWebSocketInputOperator) LocalMode(com.datatorrent.api.LocalMode) Servlet(javax.servlet.Servlet) SamplePubSubWebSocketServlet(org.apache.apex.malhar.lib.helper.SamplePubSubWebSocketServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) HashMap(java.util.HashMap) Map(java.util.Map) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

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