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.actuate.autoconfigure.web.reactive;
018
019import org.springframework.beans.factory.ListableBeanFactory;
020import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
021import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
022import org.springframework.boot.actuate.autoconfigure.web.server.ManagementWebServerFactoryCustomizer;
023import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
024import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
025import org.springframework.boot.autoconfigure.web.embedded.JettyWebServerFactoryCustomizer;
026import org.springframework.boot.autoconfigure.web.embedded.NettyWebServerFactoryCustomizer;
027import org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer;
028import org.springframework.boot.autoconfigure.web.embedded.UndertowWebServerFactoryCustomizer;
029import org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryCustomizer;
030import org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory;
031import org.springframework.context.ApplicationContext;
032import org.springframework.context.annotation.Bean;
033import org.springframework.http.server.reactive.HttpHandler;
034import org.springframework.web.reactive.config.EnableWebFlux;
035import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
036
037/**
038 * {@link ManagementContextConfiguration} for reactive web infrastructure when a separate
039 * management context with a web server running on a different port is required.
040 *
041 * @author Andy Wilkinson
042 * @author Phillip Webb
043 * @since 2.0.0
044 */
045@EnableWebFlux
046@ManagementContextConfiguration(ManagementContextType.CHILD)
047@ConditionalOnWebApplication(type = Type.REACTIVE)
048public class ReactiveManagementChildContextConfiguration {
049
050        @Bean
051        public ReactiveManagementWebServerFactoryCustomizer reactiveManagementWebServerFactoryCustomizer(
052                        ListableBeanFactory beanFactory) {
053                return new ReactiveManagementWebServerFactoryCustomizer(beanFactory);
054        }
055
056        @Bean
057        public HttpHandler httpHandler(ApplicationContext applicationContext) {
058                return WebHttpHandlerBuilder.applicationContext(applicationContext).build();
059        }
060
061        class ReactiveManagementWebServerFactoryCustomizer extends
062                        ManagementWebServerFactoryCustomizer<ConfigurableReactiveWebServerFactory> {
063
064                ReactiveManagementWebServerFactoryCustomizer(ListableBeanFactory beanFactory) {
065                        super(beanFactory, ReactiveWebServerFactoryCustomizer.class,
066                                        TomcatWebServerFactoryCustomizer.class,
067                                        JettyWebServerFactoryCustomizer.class,
068                                        UndertowWebServerFactoryCustomizer.class,
069                                        NettyWebServerFactoryCustomizer.class);
070                }
071
072        }
073
074}