package kr.xit.core.spring.config.support;

import java.net.*;

import org.apache.catalina.connector.*;
import org.apache.coyote.ajp.*;
import org.springframework.boot.web.embedded.tomcat.*;
import org.springframework.boot.web.servlet.server.*;
import org.springframework.context.annotation.*;

//@Configuration
//@Profile({"local-can", "prod-can"})
public class TomcatConfiguration {

    @Bean
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
        tomcat.addAdditionalTomcatConnectors(createAjpConnector());
        return tomcat;
    }

    private Connector createAjpConnector() {
        Connector ajpConnector = new Connector("AJP/1.3");
        ajpConnector.setPort(18009);
        ajpConnector.setSecure(false);
        ajpConnector.setAllowTrace(false);
        ajpConnector.setScheme("http");
        ((AbstractAjpProtocol) ajpConnector.getProtocolHandler()).setSecretRequired(false);
        try {
            AjpNioProtocol protocol = (AjpNioProtocol) ajpConnector.getProtocolHandler();
            protocol.setAddress(InetAddress.getByName("0.0.0.0"));
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
        return ajpConnector;
    }
}
