@SuppressWarnings("unchecked")
private ResourceConfig buildResourceConfig(final boolean enableGzip,
final boolean enableCors,
final Set<Resource> additionalResources) {
ResourceConfig rc = new ResourceConfig()
.property(NettyContainer.PROPERTY_BASE_URI, configuration.getRestListenUri())
.registerClasses(
JacksonPropertyExceptionMapper.class,
AnyExceptionClassMapper.class,
WebApplicationExceptionMapper.class)
.register(ObjectMapperProvider.class)
.register(JacksonFeature.class)
.registerFinder(new PackageNamesScanner(new String[]{
"org.graylog2.rest.resources",
"org.graylog2.radio.rest.resources",
"org.graylog2.shared.rest.resources"
}, true))
.registerResources(additionalResources);
for (Class<? extends ExceptionMapper> exceptionMapper : exceptionMappers) {
rc.registerClasses(exceptionMapper);
}
for (Class<? extends DynamicFeature> dynamicFeatureClass : dynamicFeatures) {
rc.registerClasses(dynamicFeatureClass);
}
for (Class<? extends ContainerResponseFilter> responseFilter : containerResponseFilters) {
rc.registerClasses(responseFilter);
}
if (enableGzip) {
EncodingFilter.enableFor(rc, GZipEncoder.class);
}
if (enableCors) {
LOG.info("Enabling CORS for REST API");
rc.register(CORSFilter.class);
}
if (LOG.isDebugEnabled()) {
rc.register(PrintModelProcessor.class);
}
return rc;
}