Skip to content

Commit

Permalink
[#43] refactor: String content > MediaType 상수 변환
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyoungchoi95 committed Sep 13, 2021
1 parent bf1cd7e commit 7d56007
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

@Component
public class JwtAuthenticationEntiyPoint implements AuthenticationEntryPoint {

private static final String CONTENT_TYPE = "application/json";

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException {
response.setContentType(CONTENT_TYPE);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

response.getWriter().write(ErrorResponse.toJson(authException));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

Expand All @@ -17,8 +18,6 @@ public class JwtExceptionFilter extends OncePerRequestFilter {

private final Logger log = LoggerFactory.getLogger(getClass());

private static final String CONTENT_TYPE = "application/json";

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
Expand All @@ -32,7 +31,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
}

private void sendErrorMessage(HttpServletResponse response, JwtException e) throws IOException {
response.setContentType(CONTENT_TYPE);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setStatus(e.getHttpStatusValue());

response.getWriter().write(ErrorResponse.toJson(e));
Expand Down

0 comments on commit 7d56007

Please sign in to comment.