@Test public void testResponseFilter() throws IOException { CORSFilter filter = new CORSFilter(); ContainerRequestContext requestContext = Mockito.mock(ContainerRequestContext.class); ContainerResponseContext responseContext = Mockito.mock(ContainerResponseContext.class); MultivaluedMap<String, Object> headers = Mockito.mock(MultivaluedMap.class); Mockito.when(requestContext.getHeaderString(Headers.ORIGIN)).thenReturn(null); filter.filter(requestContext, responseContext); Mockito.verify(responseContext, Mockito.never()).getHeaders(); Mockito.when(requestContext.getHeaderString(Headers.ORIGIN)).thenReturn(ALLOWED_FOREIGN_ORIGIN); Mockito.when(requestContext.getMethod()).thenReturn("OPTIONS"); filter.filter(requestContext, responseContext); Mockito.verify(responseContext, Mockito.never()).getHeaders(); Mockito.when(requestContext.getHeaderString(Headers.ORIGIN)).thenReturn(ALLOWED_FOREIGN_ORIGIN); Mockito.when(requestContext.getMethod()).thenReturn("POST"); Mockito.when(requestContext.getProperty("access.denied")).thenReturn(true); filter.filter(requestContext, responseContext); Mockito.verify(responseContext, Mockito.never()).getHeaders(); Mockito.when(requestContext.getHeaderString(Headers.ORIGIN)).thenReturn(ALLOWED_FOREIGN_ORIGIN); Mockito.when(requestContext.getMethod()).thenReturn("POST"); Mockito.when(requestContext.getProperty("access.denied")).thenReturn(null); Mockito.when(responseContext.getHeaders()).thenReturn(headers); filter.filter(requestContext, responseContext); Mockito.verify(headers).putSingle(Headers.ACCESS_CONTROL_ALLOW_ORIGIN, ALLOWED_FOREIGN_ORIGIN); Mockito.verify(headers).putSingle(Headers.VARY, Headers.ORIGIN); Mockito.when(requestContext.getHeaderString(Headers.ORIGIN)).thenReturn("allowed.origin.com"); Mockito.when(requestContext.getMethod()).thenReturn("POST"); Mockito.when(requestContext.getProperty("access.denied")).thenReturn(null); Mockito.when(responseContext.getHeaders()).thenReturn(headers); filter.filter(requestContext, responseContext); Mockito.verify(headers).putSingle(Headers.ACCESS_CONTROL_ALLOW_ORIGIN, "allowed.origin.com"); Mockito.verify(headers, Mockito.times(2)).putSingle(Headers.VARY, Headers.ORIGIN); }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { String origin = getOrigin(requestContext); if (origin == null || requestContext.getMethod().equalsIgnoreCase(OPTIONS) || requestContext.getProperty(ACCESS_DENIED) != null) { return; } responseContext.getHeaders().putSingle(Headers.ACCESS_CONTROL_ALLOW_ORIGIN, origin); responseContext.getHeaders().putSingle(Headers.VARY, Headers.ORIGIN); }
CORSFilter implements ContainerResponseFilter, ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { String origin = getOrigin(requestContext); if (origin == null || requestContext.getMethod().equalsIgnoreCase(OPTIONS) || requestContext.getProperty(ACCESS_DENIED) != null) { return; } responseContext.getHeaders().putSingle(Headers.ACCESS_CONTROL_ALLOW_ORIGIN, origin); responseContext.getHeaders().putSingle(Headers.VARY, Headers.ORIGIN); } }
CORSFilter implements ContainerResponseFilter, ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { String origin = getOrigin(requestContext); if (origin == null || requestContext.getMethod().equalsIgnoreCase(OPTIONS) || requestContext.getProperty(ACCESS_DENIED) != null) { return; } responseContext.getHeaders().putSingle(Headers.ACCESS_CONTROL_ALLOW_ORIGIN, origin); responseContext.getHeaders().putSingle(Headers.VARY, Headers.ORIGIN); }  }
CORSFilter implements ContainerResponseFilter, ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { String origin = getOrigin(requestContext); if (origin == null || requestContext.getMethod().equalsIgnoreCase(OPTIONS) || requestContext.getProperty(ACCESS_DENIED) != null) { return; } responseContext.getHeaders().putSingle(Headers.ACCESS_CONTROL_ALLOW_ORIGIN, origin); responseContext.getHeaders().putSingle(Headers.VARY, Headers.ORIGIN); }  @Override void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext); @Override void filter(ContainerRequestContext requestContext); List<String> getAllowedOrigins(); }
CORSFilter implements ContainerResponseFilter, ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { String origin = getOrigin(requestContext); if (origin == null || requestContext.getMethod().equalsIgnoreCase(OPTIONS) || requestContext.getProperty(ACCESS_DENIED) != null) { return; } responseContext.getHeaders().putSingle(Headers.ACCESS_CONTROL_ALLOW_ORIGIN, origin); responseContext.getHeaders().putSingle(Headers.VARY, Headers.ORIGIN); }  @Override void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext); @Override void filter(ContainerRequestContext requestContext); List<String> getAllowedOrigins(); @Reference
	public ConfigurationManager configurationManager; }