Search in sources :

Example 26 with Configuration

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

the class ConfigurationImplTest method testServerFilterContractsOnClientIsRejected.

@Test
public void testServerFilterContractsOnClientIsRejected() {
    try (ConfigurableImpl<Client> configurable = new ConfigurableImpl<>(createClientProxy(), RuntimeType.CLIENT)) {
        Configuration config = configurable.getConfiguration();
        configurable.register(TestFilter.class);
        Map<Class<?>, Integer> contracts = config.getContracts(TestFilter.class);
        assertTrue(contracts.containsKey(ClientRequestFilter.class));
        assertTrue(contracts.containsKey(ClientResponseFilter.class));
        assertFalse(contracts.containsKey(ContainerRequestFilter.class));
        assertFalse(contracts.containsKey(ContainerResponseFilter.class));
    }
}
Also used : ClientRequestFilter(javax.ws.rs.client.ClientRequestFilter) ContainerResponseFilter(javax.ws.rs.container.ContainerResponseFilter) Configuration(javax.ws.rs.core.Configuration) ClientResponseFilter(javax.ws.rs.client.ClientResponseFilter) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 27 with Configuration

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

the class SseEventSourceImpl method open.

@Override
public void open() {
    if (!tryChangeState(SseSourceState.CLOSED, SseSourceState.CONNECTING)) {
        throw new IllegalStateException("The SseEventSource is already in " + state.get() + " state");
    }
    // Create the executor for scheduling the reconnect tasks
    final Configuration configuration = target.getConfiguration();
    if (executor == null) {
        executor = (ScheduledExecutorService) configuration.getProperty("scheduledExecutorService");
        if (executor == null) {
            executor = Executors.newSingleThreadScheduledExecutor();
            managedExecutor = false;
        /* we manage lifecycle */
        }
    }
    final Object lastEventId = configuration.getProperty(HttpHeaders.LAST_EVENT_ID_HEADER);
    connect(lastEventId != null ? lastEventId.toString() : null);
}
Also used : Configuration(javax.ws.rs.core.Configuration)

Example 28 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 29 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 30 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)

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