org.zodiac.autoconfigure.netty2.server.NettyServerConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.netty2.server;
import java.util.Optional;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.servlet.MultipartProperties;
import org.zodiac.autoconfigure.netty2.NettyServerProperties;
public class NettyServerConfiguration {
public NettyServerConfiguration() {
}
protected NettyServerProperties nettyServerProperties(ObjectProvider serverPropertiesProvider,
ObjectProvider multipartPropertiesProvider) {
final NettyServerProperties properties = new NettyServerProperties();
Optional.ofNullable(serverPropertiesProvider.getIfAvailable()).ifPresent(p -> {
if (null != p.getPort()) {
properties.setPort(p.getPort());
properties.getListen().setServerPort(properties.getPort());
}
boolean secure = null != p.getSsl() && p.getSsl().isEnabled();
properties.getHandler().setEnableSsl(secure);
properties.getTls().setEnabled(secure);
properties.getHttp().getHttp20().setEnabled(null != p.getHttp2() && p.getHttp2().isEnabled());
});
Optional.ofNullable(multipartPropertiesProvider.getIfAvailable()).ifPresent(p -> {
properties.getHttp().getServlet().getMultipart().setEnabled(p.getEnabled())
.setFileSizeThreshold(p.getFileSizeThreshold()).setLocation(p.getLocation())
.setMaxFileSize(p.getMaxFileSize()).setMaxRequestSize(p.getMaxFileSize())
.setResolveLazily(p.isResolveLazily());
});
return properties;
}
}