TssWebMvcConfig.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package com.style24.scm.support.config;
  2. import java.nio.charset.Charset;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.boot.web.servlet.FilterRegistrationBean;
  5. import org.springframework.context.annotation.Bean;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
  8. import org.springframework.http.converter.StringHttpMessageConverter;
  9. import org.springframework.web.client.RestTemplate;
  10. import org.springframework.web.multipart.support.MultipartFilter;
  11. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  12. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  13. import com.style24.scm.support.interceptor.TssDefaultInterceptor;
  14. import com.gagaframework.web.core.filter.GagaXssServletFilter;
  15. import com.gagaframework.web.rest.client.GagaRequestStringTrim;
  16. /**
  17. * Web MVC Configuration
  18. *
  19. * @author gagamel
  20. * @since 2020. 10. 19
  21. */
  22. @Configuration
  23. public class TssWebMvcConfig implements WebMvcConfigurer {
  24. @Autowired
  25. private TssDefaultInterceptor defaultInterceptor;
  26. @Override
  27. public void addInterceptors(InterceptorRegistry registry) {
  28. final String[] excludePathPatterns = new String[] {
  29. "/", "/index", "/signin", "/image/**", "/ux/**", "/smartEditor/**", "/favicon.ico",
  30. "/error/**", "/data/**", "/login", "/logout",
  31. "/delivery/sweettracker/response"
  32. };
  33. registry.addInterceptor(defaultInterceptor)
  34. .addPathPatterns("/**/*")
  35. .excludePathPatterns(excludePathPatterns);
  36. }
  37. /**
  38. * @RequestBody annotation 이용 시 json data 형식의 모든 문자열의 앞, 뒤 공백을 제거
  39. */
  40. @Bean
  41. public GagaRequestStringTrim stringTrim() {
  42. return new GagaRequestStringTrim();
  43. }
  44. /**
  45. * XSS(Cross Site Script) Prevention Filter
  46. *
  47. * @return
  48. */
  49. @SuppressWarnings({"rawtypes", "unchecked"})
  50. @Bean
  51. public FilterRegistrationBean xssFilterRegistrationBean() {
  52. FilterRegistrationBean bean = new FilterRegistrationBean();
  53. bean.setFilter(new GagaXssServletFilter());
  54. bean.setOrder(2);
  55. bean.addUrlPatterns("/*");
  56. return bean;
  57. }
  58. /**
  59. * Multipart Filter
  60. * 파일 업로드 구현 시 MultipartRequest를 처리함에 따라 해당 부분은 불필요 하나,
  61. * com.oreilly.servlet.MultipartRequest 같은 걸 이용 시
  62. * "Corrupt form data: premature ending" exception이 발생한다.
  63. * 이를 해결하고자 Filter를 구성
  64. *
  65. * @return
  66. */
  67. @SuppressWarnings({"rawtypes", "unchecked"})
  68. @Bean
  69. public FilterRegistrationBean springMultipartRegistrationBean() {
  70. FilterRegistrationBean bean = new FilterRegistrationBean();
  71. bean.setName("springMultipartResolver");
  72. bean.setFilter(new MultipartFilter());
  73. bean.setOrder(1);
  74. bean.addUrlPatterns(new String[] {
  75. "/common/file/upload/**",
  76. "/common/files/upload/**"
  77. });
  78. return bean;
  79. }
  80. /**
  81. * API 호출을 위한 RestTemplate 설정
  82. *
  83. * @return
  84. */
  85. @Bean
  86. public RestTemplate restTemplate() {
  87. HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
  88. factory.setConnectTimeout(300000);
  89. factory.setReadTimeout(300000);
  90. RestTemplate restTemplate = new RestTemplate(factory);
  91. // Convert the message to UTF-8
  92. restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
  93. return restTemplate;
  94. }
  95. }