public void run(final SingularityConfiguration config, final Environment environment) {
if (!config.isEnableCorsFilter()) {
return;
}
final Filter corsFilter = new CrossOriginFilter();
final FilterConfig corsFilterConfig = new FilterConfig() {
@Override
public String getFilterName() {
return FILTER_NAME;
}
@Override
public ServletContext getServletContext() {
return null;
}
@Override
public String getInitParameter(final String name) {
return null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return Iterators.asEnumeration(Collections.<String>emptyIterator());
}
};
try {
corsFilter.init(corsFilterConfig);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
environment.servlets().addFilter(FILTER_NAME, corsFilter).addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");