use of javax.ws.rs.core.Configuration in project minijax by minijax.
the class SecurityTest method testCookieSessionNotFound.
@Test
public void testCookieSessionNotFound() {
final String cookie = IdUtils.create().toString();
final SecurityDao dao = mock(SecurityDao.class);
final Configuration config = mock(Configuration.class);
final Security<User> security = new Security<>(dao, config, null, cookie);
assertFalse(security.isLoggedIn());
assertNull(security.getUserPrincipal());
}
use of javax.ws.rs.core.Configuration in project cxf by apache.
the class JAXRSClientFactoryBean method applyFeatures.
protected void applyFeatures(AbstractClient client) {
if (getFeatures() != null) {
getFeatures().forEach(feature -> {
feature.initialize(client.getConfiguration(), getBus());
});
}
// Process JAX-RS features which are passed through as providers
final Set<Object> providers = new HashSet<>();
for (final Object provider : getProviders()) {
if (provider instanceof Feature) {
final Feature feature = (Feature) provider;
final FeatureContextImpl context = new FeatureContextImpl();
final Configurable<?> configurable = getConfigurableFor(context);
final Configuration configuration = configurable.getConfiguration();
final Set<Object> registered = configuration.getInstances();
if (!configuration.isRegistered(feature)) {
configurable.register(feature);
// Disregarding if the feature is enabled or disabled, register only newly added providers,
// excluding pre-existing ones and the feature instance itself.
final Set<Object> added = new HashSet<Object>(configuration.getInstances());
added.remove(feature);
added.removeAll(registered);
providers.addAll(added);
}
}
}
if (!providers.isEmpty()) {
setProviders(Arrays.asList(providers));
}
}
use of javax.ws.rs.core.Configuration in project cxf by apache.
the class ServerProviderFactory method setProviders.
@SuppressWarnings("unchecked")
@Override
protected void setProviders(boolean custom, boolean busGlobal, Object... providers) {
List<Object> allProviders = new LinkedList<>();
for (Object p : providers) {
if (p instanceof Feature) {
FeatureContext featureContext = createServerFeatureContext();
Feature feature = (Feature) p;
injectApplicationIntoFeature(feature);
feature.configure(featureContext);
Configuration cfg = featureContext.getConfiguration();
for (Object featureProvider : cfg.getInstances()) {
Map<Class<?>, Integer> contracts = cfg.getContracts(featureProvider.getClass());
if (contracts != null && !contracts.isEmpty()) {
Class<?> providerCls = ClassHelper.getRealClass(getBus(), featureProvider);
allProviders.add(new FilterProviderInfo<Object>(featureProvider.getClass(), providerCls, featureProvider, getBus(), getFilterNameBindings(getBus(), featureProvider), false, contracts));
} else {
allProviders.add(featureProvider);
}
}
} else {
allProviders.add(p);
}
}
List<ProviderInfo<ContainerRequestFilter>> postMatchRequestFilters = new LinkedList<>();
List<ProviderInfo<ContainerResponseFilter>> postMatchResponseFilters = new LinkedList<>();
List<ProviderInfo<? extends Object>> theProviders = prepareProviders(custom, busGlobal, allProviders.toArray(), application);
super.setCommonProviders(theProviders, RuntimeType.SERVER);
for (ProviderInfo<? extends Object> provider : theProviders) {
Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider.getProvider());
// Check if provider is constrained to server
if (!constrainedTo(providerCls, RuntimeType.SERVER)) {
continue;
}
if (filterContractSupported(provider, providerCls, ContainerRequestFilter.class)) {
addContainerRequestFilter(postMatchRequestFilters, (ProviderInfo<ContainerRequestFilter>) provider);
}
if (filterContractSupported(provider, providerCls, ContainerResponseFilter.class)) {
postMatchResponseFilters.add((ProviderInfo<ContainerResponseFilter>) provider);
}
if (DynamicFeature.class.isAssignableFrom(providerCls)) {
// TODO: review the possibility of DynamicFeatures needing to have Contexts injected
Object feature = provider.getProvider();
dynamicFeatures.add((DynamicFeature) feature);
}
if (filterContractSupported(provider, providerCls, ExceptionMapper.class)) {
addProviderToList(exceptionMappers, provider);
}
}
Collections.sort(preMatchContainerRequestFilters, new BindingPriorityComparator(ContainerRequestFilter.class, true));
mapInterceptorFilters(postMatchContainerRequestFilters, postMatchRequestFilters, ContainerRequestFilter.class, true);
mapInterceptorFilters(containerResponseFilters, postMatchResponseFilters, ContainerResponseFilter.class, false);
injectContextProxies(exceptionMappers, postMatchContainerRequestFilters.values(), preMatchContainerRequestFilters, containerResponseFilters.values());
}
use of javax.ws.rs.core.Configuration in project cxf by apache.
the class ConfigurationImplTest method testChecksConstrainedToAnnotationDuringRegistration.
@Test
public void testChecksConstrainedToAnnotationDuringRegistration() {
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(ContainerResponseFilterImpl.class);
assertEquals(0, config.getInstances().size());
for (String message : handler.messages) {
if (message.startsWith("WARN") && message.contains("Null, empty or invalid contracts specified")) {
// success
return;
}
}
}
fail("did not log expected message");
}
use of javax.ws.rs.core.Configuration in project cxf by apache.
the class ConfigurationImplTest method testFeatureDisabledInstance.
@Test
public void testFeatureDisabledInstance() {
FeatureContextImpl featureContext = new FeatureContextImpl();
Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
featureContext.setConfigurable(configurable);
Feature feature = new DisablableFeature();
featureContext.register(feature);
Configuration config = configurable.getConfiguration();
assertFalse(config.isEnabled(feature));
}
Aggregations