Search in sources :

Example 6 with NetworkConnector

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;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NetworkConnector(org.eclipse.jetty.server.NetworkConnector)

Example 7 with NetworkConnector

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();
}
Also used : NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Test(org.junit.Test)

Example 8 with NetworkConnector

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();
}
Also used : NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Connector(org.eclipse.jetty.server.Connector) NetworkConnector(org.eclipse.jetty.server.NetworkConnector)

Example 9 with NetworkConnector

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();
}
Also used : NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Connector(org.eclipse.jetty.server.Connector) MultipartConfigElement(jakarta.servlet.MultipartConfigElement) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 10 with NetworkConnector

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();
}
Also used : NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) WebProxyConfig(code.satyagraha.gfm.support.api.WebProxyConfig) DefaultResourceConfig(com.sun.jersey.api.core.DefaultResourceConfig) Config(code.satyagraha.gfm.support.api.Config) ArrayList(java.util.ArrayList) WebServiceClient(code.satyagraha.gfm.support.api.WebServiceClient) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) ClientConnManagerDefault(code.satyagraha.gfm.support.impl.conn.ClientConnManagerDefault) WebProxyConfig(code.satyagraha.gfm.support.api.WebProxyConfig) Random(java.util.Random) ExecutorService(java.util.concurrent.ExecutorService) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Future(java.util.concurrent.Future) WebServiceClientDefault(code.satyagraha.gfm.support.impl.WebServiceClientDefault) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) Test(org.junit.Test)

Aggregations

NetworkConnector (org.eclipse.jetty.server.NetworkConnector)20 Server (org.eclipse.jetty.server.Server)9 Test (org.junit.Test)8 Connector (org.eclipse.jetty.server.Connector)7 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)6 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)6 URI (java.net.URI)5 IOException (java.io.IOException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpClient (org.eclipse.jetty.client.HttpClient)3 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)3 Request (org.eclipse.jetty.client.api.Request)3 MultipartConfigElement (jakarta.servlet.MultipartConfigElement)2 File (java.io.File)2 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 MessageDigest (java.security.MessageDigest)2 AuthenticationStore (org.eclipse.jetty.client.api.AuthenticationStore)2 DigestAuthentication (org.eclipse.jetty.client.util.DigestAuthentication)2 HashLoginService (org.eclipse.jetty.security.HashLoginService)2