All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.server.http.NettyWebReactiveServerAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.server.http;

//import java.util.Collection;
//import java.util.function.Supplier;
//
//import org.springframework.beans.factory.BeanFactory;
//import org.springframework.boot.SpringBootConfiguration;
//import org.springframework.boot.autoconfigure.AutoConfigureAfter;
//import org.springframework.boot.autoconfigure.AutoConfigureOrder;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
//import org.springframework.boot.autoconfigure.condition.SearchStrategy;
//import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Import;
//import org.springframework.core.Ordered;
//import org.zodiac.autoconfigure.netty.condition.ConditionalOnNettyServerEnabled;
//import org.zodiac.commons.constants.SystemPropertiesConstants;
//
///**
// * Reactive 容器工厂配置类:配置内置Netty容器Bean。 最早是直接将NettyTcpSpringReactiveServerFactory加@Component注解,这样集成在任何环境中都会加载,可能引起端口冲突。
// * 所以通过这个配置类,配置在当前上下文缺少 EmbeddedServletContainerFactory接口实现类时(即缺少内置Servlet容器), 加载EmbeddedNettyFactory
// * 这样SpringBoot项目在引入这个maven依赖,并且排除了内置tomcat依赖、且没引入其他reactive容器(如jetty)时, 就可以通过工厂类加载并启动netty容器了。
// */
////@SpringBootConfiguration
//@ConditionalOnNettyServerEnabled
//@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
//// @ConditionalOnWebApplication(type = Type.SERVLET)
////@ConditionalOnProperty(prefix = SystemPropertiesConstants.Zodiac.SERVER_NETTY_PREFIX, value = "enabled", havingValue = "true")
//@AutoConfigureAfter(value = {org.zodiac.autoconfigure.netty.NettyReactiveServerAutoConfiguration.class})
//@Import(value = {NettyWebReactiveServerAutoConfiguration.SimpleServletWebServerFactoryConfigutation.class, NettyWebReactiveServerAutoConfiguration.RemoteServletWebServerFactoryConfigutation.class})
//@ConditionalOnClass(value = {javax.servlet.Servlet.class, /*org.springframework.web.server.WebHandler.class,*/ org.zodiac.server.http.reactive.simple.SimpleReactiveWebServer.class, org.zodiac.netty.base.api.ProtocolHandler.class, org.zodiac.netty.springboot.server.reactive.NettyTcpSpringReactiveServerFactory.class})
//public class NettyWebReactiveServerAutoConfiguration {
//
////    @Bean
////    @ConditionalOnMissingBean
////    @ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SERVER_NETTY_PREFIX, ignoreInvalidFields = true)
////    protected NettyServerProperties nettyServerProperties(ObjectProvider serverPropertiesProvider,
////        ObjectProvider multipartPropertiesProvider) {
////        final NettyServerProperties properties = new NettyServerProperties();
////        Optional.ofNullable(serverPropertiesProvider.getIfAvailable()).ifPresent(p -> {
////            if (null != p.getPort())
////                properties.getListen().setServerPort(p.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().getMultipart().setEnabled(p.getEnabled())
////                .setFileSizeThreshold(p.getFileSizeThreshold()).setLocation(p.getLocation())
////                .setMaxFileSize(p.getMaxFileSize()).setMaxRequestSize(p.getMaxFileSize())
////                .setResolveLazily(p.isResolveLazily());
////        });
////        return properties;
////    }
//
////    @Bean
////    @ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.SERVER_SIMPLE_PREFIX, ignoreInvalidFields = true)
////    protected SimpleHttpServerProperties simpleHttpServerProperties(ObjectProvider multipartPropertiesProvider) {
////        SimpleHttpServerProperties properties = new SimpleHttpServerProperties();
////        Optional.ofNullable(multipartPropertiesProvider.getIfAvailable()).ifPresent(p -> {
////            properties.getMultipart().setEnabled(p.getEnabled())
////                .setFileSizeThreshold(p.getFileSizeThreshold()).setLocation(p.getLocation())
////                .setMaxFileSize(p.getMaxFileSize()).setMaxRequestSize(p.getMaxFileSize())
////                .setResolveLazily(p.isResolveLazily());
////        });
////        return properties;
////    }
//
//    /**
//     * Netty的Bootstrap类必须在classloader中存在,才能启动Netty容器。
//     *
//     */
//    @SpringBootConfiguration
////    @ConditionalOnPlatformTenantEnabled
//    @ConditionalOnWebApplication(type = Type.REACTIVE)
//    @ConditionalOnMissingBean(value = ReactiveWebServerFactory.class, search = SearchStrategy.CURRENT)
//    @ConditionalOnProperty(name = SystemPropertiesConstants.Zodiac.SERVER_SIMPLE_ENABLED, havingValue = "true")
//    @ConditionalOnClass(value = {io.netty.bootstrap.Bootstrap.class, javax.servlet.Servlet.class, org.zodiac.server.http.reactive.simple.SimpleReactiveWebServer.class,
//        org.zodiac.netty.base.api.ProtocolHandler.class, org.zodiac.netty.springboot.server.reactive.NettyTcpSpringReactiveServerFactory.class})
//    protected static class SimpleServletWebServerFactoryConfigutation {
//
//        private org.zodiac.netty.springboot.NettyServerProperties nettyServerProperties;
//        private SimpleHttpServerProperties simpleHttpServerProperties;
//
//        public SimpleServletWebServerFactoryConfigutation(org.zodiac.netty.springboot.NettyServerProperties nettyServerProperties,
//            SimpleHttpServerProperties simpleHttpServerProperties) {
//            super();
//            this.nettyServerProperties = nettyServerProperties;
//            this.simpleHttpServerProperties = simpleHttpServerProperties;
//        }
//
//        /*上述条件注解成立的场景,使用此NettyWebServer容器工厂*/
//        @Bean
//        @ConditionalOnMissingBean(value = {ReactiveWebServerFactory.class})
//        protected org.zodiac.server.http.servlet.simple.spring.SimpleServletWebSpringServerFactory simpleServletWebSpringServerFactory() {
//            return new org.zodiac.server.http.servlet.simple.spring.SimpleServletWebSpringServerFactory(nettyServerProperties, simpleHttpServerProperties);
//        }
//    }
//
//    /**
//     * Netty的Bootstrap类必须在classloader中存在,才能启动Netty容器。
//     *
//     */
//    @SpringBootConfiguration
////    @ConditionalOnHttpCacheEnabled
//    @ConditionalOnWebApplication(type = Type.REACTIVE)
//    @ConditionalOnMissingBean(value = ReactiveWebServerFactory.class, search = SearchStrategy.CURRENT)
//    @ConditionalOnClass(value = {io.netty.bootstrap.Bootstrap.class, org.zodiac.netty.base.api.ProtocolHandler.class, org.zodiac.netty.springboot.server.servlet.NettyTcpSpringServletServerFactory.class})
//    protected static class RemoteServletWebServerFactoryConfigutation {
//
//        private org.zodiac.netty.springboot.NettyServerProperties nettyServerProperties;
//
//        public RemoteServletWebServerFactoryConfigutation(org.zodiac.netty.springboot.NettyServerProperties nettyServerProperties) {
//            this.nettyServerProperties = nettyServerProperties;
//        }
//
//        /**
//         * Add a TCP service factory
//         * 
//         * @param protocolHandlers protocolHandlers
//         * @param serverListeners serverListeners
//         * @param beanFactory beanFactory
//         * @return NettyTcpServerFactory
//         */
//        @Bean(name = org.zodiac.netty.base.constants.NettyConstants.NETTY_TCP_SERVER_FACTORY_BEAN_NAME)
//        //@ConditionalOnMissingBean
//        protected org.zodiac.netty.springboot.server.servlet.NettyTcpSpringServletServerFactory nettyTcpSpringServletServerFactory(Collection protocolHandlers,
//            Collection serverListeners, BeanFactory beanFactory) {
//            Supplier handlerSupplier = () -> {
//                Class type = nettyServerProperties.getChannelHandler();
//                return type == org.zodiac.netty.base.protocol.DynamicProtocolChannelHandler.class ? new org.zodiac.netty.base.protocol.DynamicProtocolChannelHandler()
//                    : beanFactory.getBean(type);
//            };
//            org.zodiac.netty.springboot.server.servlet.NettyTcpSpringServletServerFactory tcpServerFactory =
//                new org.zodiac.netty.springboot.server.servlet.NettyTcpSpringServletServerFactory(nettyServerProperties, handlerSupplier);
//            tcpServerFactory.getProtocolHandlers().addAll(protocolHandlers);
//            tcpServerFactory.getServerListeners().addAll(serverListeners);
//            return tcpServerFactory;
//        }
//    }
//}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy