CorsFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { if (isEnabled && !processPreflight(requestContext, responseContext)) { processRequest(requestContext, responseContext); } } CorsFilter(); @Override void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext);  }
@Test public void notCorsOptionsRequestTest() throws IOException { setupRequestContext(HTTP_OPTIONS_METHOD, null, null, null); setupResponseContext(null); filter.filter(requestContext, responseContext); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_METHODS_HEADER); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_HEADERS); assertResponseWithoutHeader(VARY_HEADER); }
@Test public void notCorsRealRequestTest() throws IOException { setupRequestContext(HTTP_GET_METHOD, null, null, null); setupResponseContext(null); filter.filter(requestContext, responseContext); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_METHODS_HEADER); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_HEADERS); assertResponseWithoutHeader(VARY_HEADER); }
@Test public void corsPreflightRequestTest() throws IOException { setupRequestContext(HTTP_OPTIONS_METHOD, ECLIPSE_ORIGIN, HTTP_GET_METHOD, REQUEST_HEADERS); setupResponseContext(VARY_HEADER_VALUE); filter.filter(requestContext, responseContext); assertResponseHasHeader(ACCESS_CONTROL_ALLOW_METHODS_HEADER, ACCEPTED_HTTP_METHODS); assertResponseHasHeader(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, ECLIPSE_ORIGIN); assertResponseHasHeader(ACCESS_CONTROL_ALLOW_HEADERS, CONTENT_TYPE_HEADER); assertResponseHasHeader(VARY_HEADER, VARY_HEADER_VALUE + "," + ORIGIN_HEADER); }
@Test public void partialCorsPreflightRequestTest() throws IOException { setupRequestContext(HTTP_OPTIONS_METHOD, ECLIPSE_ORIGIN, null, REQUEST_HEADERS); setupResponseContext(VARY_HEADER_VALUE); filter.filter(requestContext, responseContext); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_METHODS_HEADER); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_HEADERS); assertResponseHasHeader(VARY_HEADER, VARY_HEADER_VALUE); }
@Test public void corsPreflightRequestWithoutRequestHeadersTest() throws IOException { setupRequestContext(HTTP_OPTIONS_METHOD, ECLIPSE_ORIGIN, HTTP_GET_METHOD, null); setupResponseContext(VARY_HEADER_VALUE); filter.filter(requestContext, responseContext); assertResponseHasHeader(ACCESS_CONTROL_ALLOW_METHODS_HEADER, ACCEPTED_HTTP_METHODS); assertResponseHasHeader(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, ECLIPSE_ORIGIN); assertResponseHasHeader(ACCESS_CONTROL_ALLOW_HEADERS, CONTENT_TYPE_HEADER); assertResponseHasHeader(VARY_HEADER, VARY_HEADER_VALUE + "," + ORIGIN_HEADER); }
@Test public void corsRealRequestTest() throws IOException { setupRequestContext(HTTP_GET_METHOD, ECLIPSE_ORIGIN, null, null); setupResponseContext(null); filter.filter(requestContext, responseContext); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_METHODS_HEADER); assertResponseHasHeader(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, ECLIPSE_ORIGIN); assertResponseWithoutHeader(ACCESS_CONTROL_ALLOW_HEADERS); assertResponseWithoutHeader(VARY_HEADER); }