Search in sources :

Example 56 with Configuration

use of javax.ws.rs.core.Configuration in project graylog2-server by Graylog2.

the class PrefixAddingModelProcessor method processResourceModel.

@Override
public ResourceModel processResourceModel(ResourceModel model, Configuration config) {
    // Create new resource model.
    final ResourceModel.Builder resourceModelBuilder = new ResourceModel.Builder(false);
    for (final Resource resource : model.getResources()) {
        for (Class<?> handlerClass : resource.getHandlerClasses()) {
            final HideOnCloud hideOnCloud = handlerClass.getAnnotation(HideOnCloud.class);
            if (hideOnCloud != null && configuration.isCloud()) {
                break;
            }
            final String packageName = handlerClass.getPackage().getName();
            final Optional<String> packagePrefix = packagePrefixes.entrySet().stream().filter(entry -> packageName.startsWith(entry.getKey())).sorted((o1, o2) -> -o1.getKey().compareTo(o2.getKey())).map(Map.Entry::getValue).findFirst();
            if (packagePrefix.isPresent()) {
                final String prefixedPath = prefixPath(packagePrefix.get(), resource.getPath());
                final Resource newResource = Resource.builder(resource).path(prefixedPath).build();
                resourceModelBuilder.addResource(newResource);
            } else {
                resourceModelBuilder.addResource(resource);
            }
        }
    }
    return resourceModelBuilder.build();
}
Also used : HideOnCloud(org.graylog2.shared.rest.HideOnCloud) Provider(javax.ws.rs.ext.Provider) ImmutableMap(com.google.common.collect.ImmutableMap) Configuration(javax.ws.rs.core.Configuration) Map(java.util.Map) ResourceModel(org.glassfish.jersey.server.model.ResourceModel) Optional(java.util.Optional) ModelProcessor(org.glassfish.jersey.server.model.ModelProcessor) Resource(org.glassfish.jersey.server.model.Resource) Resource(org.glassfish.jersey.server.model.Resource) ResourceModel(org.glassfish.jersey.server.model.ResourceModel) HideOnCloud(org.graylog2.shared.rest.HideOnCloud) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

Configuration (javax.ws.rs.core.Configuration)56 Test (org.junit.Test)28 MinijaxTest (org.minijax.test.MinijaxTest)17 FeatureContext (javax.ws.rs.core.FeatureContext)7 Client (javax.ws.rs.client.Client)5 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)4 Map (java.util.Map)3 ClientRequestFilter (javax.ws.rs.client.ClientRequestFilter)3 ClientResponseFilter (javax.ws.rs.client.ClientResponseFilter)3 ContainerRequestFilter (javax.ws.rs.container.ContainerRequestFilter)3 Feature (javax.ws.rs.core.Feature)3 NewCookie (javax.ws.rs.core.NewCookie)3 List (java.util.List)2 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)2 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)2 AbstractBinder (org.glassfish.jersey.internal.inject.AbstractBinder)2 LocalResteasyProviderFactory (org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory)2 ResteasyJackson2Provider (org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider)2 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)2 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1