001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.web.embedded;
018
019import io.undertow.Undertow;
020import org.apache.catalina.startup.Tomcat;
021import org.apache.coyote.UpgradeProtocol;
022import org.eclipse.jetty.server.Server;
023import org.eclipse.jetty.util.Loader;
024import org.eclipse.jetty.webapp.WebAppContext;
025import org.xnio.SslClientAuthMode;
026import reactor.netty.http.server.HttpServer;
027
028import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
029import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
030import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
031import org.springframework.boot.autoconfigure.web.ServerProperties;
032import org.springframework.boot.context.properties.EnableConfigurationProperties;
033import org.springframework.context.annotation.Bean;
034import org.springframework.context.annotation.Configuration;
035import org.springframework.core.env.Environment;
036
037/**
038 * {@link EnableAutoConfiguration Auto-configuration} for embedded servlet and reactive
039 * web servers customizations.
040 *
041 * @author Phillip Webb
042 * @since 2.0.0
043 */
044@Configuration
045@ConditionalOnWebApplication
046@EnableConfigurationProperties(ServerProperties.class)
047public class EmbeddedWebServerFactoryCustomizerAutoConfiguration {
048
049        /**
050         * Nested configuration if Tomcat is being used.
051         */
052        @Configuration
053        @ConditionalOnClass({ Tomcat.class, UpgradeProtocol.class })
054        public static class TomcatWebServerFactoryCustomizerConfiguration {
055
056                @Bean
057                public TomcatWebServerFactoryCustomizer tomcatWebServerFactoryCustomizer(
058                                Environment environment, ServerProperties serverProperties) {
059                        return new TomcatWebServerFactoryCustomizer(environment, serverProperties);
060                }
061
062        }
063
064        /**
065         * Nested configuration if Jetty is being used.
066         */
067        @Configuration
068        @ConditionalOnClass({ Server.class, Loader.class, WebAppContext.class })
069        public static class JettyWebServerFactoryCustomizerConfiguration {
070
071                @Bean
072                public JettyWebServerFactoryCustomizer jettyWebServerFactoryCustomizer(
073                                Environment environment, ServerProperties serverProperties) {
074                        return new JettyWebServerFactoryCustomizer(environment, serverProperties);
075                }
076
077        }
078
079        /**
080         * Nested configuration if Undertow is being used.
081         */
082        @Configuration
083        @ConditionalOnClass({ Undertow.class, SslClientAuthMode.class })
084        public static class UndertowWebServerFactoryCustomizerConfiguration {
085
086                @Bean
087                public UndertowWebServerFactoryCustomizer undertowWebServerFactoryCustomizer(
088                                Environment environment, ServerProperties serverProperties) {
089                        return new UndertowWebServerFactoryCustomizer(environment, serverProperties);
090                }
091
092        }
093
094        /**
095         * Nested configuration if Netty is being used.
096         */
097        @Configuration
098        @ConditionalOnClass(HttpServer.class)
099        public static class NettyWebServerFactoryCustomizerConfiguration {
100
101                @Bean
102                public NettyWebServerFactoryCustomizer nettyWebServerFactoryCustomizer(
103                                Environment environment, ServerProperties serverProperties) {
104                        return new NettyWebServerFactoryCustomizer(environment, serverProperties);
105                }
106
107        }
108
109}