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