BAEL-2715: Modified customizers
This commit is contained in:
parent
24c5be0e4f
commit
4d05dd1d9e
|
@ -0,0 +1,49 @@
|
|||
package com.baeldung.serverconfig.server;
|
||||
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
|
||||
import org.springframework.boot.web.embedded.netty.NettyServerCustomizer;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.netty.http.server.HttpServer;
|
||||
|
||||
@Component
|
||||
public class NettyWebServerFactoryBootstrapCustomizer implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
|
||||
|
||||
@Override
|
||||
public void customize(NettyReactiveWebServerFactory serverFactory) {
|
||||
serverFactory.addServerCustomizers(new PortCustomizer(8443));
|
||||
serverFactory.addServerCustomizers(new EventLoopNettyCustomizer());
|
||||
}
|
||||
|
||||
private static class PortCustomizer implements NettyServerCustomizer {
|
||||
|
||||
private final int port;
|
||||
|
||||
private PortCustomizer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpServer apply(HttpServer httpServer) {
|
||||
return httpServer.port(port);
|
||||
}
|
||||
}
|
||||
|
||||
private static class EventLoopNettyCustomizer implements NettyServerCustomizer {
|
||||
|
||||
@Override
|
||||
public HttpServer apply(HttpServer httpServer) {
|
||||
EventLoopGroup parentGroup = new NioEventLoopGroup();
|
||||
EventLoopGroup childGroup = new NioEventLoopGroup();
|
||||
return httpServer
|
||||
.tcpConfiguration(tcpServer -> tcpServer.bootstrap(
|
||||
serverBootstrap -> serverBootstrap.group(parentGroup, childGroup).channel(NioServerSocketChannel.class)
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.baeldung.serverconfig.server;
|
||||
|
||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
|
||||
import org.springframework.boot.web.embedded.netty.NettyServerCustomizer;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.netty.http.server.HttpServer;
|
||||
|
||||
@Component
|
||||
public class NettyWebServerFactoryPortCustomizer implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
|
||||
|
||||
@Override
|
||||
public void customize(NettyReactiveWebServerFactory serverFactory) {
|
||||
serverFactory.addServerCustomizers(new PortCustomizer(8443));
|
||||
}
|
||||
|
||||
private static class PortCustomizer implements NettyServerCustomizer {
|
||||
|
||||
private final int port;
|
||||
|
||||
private PortCustomizer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpServer apply(HttpServer httpServer) {
|
||||
return httpServer.port(port);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package com.baeldung.serverconfig.server;
|
||||
|
||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
|
||||
import org.springframework.boot.web.embedded.netty.SslServerCustomizer;
|
||||
import org.springframework.boot.web.server.Http2;
|
||||
import org.springframework.boot.web.server.Ssl;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -16,7 +18,9 @@ public class NettyWebServerFactorySslCustomizer implements WebServerFactoryCusto
|
|||
ssl.setKeyAlias("alias");
|
||||
ssl.setKeyPassword("password");
|
||||
ssl.setKeyStorePassword("secret");
|
||||
serverFactory.setSsl(ssl);
|
||||
Http2 http2 = new Http2();
|
||||
http2.setEnabled(false);
|
||||
serverFactory.addServerCustomizers(new SslServerCustomizer(ssl, http2, null));
|
||||
serverFactory.setPort(8443);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue