use of org.eclipse.jetty.server.NetworkConnector in project knox by apache.
the class GatewayServer method getAddresses.
public InetSocketAddress[] getAddresses() {
InetSocketAddress[] addresses = new InetSocketAddress[jetty.getConnectors().length];
for (int i = 0, n = addresses.length; i < n; i++) {
NetworkConnector connector = (NetworkConnector) jetty.getConnectors()[i];
String host = connector.getHost();
if (host == null) {
addresses[i] = new InetSocketAddress(connector.getLocalPort());
} else {
addresses[i] = new InetSocketAddress(host, connector.getLocalPort());
}
}
return addresses;
}
use of org.eclipse.jetty.server.NetworkConnector in project samza by apache.
the class TestSamzaRestService method testStartShouldStartTheMetricsReportersAndServer.
@Test
public void testStartShouldStartTheMetricsReportersAndServer() throws Exception {
NetworkConnector connector = Mockito.mock(NetworkConnector.class);
int testServerPort = 100;
Mockito.doReturn(testServerPort).when(connector).getPort();
Mockito.when(server.getConnectors()).thenReturn(new NetworkConnector[] { connector });
Mockito.doNothing().when(server).start();
samzaRestService.start();
Mockito.verify(metricsReporter).start();
Mockito.verify(metricsReporter).register("SamzaRest", metricsRegistry);
Mockito.verify(server).start();
}
use of org.eclipse.jetty.server.NetworkConnector in project spring-framework by spring-projects.
the class JettyWebSocketTestServer method start.
@Override
public void start() throws Exception {
this.jettyServer.start();
this.contextHandler.start();
Connector[] connectors = jettyServer.getConnectors();
NetworkConnector connector = (NetworkConnector) connectors[0];
this.port = connector.getLocalPort();
}
use of org.eclipse.jetty.server.NetworkConnector in project spring-framework by spring-projects.
the class RequestPartIntegrationTests method startServer.
@BeforeAll
public static void startServer() throws Exception {
// Let server pick its own random, available port.
server = new Server(0);
ServletContextHandler handler = new ServletContextHandler();
handler.setContextPath("/");
ServletHolder standardResolverServlet = new ServletHolder(DispatcherServlet.class);
standardResolverServlet.setInitParameter("contextConfigLocation", StandardMultipartResolverTestConfig.class.getName());
standardResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
standardResolverServlet.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
handler.addServlet(standardResolverServlet, "/standard-resolver/*");
server.setHandler(handler);
server.start();
Connector[] connectors = server.getConnectors();
NetworkConnector connector = (NetworkConnector) connectors[0];
baseUrl = "http://localhost:" + connector.getLocalPort();
}
use of org.eclipse.jetty.server.NetworkConnector in project gfm_viewer by satyagraha.
the class TestWebServiceClientDefault method shouldHandleSimpleRequest.
@Test
public void shouldHandleSimpleRequest() throws Exception {
ServletHolder sh = new ServletHolder(ServletContainer.class);
sh.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS, StubResourceConfig.class.getName());
sh.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true");
Server server = new Server(0);
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
context.addServlet(sh, "/*");
server.start();
Connector[] connectors = server.getConnectors();
int port = ((NetworkConnector) connectors[0]).getLocalPort();
LOGGER.info("server port: " + port);
Config config = mock(Config.class);
String apiUrl = "http://localhost:" + port;
given(config.getApiUrl()).willReturn(apiUrl);
WebProxyConfig webProxyConfig = mock(WebProxyConfig.class);
SSLSocketFactory sslSocketFactory = mock(SSLSocketFactory.class);
ClientConnectionManager connectionManager = new ClientConnManagerDefault(sslSocketFactory);
WebServiceClient webServiceClient = new WebServiceClientDefault(config, webProxyConfig, connectionManager);
Random random = new Random();
// construct the tasks to run
int threadCount = 50;
List<WebServiceClientCallable> tasks = new ArrayList<WebServiceClientCallable>();
for (int threadIndex = 0; threadIndex < threadCount; threadIndex++) {
String mdText = RandomStringUtils.randomAlphanumeric(random.nextInt(100));
WebServiceClientCallable task = new WebServiceClientCallable(webServiceClient, mdText);
tasks.add(task);
}
// run the tasks
ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
List<Future<String>> futures = executorService.invokeAll(tasks, 10, TimeUnit.SECONDS);
// verify results
assertThat(futures, hasSize(threadCount));
for (int threadIndex = 0; threadIndex < threadCount; threadIndex++) {
String result = futures.get(threadIndex).get();
WebServiceClientCallable task = tasks.get(threadIndex);
assertThat(result, is(performSampleTransformation(task.mdText)));
}
server.stop();
}
Aggregations