class 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) {
			// do nothing, either it isn't a cors request or an options call or already failed
			return;
		}
		responseContext.getHeaders().putSingle(Headers.ACCESS_CONTROL_ALLOW_ORIGIN, origin);
		responseContext.getHeaders().putSingle(Headers.VARY, Headers.ORIGIN);
	}

}