Search in sources :

Example 51 with Configuration

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

the class ConfigurationImplTest method testInvalidConstraintOnProvider.

@Test
public void testInvalidConstraintOnProvider() {
    TestHandler handler = new TestHandler();
    LogUtils.getL7dLogger(ConfigurableImpl.class).addHandler(handler);
    try (ConfigurableImpl<Client> configurable = new ConfigurableImpl<>(createClientProxy(), RuntimeType.CLIENT)) {
        Configuration config = configurable.getConfiguration();
        configurable.register(ClientFilterConstrainedToServer.class);
        assertEquals(0, config.getInstances().size());
        for (String message : handler.messages) {
            if (message.startsWith("WARN") && message.contains("cannot be registered in ")) {
                // success
                return;
            }
        }
    }
    fail("did not log expected message");
}
Also used : Configuration(javax.ws.rs.core.Configuration) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 52 with Configuration

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

the class ConfigurationImplTest method testIsEnabledWithMultipleFeaturesOfSameType.

@Test
public void testIsEnabledWithMultipleFeaturesOfSameType() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    featureContext.register(new DisablableFeature());
    featureContext.register(new DisablableFeature());
    featureContext.register(new DisablableFeature());
    Configuration config = configurable.getConfiguration();
    assertEquals(3, config.getInstances().size());
    assertFalse(config.isEnabled(DisablableFeature.class));
    DisablableFeature enabledFeature = new DisablableFeature();
    enabledFeature.enabled = true;
    featureContext.register(enabledFeature);
    assertEquals(4, config.getInstances().size());
    assertTrue(config.isEnabled(DisablableFeature.class));
    featureContext.register(new DisablableFeature());
    assertEquals(5, config.getInstances().size());
    assertTrue(config.isEnabled(DisablableFeature.class));
}
Also used : Configuration(javax.ws.rs.core.Configuration) FeatureContext(javax.ws.rs.core.FeatureContext) Test(org.junit.Test)

Example 53 with Configuration

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

the class CxfTypeSafeClientBuilder method build.

@Override
public <T> T build(Class<T> aClass) {
    if (baseUri == null) {
        throw new IllegalStateException("baseUrl not set");
    }
    Validator.checkValid(aClass);
    RegisterProvider[] providers = aClass.getAnnotationsByType(RegisterProvider.class);
    Configuration config = configImpl.getConfiguration();
    if (providers != null) {
        for (RegisterProvider provider : providers) {
            if (!config.isRegistered(provider.value())) {
                if (provider.priority() == -1) {
                    register(provider.value());
                } else {
                    register(provider.value(), provider.priority());
                }
            }
        }
    }
    register(SseMessageBodyReader.class);
    listeners().forEach(l -> l.onNewClient(aClass, this));
    MicroProfileClientFactoryBean bean = new MicroProfileClientFactoryBean(configImpl, baseUri, aClass, executorService, secConfig);
    return bean.create(aClass);
}
Also used : Configuration(javax.ws.rs.core.Configuration) TLSConfiguration(org.apache.cxf.jaxrs.client.spec.TLSConfiguration) RegisterProvider(org.eclipse.microprofile.rest.client.annotation.RegisterProvider)

Example 54 with Configuration

use of javax.ws.rs.core.Configuration in project winery by eclipse.

the class JsonFeature method configure.

@Override
public boolean configure(FeatureContext featureContext) {
    featureContext.register(JacksonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
    final Configuration config = featureContext.getConfiguration();
    // Disables discoverability of org.glassfish.jersey.jackson.JacksonFeature
    featureContext.property(PropertiesHelper.getPropertyNameForRuntime(JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE);
    return true;
}
Also used : Configuration(javax.ws.rs.core.Configuration)

Example 55 with Configuration

use of javax.ws.rs.core.Configuration in project uavstack by uavorg.

the class FastJsonFeature method configure.

@Override
public boolean configure(final FeatureContext context) {
    try {
        final Configuration config = context.getConfiguration();
        final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class);
        // Other JSON providers registered.
        if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
            return false;
        }
        // Disable other JSON providers.
        context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE);
        // Register FastJson.
        if (!config.isRegistered(FastJsonProvider.class)) {
            context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
        }
    } catch (NoSuchMethodError e) {
    // skip
    }
    return true;
}
Also used : Configuration(javax.ws.rs.core.Configuration)

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