
์ด๋ฒ ๊ฐ์ธ ๊ณผ์ ๋ ์์ ๋ฅผ ๊ฐ์ ธ์
์ฝ๋๋ฅผ ๊ฐ์ ํ๊ณ , ํ
์คํธ ์ฝ๋๋ฅผ ์์ฑํด๋ณด๊ณ , ๋ฆฌํฉํฐ๋ง ํด๋ณด๋ ๊ณผ์ ์๋ค
โ๏ธ ๊ฐ๋ฐ ํ๊ฒฝ
- Java: 17
- JDK: 17.0.1
- IDE: IntelliJ
- Spring Frame Work : 3.4.4
- API ํ ์คํธ ๋๊ตฌ : postman
@Transactional public SignupResponse signup(SignupRequest signupRequest) { if (userRepository.existsByEmail(signupRequest.getEmail())) { throw new InvalidRequestException("์ด๋ฏธ ์กด์ฌํ๋ ์ด๋ฉ์ผ์ ๋๋ค."); } // ๐ก ์์ ํ ์์น String encodedPassword = passwordEncoder.encode(signupRequest.getPassword()); //if (userRepository.existsByEmail(signupRequest.getEmail())) { // throw new InvalidRequestException("์ด๋ฏธ ์กด์ฌํ๋ ์ด๋ฉ์ผ์ ๋๋ค."); //} ๊ธฐ์กด ์์น UserRole userRole = UserRole.of(signupRequest.getUserRole()); ...
if (!HttpStatus.OK.equals(responseEntity.getStatusCode())) { throw new ServerException("๋ ์จ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋๋ฐ ์คํจํ์ต๋๋ค. ์ํ ์ฝ๋: " + responseEntity.getStatusCode()); if (weatherArray == null || weatherArray.length == 0) { throw new ServerException("๋ ์จ ๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค."); } }
UserService ํด๋์ค
if (userChangePasswordRequest.getNewPassword().length() < 8 || !userChangePasswordRequest.getNewPassword().matches(".*\\d.*") || !userChangePasswordRequest.getNewPassword().matches(".*[A-Z].*")) { throw new InvalidRequestException("์ ๋น๋ฐ๋ฒํธ๋ 8์ ์ด์์ด์ด์ผ ํ๊ณ , ์ซ์์ ๋๋ฌธ์๋ฅผ ํฌํจํด์ผ ํฉ๋๋ค."); }UserChangePasswordRequest ํด๋์ค
@NotBlank @Pattern(regexp = "^(?=.*[0-9])(?=.*[A-Z])[A-Za-z\\d]{9,}$", message = "์ ๋น๋ฐ๋ฒํธ๋ 8์ ์ด์์ด์ด์ผ ํ๊ณ , ์ซ์์ ๋๋ฌธ์๋ฅผ ํฌํจํด์ผ ํฉ๋๋ค.") private String newPassword;
๊ธฐ์กด fetch join์ ์ฌ์ฉํด ์ฐ๊ด๋ ๋ฐ์ดํฐ๋ฅผ ์ฆ์ ๋ก๋ฉ์์ JPA์
@EntityGraph๋ก ๋ฆฌํฉํ ๋ง
โ๏ธ ๋ฌธ์
![]()
![]()
โ๏ธ ํด๊ฒฐ
passwordEncoder.matches()
โ๏ธ ๋ฌธ์ โ๏ธ ํด๊ฒฐ 1 2 3
Exception์ผ๋ก ๋ณ๊ฒฝํด ํ
์คํธ ์ฝ๋ ์คํ์ ์ฑ๊ณตํ๋๋ก ์์ ํ๋คInterceptor์ AOP๋ฅผ ํ์ฉํ API ๋ก๊น
์์ด ๋ฐฉ๋ํด์ ๋ฐ๋ก ์ผ๋ค..๐คฏ


@Around๋ฅผ ์ฌ์ฉํด ์ด๋๋ฏผ API ์คํ ์ ํ์ ๋ก๊น
RequestBody), ์๋ต ๋ณธ๋ฌธ (ResponseBody)Logger ํด๋์ค ํ์ฉ

โ๏ธ ์ด๋ ค์ ๋์ + ๋ฐฐ์ด์
- ๋ณธ๋ฌธ์ JSON์ผ๋ก ๋ถ๋ฌ์ฌ ๊ฒ
request.getInputStream()๋ฑ์ผ๋ก๋ ํ ๋ฒ๋ง ์ฝ์ ์ ์์- Tomcat์ด ๋จผ์ ์ฝ์ผ๋ฉด ๋ฐ๋๋ null๋ก ๋์ด
- ํด๊ฒฐ์ฑ :
ContentCachingRequestWrapper๋ฅผ ํํฐ๋ก ๊ฐ์ธ ์์ฒญ ๋ฐ๋๋ฅผ ์บ์ฑ
- ์ ํํฐ๋ฅผ ๋ง๋ค์ด์ผ ํ๋๊ฐ?
- AOP๋ ์ผ๋ฐ ํด๋์ค์์๋ ์ด๋ฏธ Tomcat์ด ์ฝ์ ๋ค๋ผ ๊ฐ์ธ๋ ๋ฌด์ฉ์ง๋ฌผ
- ํํฐ๋ก ๊ฐ์ฅ ๋จผ์ ์์ฒญ์ ๊ฐ๋ก์ฑ๊ณ ๊ฐ์ธ์ผ ์ดํ AOP์์ ๊บผ๋ด ์ฝ์ ์ ์์
- ๊ทธ๋์
OncePerRequestFilter๋ฅผ ๊ตฌํํ ํํฐ๋ก ์ง์ ๊ฐ์
- ์บ์ฑํด์ ๊ฐ์ธ์ ธ ์๋์ง
instanceof๋ก ํ์ธ
request๊ฐ ๋ด๊ฐ ๊ฐ์ผContentCachingRequestWrapper๊ฐ์ฒด์ธ์ง ์ฒดํฌํด์ผ ํจ- ๊ทธ๋ ์ง ์์ผ๋ฉด
getContentAsByteArray()ํธ์ถ ์์ฒด๊ฐ ๋ถ๊ฐ๋ฅinstanceof๊ฒ์ฌ ํ โ ๋ฐ์ดํธ ๋ฐฐ์ด โ ๋ฌธ์์ด ๋ณํ โ ๋ก๊น
๊ธ์์ ๋ค๊ธํจ์ด ๋๊ปด์ง๋ค์