Search in sources :

Example 1 with PortInUseException

use of cn.taketoday.framework.web.server.PortInUseException in project today-infrastructure by TAKETODAY.

the class UndertowServletWebServerFactoryTests method handleExceptionCausedByBlockedPortOnPrimaryConnector.

@Override
protected void handleExceptionCausedByBlockedPortOnPrimaryConnector(RuntimeException ex, int blockedPort) {
    assertThat(ex).isInstanceOf(PortInUseException.class);
    assertThat(((PortInUseException) ex).getPort()).isEqualTo(blockedPort);
    Undertow undertow = (Undertow) ReflectionTestUtils.getField(this.webServer, "undertow");
    Assertions.assertThat(undertow.getWorker()).isNull();
}
Also used : PortInUseException(cn.taketoday.framework.web.server.PortInUseException) Undertow(io.undertow.Undertow)

Example 2 with PortInUseException

use of cn.taketoday.framework.web.server.PortInUseException in project today-framework by TAKETODAY.

the class UndertowServletWebServerFactoryTests method handleExceptionCausedByBlockedPortOnPrimaryConnector.

@Override
protected void handleExceptionCausedByBlockedPortOnPrimaryConnector(RuntimeException ex, int blockedPort) {
    assertThat(ex).isInstanceOf(PortInUseException.class);
    assertThat(((PortInUseException) ex).getPort()).isEqualTo(blockedPort);
    Undertow undertow = (Undertow) ReflectionTestUtils.getField(this.webServer, "undertow");
    Assertions.assertThat(undertow.getWorker()).isNull();
}
Also used : PortInUseException(cn.taketoday.framework.web.server.PortInUseException) Undertow(io.undertow.Undertow)

Example 3 with PortInUseException

use of cn.taketoday.framework.web.server.PortInUseException in project today-framework by TAKETODAY.

the class NettyWebServer method start.

@Override
public void start() throws WebServerException {
    DisposableServer disposableServer = this.disposableServer;
    if (disposableServer == null) {
        try {
            disposableServer = startHttpServer();
            this.disposableServer = disposableServer;
        } catch (Exception ex) {
            PortInUseException.ifCausedBy(ex, ChannelBindException.class, (bindException) -> {
                if (bindException.localPort() > 0 && !isPermissionDenied(bindException.getCause())) {
                    throw new PortInUseException(bindException.localPort(), ex);
                }
            });
            throw new WebServerException("Unable to start Netty", ex);
        }
        logger.info("Netty started{}", getStartedOnMessage(disposableServer));
        startDaemonAwaitThread(disposableServer);
    }
}
Also used : HttpServerResponse(reactor.netty.http.server.HttpServerResponse) NativeIoException(io.netty.channel.unix.Errors.NativeIoException) Assert(cn.taketoday.lang.Assert) GracefulShutdownCallback(cn.taketoday.framework.web.server.GracefulShutdownCallback) WebServer(cn.taketoday.framework.web.server.WebServer) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) BiFunction(java.util.function.BiFunction) ReactorHttpHandlerAdapter(cn.taketoday.http.server.reactive.ReactorHttpHandlerAdapter) Supplier(java.util.function.Supplier) PortInUseException(cn.taketoday.framework.web.server.PortInUseException) Duration(java.time.Duration) Predicate(java.util.function.Predicate) Publisher(org.reactivestreams.Publisher) WebServerException(cn.taketoday.framework.web.server.WebServerException) ChannelBindException(reactor.netty.ChannelBindException) Shutdown(cn.taketoday.framework.web.server.Shutdown) GracefulShutdownResult(cn.taketoday.framework.web.server.GracefulShutdownResult) LoggerFactory(cn.taketoday.logging.LoggerFactory) DefaultEventExecutor(io.netty.util.concurrent.DefaultEventExecutor) HttpServerRequest(reactor.netty.http.server.HttpServerRequest) List(java.util.List) HttpServer(reactor.netty.http.server.HttpServer) Nullable(cn.taketoday.lang.Nullable) Logger(cn.taketoday.logging.Logger) Collections(java.util.Collections) DisposableServer(reactor.netty.DisposableServer) HttpServerRoutes(reactor.netty.http.server.HttpServerRoutes) PortInUseException(cn.taketoday.framework.web.server.PortInUseException) DisposableServer(reactor.netty.DisposableServer) WebServerException(cn.taketoday.framework.web.server.WebServerException) NativeIoException(io.netty.channel.unix.Errors.NativeIoException) PortInUseException(cn.taketoday.framework.web.server.PortInUseException) WebServerException(cn.taketoday.framework.web.server.WebServerException) ChannelBindException(reactor.netty.ChannelBindException) ChannelBindException(reactor.netty.ChannelBindException)

Aggregations

PortInUseException (cn.taketoday.framework.web.server.PortInUseException)3 Undertow (io.undertow.Undertow)2 GracefulShutdownCallback (cn.taketoday.framework.web.server.GracefulShutdownCallback)1 GracefulShutdownResult (cn.taketoday.framework.web.server.GracefulShutdownResult)1 Shutdown (cn.taketoday.framework.web.server.Shutdown)1 WebServer (cn.taketoday.framework.web.server.WebServer)1 WebServerException (cn.taketoday.framework.web.server.WebServerException)1 ReactorHttpHandlerAdapter (cn.taketoday.http.server.reactive.ReactorHttpHandlerAdapter)1 Assert (cn.taketoday.lang.Assert)1 Nullable (cn.taketoday.lang.Nullable)1 Logger (cn.taketoday.logging.Logger)1 LoggerFactory (cn.taketoday.logging.LoggerFactory)1 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)1 NativeIoException (io.netty.channel.unix.Errors.NativeIoException)1 DefaultEventExecutor (io.netty.util.concurrent.DefaultEventExecutor)1 Duration (java.time.Duration)1 Collections (java.util.Collections)1 List (java.util.List)1 BiFunction (java.util.function.BiFunction)1 Predicate (java.util.function.Predicate)1