public static void filterRequest ( ContainerRequestContext requestContext , Predicate < String > predicate ) { //NOT a CORS request String requestOrigin = requestContext . getHeaderString ( Headers . ORIGIN ) ; if ( requestOrigin == null ) { return ; } if ( ! predicate . test ( requestOrigin ) ) { requestContext . abortWith ( Response . status ( Response . Status . BAD_REQUEST ) . build ( ) ) ; return ; } //It is a CORS pre-flight request, there is no route for it, just return 200 if ( requestContext . getMethod ( ) . equalsIgnoreCase ( HttpMethod . OPTIONS ) ) { requestContext . abortWith ( Response . status ( Response . Status . OK ) . build ( ) ) ; } }
Apply CORS filter on request