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.websocket.reactive;
018
019import javax.servlet.Servlet;
020import javax.websocket.server.ServerContainer;
021
022import org.apache.catalina.startup.Tomcat;
023
024import org.springframework.boot.autoconfigure.AutoConfigureBefore;
025import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
026import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
027import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
028import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
029import org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration;
030import org.springframework.context.annotation.Bean;
031import org.springframework.context.annotation.Configuration;
032
033/**
034 * Auto configuration for WebSocket reactive server in Tomcat, Jetty or Undertow. Requires
035 * the appropriate WebSocket modules to be on the classpath.
036 * <p>
037 * If Tomcat's WebSocket support is detected on the classpath we add a customizer that
038 * installs the Tomcat WebSocket initializer.
039 *
040 * @author Brian Clozel
041 * @since 2.0.0
042 */
043@Configuration
044@ConditionalOnClass({ Servlet.class, ServerContainer.class })
045@ConditionalOnWebApplication(type = Type.REACTIVE)
046@AutoConfigureBefore(ReactiveWebServerFactoryAutoConfiguration.class)
047public class WebSocketReactiveAutoConfiguration {
048
049        @Configuration
050        @ConditionalOnClass(name = "org.apache.tomcat.websocket.server.WsSci", value = Tomcat.class)
051        static class TomcatWebSocketConfiguration {
052
053                @Bean
054                @ConditionalOnMissingBean(name = "websocketReactiveWebServerCustomizer")
055                public TomcatWebSocketReactiveWebServerCustomizer websocketReactiveWebServerCustomizer() {
056                        return new TomcatWebSocketReactiveWebServerCustomizer();
057                }
058
059        }
060
061}