Search in sources :

Example 16 with NetworkConnector

use of org.eclipse.jetty.server.NetworkConnector in project spring-boot by spring-projects.

the class JettyWebServer method start.

@Override
public void start() throws WebServerException {
    synchronized (this.monitor) {
        if (this.started) {
            return;
        }
        this.server.setConnectors(this.connectors);
        if (!this.autoStart) {
            return;
        }
        try {
            this.server.start();
            for (Handler handler : this.server.getHandlers()) {
                handleDeferredInitialize(handler);
            }
            Connector[] connectors = this.server.getConnectors();
            for (Connector connector : connectors) {
                try {
                    connector.start();
                } catch (IOException ex) {
                    if (connector instanceof NetworkConnector) {
                        PortInUseException.throwIfPortBindingException(ex, () -> ((NetworkConnector) connector).getPort());
                    }
                    throw ex;
                }
            }
            this.started = true;
            logger.info("Jetty started on port(s) " + getActualPortsDescription() + " with context path '" + getContextPath() + "'");
        } catch (WebServerException ex) {
            stopSilently();
            throw ex;
        } catch (Exception ex) {
            stopSilently();
            throw new WebServerException("Unable to start embedded Jetty server", ex);
        }
    }
}
Also used : NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Connector(org.eclipse.jetty.server.Connector) WebServerException(org.springframework.boot.web.server.WebServerException) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) IOException(java.io.IOException) WebServerException(org.springframework.boot.web.server.WebServerException) IOException(java.io.IOException) PortInUseException(org.springframework.boot.web.server.PortInUseException)

Example 17 with NetworkConnector

use of org.eclipse.jetty.server.NetworkConnector in project cxf by apache.

the class CodeGenBugTest method testHelloWorldExternalBindingFile.

@Test
public void testHelloWorldExternalBindingFile() throws Exception {
    Server server = new Server(0);
    try {
        ResourceHandler reshandler = new ResourceHandler();
        reshandler.setResourceBase(getLocation("/wsdl2java_wsdl/"));
        // this is the only handler we're supposed to need, so we don't need to
        // 'add' it.
        server.setHandler(reshandler);
        server.start();
        // give network connector a little time to spin up
        Thread.sleep(250);
        int port = ((NetworkConnector) server.getConnectors()[0]).getLocalPort();
        env.put(ToolConstants.CFG_WSDLURL, "http://localhost:" + port + "/hello_world.wsdl");
        env.put(ToolConstants.CFG_BINDING, "http://localhost:" + port + "/remote-hello_world_binding.xsd");
        processor.setContext(env);
        processor.execute();
        reshandler.stop();
    } finally {
        server.stop();
        server.destroy();
    }
}
Also used : Server(org.eclipse.jetty.server.Server) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 18 with NetworkConnector

use of org.eclipse.jetty.server.NetworkConnector in project qpid-broker-j by apache.

the class HttpManagement method logOperationalListenMessages.

private void logOperationalListenMessages() {
    for (Map.Entry<HttpPort<?>, ServerConnector> portConnector : _portConnectorMap.entrySet()) {
        HttpPort<?> port = portConnector.getKey();
        NetworkConnector connector = portConnector.getValue();
        logOperationalListenMessages(port, connector.getLocalPort());
    }
}
Also used : HttpPort(org.apache.qpid.server.model.port.HttpPort) ServerConnector(org.eclipse.jetty.server.ServerConnector) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 19 with NetworkConnector

use of org.eclipse.jetty.server.NetworkConnector in project dropwizard by dropwizard.

the class DefaultServerFactoryTest method testGracefulShutdown.

@Test
void testGracefulShutdown() throws Exception {
    CountDownLatch requestReceived = new CountDownLatch(1);
    CountDownLatch shutdownInvoked = new CountDownLatch(1);
    environment.jersey().register(new TestResource(requestReceived, shutdownInvoked));
    final ScheduledExecutorService executor = Executors.newScheduledThreadPool(3);
    http.configure(environment);
    final Server server = http.build(environment);
    ((AbstractNetworkConnector) server.getConnectors()[0]).setPort(0);
    ((AbstractNetworkConnector) server.getConnectors()[1]).setPort(0);
    ScheduledFuture<Void> cleanup = executor.schedule(() -> {
        if (!server.isStopped()) {
            server.stop();
        }
        executor.shutdownNow();
        return null;
    }, 5, TimeUnit.SECONDS);
    server.start();
    final int port = ((AbstractNetworkConnector) server.getConnectors()[0]).getLocalPort();
    Future<String> futureResult = executor.submit(() -> {
        URL url = new URL("http://localhost:" + port + "/app/test");
        URLConnection connection = url.openConnection();
        connection.connect();
        try (InputStream in = connection.getInputStream()) {
            return new String(ByteStreams.toByteArray(in), StandardCharsets.UTF_8);
        }
    });
    requestReceived.await(10, TimeUnit.SECONDS);
    Future<Void> serverStopped = executor.submit(() -> {
        server.stop();
        return null;
    });
    Connector[] connectors = server.getConnectors();
    assertThat(connectors).isNotEmpty();
    assertThat(connectors[0]).isInstanceOf(NetworkConnector.class);
    NetworkConnector connector = (NetworkConnector) connectors[0];
    // wait for server to close the connectors
    while (true) {
        if (!connector.isOpen()) {
            shutdownInvoked.countDown();
            break;
        }
        Thread.sleep(5);
    }
    String result = futureResult.get();
    assertThat(result).isEqualTo("test");
    serverStopped.get();
    // cancel the cleanup future since everything succeeded
    cleanup.cancel(false);
    executor.shutdownNow();
}
Also used : AbstractNetworkConnector(org.eclipse.jetty.server.AbstractNetworkConnector) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Connector(org.eclipse.jetty.server.Connector) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Server(org.eclipse.jetty.server.Server) InputStream(java.io.InputStream) CountDownLatch(java.util.concurrent.CountDownLatch) URL(java.net.URL) URLConnection(java.net.URLConnection) AbstractNetworkConnector(org.eclipse.jetty.server.AbstractNetworkConnector) AbstractNetworkConnector(org.eclipse.jetty.server.AbstractNetworkConnector) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Test(org.junit.jupiter.api.Test)

Example 20 with NetworkConnector

use of org.eclipse.jetty.server.NetworkConnector in project spring-framework by spring-projects.

the class WebRequestDataBinderIntegrationTests method startJettyServer.

@BeforeAll
void startJettyServer() throws Exception {
    // Let server pick its own random, available port.
    jettyServer = new Server(0);
    ServletContextHandler handler = new ServletContextHandler();
    MultipartConfigElement multipartConfig = new MultipartConfigElement("");
    ServletHolder holder = new ServletHolder(partsServlet);
    holder.getRegistration().setMultipartConfig(multipartConfig);
    handler.addServlet(holder, "/parts");
    holder = new ServletHolder(partListServlet);
    holder.getRegistration().setMultipartConfig(multipartConfig);
    handler.addServlet(holder, "/partlist");
    jettyServer.setHandler(handler);
    jettyServer.start();
    Connector[] connectors = jettyServer.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) BeforeAll(org.junit.jupiter.api.BeforeAll)

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