// Path: src/main/java/com/monkeyk/sos/web/WebUtils.java
// public abstract class WebUtils {
// 
// 
//     public static final String UTF_8 = "UTF-8";
// 
// 
//     /**
//      * Sync by pom.xml   <version></version>
//      */
//     public static final String VERSION = "2.0.1";
// 
// 
//     private static ThreadLocal<String> ipThreadLocal = new ThreadLocal<>();
// 
// 
//     public static void setIp(String ip) {
//         ipThreadLocal.set(ip);
//     }
// 
//     public static String getIp() {
//         return ipThreadLocal.get();
//     }
// 
//     //private
//     private WebUtils() {
//     }
// 
// 
//     /**
//      * Retrieve client ip address
//      *
//      * @param request HttpServletRequest
//      * @return IP
//      */
//     public static String retrieveClientIp(HttpServletRequest request) {
//         String ip = request.getHeader("x-forwarded-for");
//         if (isUnAvailableIp(ip)) {
//             ip = request.getHeader("Proxy-Client-IP");
//         }
//         if (isUnAvailableIp(ip)) {
//             ip = request.getHeader("WL-Proxy-Client-IP");
//         }
//         if (isUnAvailableIp(ip)) {
//             ip = request.getRemoteAddr();
//         }
//         return ip;
//     }
// 
//     private static boolean isUnAvailableIp(String ip) {
//         return StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip);
//     }
// 
// }
// 
// Path: src/main/java/com/monkeyk/sos/web/filter/CharacterEncodingIPFilter.java
// public class CharacterEncodingIPFilter extends CharacterEncodingFilter {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(CharacterEncodingIPFilter.class);
// 
// 
//     @Override
//     protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
//         recordIP(request);
//         super.doFilterInternal(request, response, filterChain);
//     }
// 
//     private void recordIP(HttpServletRequest request) {
//         final String ip = WebUtils.retrieveClientIp(request);
//         WebUtils.setIp(ip);
//         LOG.debug("Send request uri: {}, from IP: {}", request.getRequestURI(), ip);
//     }
// }
// 
// Path: src/main/java/com/monkeyk/sos/web/filter/SOSSiteMeshFilter.java
// public class SOSSiteMeshFilter extends ConfigurableSiteMeshFilter {
// 
// 
//     public SOSSiteMeshFilter() {
//     }
// 
// 
//     @Override
//     protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
// 
//         builder.addDecoratorPath("/*", "/WEB-INF/jsp/decorators/main.jsp")
// 
//                 .addExcludedPath("/static/**");
// 
// 
//     }
// }


import com.monkeyk.sos.web.WebUtils;
import com.monkeyk.sos.web.filter.CharacterEncodingIPFilter;
import com.monkeyk.sos.web.filter.SOSSiteMeshFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.servlet.Filter;
import java.nio.charset.Charset;
import java.util.List;
package com.monkeyk.sos.config;




/**
 * 2018/1/30
 * <p>
 * Spring MVC 扩展配置
 * <p>
 *
 * @author Shengzhao Li
 */
@Configuration
public class MVCConfiguration implements WebMvcConfigurer {


    /**
     * 扩展拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        WebMvcConfigurer.super.addInterceptors(registry);
    }


    /**
     * 解决乱码问题
     * For UTF-8
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        WebMvcConfigurer.super.configureMessageConverters(converters);
        converters.add(new StringHttpMessageConverter(Charset.forName(WebUtils.UTF_8)));
    }


    /**
     * 字符编码配置 UTF-8
     */
    @Bean
    public FilterRegistrationBean encodingFilter() {
        FilterRegistrationBean<Filter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new CharacterEncodingIPFilter());
        registrationBean.addUrlPatterns("/*");
        //值越小越靠前
        registrationBean.setOrder(1);
        return registrationBean;
    }


    /**
     * sitemesh filter
     */
// Path: src/main/java/com/monkeyk/sos/web/WebUtils.java
// public abstract class WebUtils {
// 
// 
//     public static final String UTF_8 = "UTF-8";
// 
// 
//     /**
//      * Sync by pom.xml   <version></version>
//      */
//     public static final String VERSION = "2.0.1";
// 
// 
//     private static ThreadLocal<String> ipThreadLocal = new ThreadLocal<>();
// 
// 
//     public static void setIp(String ip) {
//         ipThreadLocal.set(ip);
//     }
// 
//     public static String getIp() {
//         return ipThreadLocal.get();
//     }
// 
//     //private
//     private WebUtils() {
//     }
// 
// 
//     /**
//      * Retrieve client ip address
//      *
//      * @param request HttpServletRequest
//      * @return IP
//      */
//     public static String retrieveClientIp(HttpServletRequest request) {
//         String ip = request.getHeader("x-forwarded-for");
//         if (isUnAvailableIp(ip)) {
//             ip = request.getHeader("Proxy-Client-IP");
//         }
//         if (isUnAvailableIp(ip)) {
//             ip = request.getHeader("WL-Proxy-Client-IP");
//         }
//         if (isUnAvailableIp(ip)) {
//             ip = request.getRemoteAddr();
//         }
//         return ip;
//     }
// 
//     private static boolean isUnAvailableIp(String ip) {
//         return StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip);
//     }
// 
// }
// 
// Path: src/main/java/com/monkeyk/sos/web/filter/CharacterEncodingIPFilter.java
// public class CharacterEncodingIPFilter extends CharacterEncodingFilter {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(CharacterEncodingIPFilter.class);
// 
// 
//     @Override
//     protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
//         recordIP(request);
//         super.doFilterInternal(request, response, filterChain);
//     }
// 
//     private void recordIP(HttpServletRequest request) {
//         final String ip = WebUtils.retrieveClientIp(request);
//         WebUtils.setIp(ip);
//         LOG.debug("Send request uri: {}, from IP: {}", request.getRequestURI(), ip);
//     }
// }
// 
// Path: src/main/java/com/monkeyk/sos/web/filter/SOSSiteMeshFilter.java
// public class SOSSiteMeshFilter extends ConfigurableSiteMeshFilter {
// 
// 
//     public SOSSiteMeshFilter() {
//     }
// 
// 
//     @Override
//     protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
// 
//         builder.addDecoratorPath("/*", "/WEB-INF/jsp/decorators/main.jsp")
// 
//                 .addExcludedPath("/static/**");
// 
// 
//     }
// }


// Path: src/main/java/com/monkeyk/sos/config/MVCConfiguration.java
import com.monkeyk.sos.web.WebUtils;
import com.monkeyk.sos.web.filter.CharacterEncodingIPFilter;
import com.monkeyk.sos.web.filter.SOSSiteMeshFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.servlet.Filter;
import java.nio.charset.Charset;
import java.util.List;

package com.monkeyk.sos.config;




/**
 * 2018/1/30
 * <p>
 * Spring MVC 扩展配置
 * <p>
 *
 * @author Shengzhao Li
 */
@Configuration
public class MVCConfiguration implements WebMvcConfigurer {


    /**
     * 扩展拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        WebMvcConfigurer.super.addInterceptors(registry);
    }


    /**
     * 解决乱码问题
     * For UTF-8
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        WebMvcConfigurer.super.configureMessageConverters(converters);
        converters.add(new StringHttpMessageConverter(Charset.forName(WebUtils.UTF_8)));
    }


    /**
     * 字符编码配置 UTF-8
     */
    @Bean
    public FilterRegistrationBean encodingFilter() {
        FilterRegistrationBean<Filter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new CharacterEncodingIPFilter());
        registrationBean.addUrlPatterns("/*");
        //值越小越靠前
        registrationBean.setOrder(1);
        return registrationBean;
    }


    /**
     * sitemesh filter
     */
    @Bean