Finalize upgrade to Reactor Netty 0.8

This commit fixes the last issue for the upgrade to Reactor Netty 0.8.

Closes: gh-13321
pull/13870/merge
Brian Clozel 6 years ago
parent e15ca514c8
commit 57dbea0db3

@ -16,11 +16,11 @@
package org.springframework.boot.web.embedded.netty;
import java.net.BindException;
import java.time.Duration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import reactor.netty.ChannelBindException;
import reactor.netty.DisposableServer;
import reactor.netty.http.HttpResources;
import reactor.netty.http.server.HttpServer;
@ -69,8 +69,9 @@ public class NettyWebServer implements WebServer {
this.disposableServer = startHttpServer();
}
catch (Exception ex) {
if (findBindException(ex) != null) {
throw new PortInUseException(getPort());
ChannelBindException bindException = findBindException(ex);
if (bindException != null) {
throw new PortInUseException(bindException.localPort());
}
throw new WebServerException("Unable to start Netty", ex);
}
@ -87,11 +88,11 @@ public class NettyWebServer implements WebServer {
return this.httpServer.handle(this.handlerAdapter).bindNow();
}
private BindException findBindException(Exception ex) {
private ChannelBindException findBindException(Exception ex) {
Throwable candidate = ex;
while (candidate != null) {
if (candidate instanceof BindException) {
return (BindException) candidate;
if (candidate instanceof ChannelBindException) {
return (ChannelBindException) candidate;
}
candidate = candidate.getCause();
}

@ -18,14 +18,14 @@ package org.springframework.boot.web.embedded.netty;
import java.util.Arrays;
import org.junit.Ignore;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.mockito.InOrder;
import reactor.netty.http.server.HttpServer;
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory;
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests;
import org.springframework.boot.web.server.WebServerException;
import org.springframework.boot.web.server.PortInUseException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
@ -46,14 +46,15 @@ public class NettyReactiveWebServerFactoryTests
}
@Test
@Ignore
public void exceptionIsThrownWhenPortIsAlreadyInUse() {
AbstractReactiveWebServerFactory factory = getFactory();
factory.setPort(0);
this.webServer = factory.getWebServer(new EchoHandler());
this.webServer.start();
factory.setPort(this.webServer.getPort());
this.thrown.expect(WebServerException.class);
this.thrown.expect(PortInUseException.class);
this.thrown.expect(
Matchers.hasProperty("port", Matchers.equalTo(this.webServer.getPort())));
factory.getWebServer(new EchoHandler()).start();
}

Loading…
Cancel
Save