code: 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());
          }
      }
docs: Apply CORS filter on request
  @param requestContext request context
  @param predicate must return {@code true} if the input origin is allowed, else {@code false}.