Search in sources :

Example 1 with FeatureContextImpl

use of org.apache.cxf.jaxrs.impl.FeatureContextImpl 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));
    }
}
Also used : FeatureContextImpl(org.apache.cxf.jaxrs.impl.FeatureContextImpl) Configuration(javax.ws.rs.core.Configuration) Feature(javax.ws.rs.core.Feature) HashSet(java.util.HashSet)

Example 2 with FeatureContextImpl

use of org.apache.cxf.jaxrs.impl.FeatureContextImpl in project cxf by apache.

the class ServerProviderFactory method createServerFeatureContext.

private FeatureContext createServerFeatureContext() {
    final FeatureContextImpl featureContext = new FeatureContextImpl();
    final ServerConfigurableFactory factory = getBus().getExtension(ServerConfigurableFactory.class);
    final Configurable<FeatureContext> configImpl = (factory == null) ? new ServerFeatureContextConfigurable(featureContext) : factory.create(featureContext);
    featureContext.setConfigurable(configImpl);
    if (application != null) {
        Map<String, Object> appProps = application.getProvider().getProperties();
        for (Map.Entry<String, Object> entry : appProps.entrySet()) {
            configImpl.property(entry.getKey(), entry.getValue());
        }
    }
    return featureContext;
}
Also used : FeatureContextImpl(org.apache.cxf.jaxrs.impl.FeatureContextImpl) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FeatureContext(javax.ws.rs.core.FeatureContext)

Aggregations

FeatureContextImpl (org.apache.cxf.jaxrs.impl.FeatureContextImpl)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Configuration (javax.ws.rs.core.Configuration)1 Feature (javax.ws.rs.core.Feature)1 FeatureContext (javax.ws.rs.core.FeatureContext)1