Exception : PreFlightHandler can not casting

Spring Interceptor에서 PreFlight Request (CORS 인식을 위한 OPTIONS 요청)에 대해서 HandlerMethod로 케스팅 한 경우 발생.
해결 방법은 instanceof로 체크 하면 됨
----

관련 자료)

PreFlightHandler 클래스 

private class PreFlightHandler implements HttpRequestHandler {
private final CorsConfiguration config;
public PreFlightHandler(CorsConfiguration config) {
this.config = config;
}
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
corsProcessor.processRequest(this.config, request, response);
}
}

PreFlightHandler를 사용하는 메소드

AbstractHandlerMapping.getCorsHandlerExecutionChain

Update the HandlerExecutionChain for CORS-related handling.
For pre-flight requests, the default implementation replaces the selected handler with a simple HttpRequestHandler that invokes the configured setCorsProcessor(org.springframework.web.cors.CorsProcessor).
For actual requests, the default implementation inserts a HandlerInterceptor that makes CORS-related checks and adds CORS headers.

pre-flight requests는 무엇인가?

A CORS preflight request is a CORS request that checks to see if the CORS protocol is understood and a server is aware using specific methods and headers.
It is an OPTIONS request, using three HTTP request headers: Access-Control-Request-MethodAccess-Control-Request-Headers, and the Origin header.
A preflight request is automatically issued by a browser and in normal cases, front-end developers don't need to craft such requests themselves. It appears when request is qualified as "to be preflighted" and ommited for simple requests.
For example, a client might be asking a server if it would allow a DELETE request, before sending a DELETE request, by using a preflight request:

댓글

이 블로그의 인기 게시물

Spring Batch - JobParameters Default Value 만들기

Hsqldb Server 재기동 시 오류