CorsFilter extends AbstractFilter { @Override public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, allowedOriginDomain); response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, ALLOWED_METHODS); response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, ALLOWED_HEADERS); chain.doFilter(request, response); } CorsFilter(String allowedOriginDomain); @Override void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain);  }
@Test public void testCorsSupport() throws IOException, ServletException { CorsFilter corsFilter = new CorsFilter(DUMMY_ALLOWED_ORIGIN_DOMAIN); response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, DUMMY_ALLOWED_ORIGIN_DOMAIN); response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, CorsFilter.ALLOWED_METHODS); response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, CorsFilter.ALLOWED_HEADERS); chain.doFilter(request, response); replay(response); corsFilter.doFilter(request, response, chain); }