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

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

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

import java.util.Optional;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
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.autoconfigure.web.servlet.MultipartProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.zodiac.autoconfigure.netty2.NettyServerProperties;
import org.zodiac.commons.constants.SystemPropertiesConstants;

@SpringBootConfiguration
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnProperty(name = SystemPropertiesConstants.Zodiac.SERVER_SIMPLE_ENABLED, havingValue = "true", matchIfMissing = true)
@ConditionalOnClass(value = {io.netty.bootstrap.Bootstrap.class, org.zodiac.server.http.servlet.simple.SimpleWebServer.class})
//@ConditionalOnClass(value = {javax.servlet.Servlet.class, io.netty.bootstrap.Bootstrap.class, org.zodiac.server.http.servlet.simple.SimpleWebServer.class})
public class SimpleHttpServletServerAutoConfiguration {

    private NettyServerProperties nettyServerProperties;

    public SimpleHttpServletServerAutoConfiguration(NettyServerProperties nettyServerProperties) {
        this.nettyServerProperties = nettyServerProperties;
    }

    @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.getServlet().getMultipart().setEnabled(p.getEnabled())
                .setFileSizeThreshold(p.getFileSizeThreshold()).setLocation(p.getLocation())
                .setMaxFileSize(p.getMaxFileSize()).setMaxRequestSize(p.getMaxFileSize())
                .setResolveLazily(p.isResolveLazily());
        });
        return properties;
    }

    @Bean
    @ConditionalOnMissingBean(value = org.springframework.boot.web.servlet.server.ServletWebServerFactory.class, search = SearchStrategy.CURRENT)
    protected org.zodiac.server.http.servlet.simple.spring.SimpleServletWebSpringServerFactory simpleServletWebSpringServerFactory(SimpleHttpServerProperties simpleHttpServerProperties) {
        return new org.zodiac.server.http.servlet.simple.spring.SimpleServletWebSpringServerFactory(nettyServerProperties, simpleHttpServerProperties);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy