Search in sources :

Example 11 with Configuration

use of javax.ws.rs.core.Configuration in project tomee by apache.

the class Contexts method bind.

/**
     * Using a set ensures we don't set the thread local twice or more,
     * there may be super classes with injection points of identical types
     * <p/>
     * Also allows us to get context references from other sources such as interceptors
     *
     * @param exchange Exchange
     * @param types    Collection
     */
public static void bind(final Exchange exchange, final Collection<Class<?>> types) {
    // used in lazy mode by RESTResourceFinder if cdi beans uses @Context, === initThreadLocal
    EXCHANGE.set(exchange);
    CdiAppContextsService.pushRequestReleasable(CleanUpThreadLocal.INSTANCE);
    for (final Class<?> type : types) {
        if (Request.class.equals(type)) {
            final Request binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Request.class);
            ThreadLocalContextManager.REQUEST.set(binding);
        } else if (UriInfo.class.equals(type)) {
            final UriInfo binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, UriInfo.class);
            ThreadLocalContextManager.URI_INFO.set(binding);
        } else if (HttpHeaders.class.equals(type)) {
            final HttpHeaders binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpHeaders.class);
            ThreadLocalContextManager.HTTP_HEADERS.set(binding);
        } else if (SecurityContext.class.equals(type)) {
            final SecurityContext binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, SecurityContext.class);
            ThreadLocalContextManager.SECURITY_CONTEXT.set(binding);
        } else if (ContextResolver.class.equals(type)) {
            final ContextResolver<?> binding = JAXRSUtils.createContextValue(exchange.getInMessage(), type, ContextResolver.class);
            ThreadLocalContextManager.CONTEXT_RESOLVER.set(binding);
        } else if (Providers.class.equals(type)) {
            final Providers providers = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Providers.class);
            ThreadLocalContextManager.PROVIDERS.set(providers);
        } else if (ServletRequest.class.equals(type)) {
            ServletRequest servletRequest = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ServletRequest.class);
            if (servletRequest == null) {
                // probably the case with CXF
                servletRequest = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpServletRequest.class);
            }
            ThreadLocalContextManager.SERVLET_REQUEST.set(servletRequest);
        } else if (HttpServletRequest.class.equals(type)) {
            final HttpServletRequest httpServletRequest = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpServletRequest.class);
            ThreadLocalContextManager.HTTP_SERVLET_REQUEST.set(httpServletRequest);
        } else if (HttpServletResponse.class.equals(type)) {
            final HttpServletResponse httpServletResponse = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpServletResponse.class);
            ThreadLocalContextManager.HTTP_SERVLET_RESPONSE.set(httpServletResponse);
        } else if (ServletConfig.class.equals(type)) {
            final ServletConfig servletConfig = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ServletConfig.class);
            ThreadLocalContextManager.SERVLET_CONFIG.set(servletConfig);
        } else if (Configuration.class.equals(type)) {
            final Configuration config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Configuration.class);
            ThreadLocalContextManager.CONFIGURATION.set(config);
        } else if (ResourceInfo.class.equals(type)) {
            final ResourceInfo config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ResourceInfo.class);
            ThreadLocalContextManager.RESOURCE_INFO.set(config);
        } else if (ResourceContext.class.equals(type)) {
            final ResourceContext config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ResourceContext.class);
            ThreadLocalContextManager.RESOURCE_CONTEXT.set(config);
        } else {
            final Message message = exchange.getInMessage();
            final ContextProvider<?> provider = ProviderFactory.getInstance(message).createContextProvider(type, message);
            if (provider != null) {
                final Object value = provider.createContext(message);
                Map<String, Object> map = ThreadLocalContextManager.OTHERS.get();
                if (map == null) {
                    map = new HashMap<>();
                    ThreadLocalContextManager.OTHERS.set(map);
                }
                map.put(type.getName(), value);
            }
        }
    }
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) ResourceInfo(javax.ws.rs.container.ResourceInfo) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ResourceContext(javax.ws.rs.container.ResourceContext) Configuration(javax.ws.rs.core.Configuration) Message(org.apache.cxf.message.Message) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) Request(javax.ws.rs.core.Request) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) Providers(javax.ws.rs.ext.Providers) HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityContext(javax.ws.rs.core.SecurityContext) UriInfo(javax.ws.rs.core.UriInfo)

Example 12 with Configuration

use of javax.ws.rs.core.Configuration in project jersey by jersey.

the class ServerFiltersAutoDiscoverable method configure.

@Override
public void configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();
    // UriConnegFilter.
    final Object languageMappings = config.getProperty(ServerProperties.LANGUAGE_MAPPINGS);
    final Object mediaTypesMappings = config.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS);
    if (!config.isRegistered(UriConnegFilter.class) && (languageMappings != null || mediaTypesMappings != null)) {
        context.register(UriConnegFilter.class);
    }
}
Also used : Configuration(javax.ws.rs.core.Configuration)

Example 13 with Configuration

use of javax.ws.rs.core.Configuration in project jersey by jersey.

the class ClientConfigTest method testGetFeatures.

/**
     * Copied from DefaultConfigTest.
     */
@Test
public void testGetFeatures() {
    final EmptyFeature emptyFeature = new EmptyFeature();
    final UnconfigurableFeature unconfigurableFeature = new UnconfigurableFeature();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(emptyFeature);
    clientConfig.register(unconfigurableFeature);
    // Features are registered at the time of provider bindings.
    final JerseyClient jerseyClient = new JerseyClient(clientConfig, (UnsafeValue<SSLContext, IllegalStateException>) null, null);
    clientConfig = jerseyClient.getConfiguration();
    clientConfig.getRuntime();
    final Configuration runtimeConfig = clientConfig.getRuntime().getConfig();
    assertTrue(runtimeConfig.isEnabled(emptyFeature));
}
Also used : Configuration(javax.ws.rs.core.Configuration) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.Test)

Example 14 with Configuration

use of javax.ws.rs.core.Configuration in project jersey by jersey.

the class SecurityEntityFilteringFeature method configure.

@Override
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();
    if (!config.isRegistered(SecurityEntityProcessor.class)) {
        // RolesAllowed feature.
        if (!config.isRegistered(RolesAllowedDynamicFeature.class)) {
            context.register(RolesAllowedDynamicFeature.class);
        }
        // Binder (FilteringObjectProvider/FilteringGraphTransformer).
        if (!config.isRegistered(EntityFilteringBinder.class)) {
            context.register(new EntityFilteringBinder());
        }
        // Entity Processors.
        context.register(SecurityEntityProcessor.class);
        if (!config.isRegistered(DefaultEntityProcessor.class)) {
            context.register(DefaultEntityProcessor.class);
        }
        // Scope Providers.
        context.register(SecurityScopeResolver.class);
        if (RuntimeType.SERVER.equals(config.getRuntimeType())) {
            context.register(SecurityServerScopeResolver.class);
        }
        // Scope Resolver.
        if (RuntimeType.SERVER == config.getRuntimeType()) {
            context.register(SecurityServerScopeProvider.class);
        } else {
            context.register(CommonScopeProvider.class);
        }
        return true;
    }
    return false;
}
Also used : Configuration(javax.ws.rs.core.Configuration) RolesAllowedDynamicFeature(org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature)

Example 15 with Configuration

use of javax.ws.rs.core.Configuration in project jersey by jersey.

the class SelectableEntityFilteringFeature method configure.

@Override
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();
    if (!config.isRegistered(SelectableEntityProcessor.class)) {
        // register EntityFilteringFeature
        if (!config.isRegistered(EntityFilteringFeature.class)) {
            context.register(EntityFilteringFeature.class);
        }
        // Entity Processors.
        context.register(SelectableEntityProcessor.class);
        // Scope Resolver.
        context.register(SelectableScopeResolver.class);
        return true;
    }
    return true;
}
Also used : Configuration(javax.ws.rs.core.Configuration)

Aggregations

Configuration (javax.ws.rs.core.Configuration)21 Map (java.util.Map)2 SSLContext (javax.net.ssl.SSLContext)2 ServletContext (javax.servlet.ServletContext)2 AbstractBinder (org.glassfish.jersey.internal.inject.AbstractBinder)2 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 Channel (io.netty.channel.Channel)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)1 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)1 HttpChunkedInput (io.netty.handler.codec.http.HttpChunkedInput)1 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)1 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 HttpProxyHandler (io.netty.handler.proxy.HttpProxyHandler)1 JdkSslContext (io.netty.handler.ssl.JdkSslContext)1