diff --git a/README.md b/README.md index 6aa1b17..27ddd81 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Academ Back-end repository입니다. --- ### 프로젝트 구조 -( 최신화 : v1.2.0-alpha ) +( 최신화 : v1.2.1-alpha ) ``` │ ├── .github diff --git a/src/main/java/com/example/Devkor_project/security/TrafficFilter.java b/src/main/java/com/example/Devkor_project/security/TrafficFilter.java index c14ef1e..c280760 100644 --- a/src/main/java/com/example/Devkor_project/security/TrafficFilter.java +++ b/src/main/java/com/example/Devkor_project/security/TrafficFilter.java @@ -22,61 +22,41 @@ public class TrafficFilter extends OncePerRequestFilter { @Override @Transactional - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - - // 비동기 가능 여부 확인 - if(request.isAsyncSupported()) - { - // 비동기 작업 수행 - AsyncContext asyncContext = request.startAsync(); - - asyncContext.start(() -> { - - Traffic traffic = trafficRepository.searchTraffic(request.getRequestURI(), String.valueOf(LocalDate.now().getYear()), (byte) LocalDate.now().getMonthValue()); - - // 기존 트래픽 정보가 존재한다면, count 값을 1 증가 - // 기존 트래픽 정보가 존재하지 않는다면, 새롭게 만든 후 count 값을 1로 초기화 - if(traffic != null) - { - traffic.setCount(traffic.getCount() + 1); - - trafficRepository.save(traffic); - } - else - { - Traffic newTraffic = Traffic.builder() - .api_path(request.getRequestURI()) - .year(String.valueOf(LocalDate.now().getYear())) - .month((byte) LocalDate.now().getMonthValue()) - .count(1) - .build(); - - trafficRepository.save(newTraffic); - } - - // 비동기 작업 완료 - asyncContext.complete(); - }); + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException + { + try { + Traffic traffic = trafficRepository.searchTraffic(request.getRequestURI(), String.valueOf(LocalDate.now().getYear()), (byte) LocalDate.now().getMonthValue()); + + // 기존 트래픽 정보가 존재한다면, count 값을 1 증가 + // 기존 트래픽 정보가 존재하지 않는다면, 새롭게 만든 후 count 값을 1로 초기화 + if (traffic != null) { + traffic.setCount(traffic.getCount() + 1); + + trafficRepository.save(traffic); + } else { + Traffic newTraffic = Traffic.builder() + .api_path(request.getRequestURI()) + .year(String.valueOf(LocalDate.now().getYear())) + .month((byte) LocalDate.now().getMonthValue()) + .count(1) + .build(); + + trafficRepository.save(newTraffic); + } + } catch (Exception error) { + throw new RuntimeException(error); } filterChain.doFilter(request, response); - } // 필터를 적용하지 않을 경로 설정 @Override - protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { - - String[] excludePath = { - "/api/admin", - "/api/is-secure", - "/swagger-ui", - "/v3/api-docs" - }; + protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException + { String path = request.getRequestURI(); - return Arrays.stream(excludePath).anyMatch(path::startsWith); - + return !path.startsWith("/api"); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index bc1b584..dcf2eb3 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ academ: - version: "v1.2.0-alpha" + version: "v1.2.1-alpha" spring: