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");
}
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));
}
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);
}
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;
}
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;
}
Aggregations