Search in sources :

Example 21 with Feature

use of org.apache.cxf.feature.Feature in project steve by RWTH-i5-IDSG.

the class OcppConfiguration method init.

@PostConstruct
public void init() {
    List<Interceptor<? extends Message>> interceptors = asList(new MessageIdInterceptor(), fromAddressInterceptor);
    List<Feature> logging = singletonList(LoggingFeatureProxy.INSTANCE.get());
    createOcppService(ocpp12Server, "/CentralSystemServiceOCPP12", interceptors, logging);
    createOcppService(ocpp15Server, "/CentralSystemServiceOCPP15", interceptors, logging);
    createOcppService(ocpp16Server, "/CentralSystemServiceOCPP16", interceptors, logging);
    // Just a dummy service to route incoming messages to the appropriate service version. This should be the last
    // one to be created, since in MediatorInInterceptor we go over created/registered services and build a map.
    // 
    List<Interceptor<? extends Message>> mediator = singletonList(new MediatorInInterceptor(springBus()));
    createOcppService(ocpp12Server, CONFIG.getRouterEndpointPath(), mediator, Collections.emptyList());
}
Also used : Message(org.apache.cxf.message.Message) MessageIdInterceptor(de.rwth.idsg.steve.ocpp.soap.MessageIdInterceptor) MediatorInInterceptor(de.rwth.idsg.steve.ocpp.soap.MediatorInInterceptor) MessageIdInterceptor(de.rwth.idsg.steve.ocpp.soap.MessageIdInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) MediatorInInterceptor(de.rwth.idsg.steve.ocpp.soap.MediatorInInterceptor) Feature(org.apache.cxf.feature.Feature) PostConstruct(javax.annotation.PostConstruct)

Example 22 with Feature

use of org.apache.cxf.feature.Feature in project syncope by apache.

the class SyncopeClientFactoryBean method defaultRestClientFactoryBean.

protected JAXRSClientFactoryBean defaultRestClientFactoryBean() {
    JAXRSClientFactoryBean defaultRestClientFactoryBean = new JAXRSClientFactoryBean();
    defaultRestClientFactoryBean.setHeaders(new HashMap<>());
    if (StringUtils.isBlank(address)) {
        throw new IllegalArgumentException("Property 'address' is missing");
    }
    defaultRestClientFactoryBean.setAddress(address);
    if (StringUtils.isNotBlank(domain)) {
        defaultRestClientFactoryBean.getHeaders().put(RESTHeaders.DOMAIN, Collections.singletonList(domain));
    }
    defaultRestClientFactoryBean.setThreadSafe(true);
    defaultRestClientFactoryBean.setInheritHeaders(true);
    List<Feature> features = new ArrayList<>();
    features.add(new LoggingFeature());
    defaultRestClientFactoryBean.setFeatures(features);
    List<Object> providers = new ArrayList<>(4);
    providers.add(new DateParamConverterProvider());
    providers.add(getJaxbProvider());
    providers.add(getJsonProvider());
    providers.add(getExceptionMapper());
    defaultRestClientFactoryBean.setProviders(providers);
    return defaultRestClientFactoryBean;
}
Also used : DateParamConverterProvider(org.apache.syncope.common.rest.api.DateParamConverterProvider) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) ArrayList(java.util.ArrayList) Feature(org.apache.cxf.feature.Feature) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature)

Example 23 with Feature

use of org.apache.cxf.feature.Feature in project tomee by apache.

the class OSGIBusListener method registerBusFeatures.

private void registerBusFeatures() {
    ServiceReference<?>[] refs = getServiceReferences(defaultContext, Feature.class);
    for (ServiceReference<?> ref : refs) {
        if (!isPrivate(ref) && !isExcluded(ref)) {
            Feature feature = (Feature) defaultContext.getService(ref);
            bus.getFeatures().add(feature);
        }
    }
}
Also used : Feature(org.apache.cxf.feature.Feature) ServiceReference(org.osgi.framework.ServiceReference)

Example 24 with Feature

use of org.apache.cxf.feature.Feature in project tomee by apache.

the class CxfUtil method configureBus.

public static void configureBus() {
    if (USER_COUNT.incrementAndGet() > 1) {
        return;
    }
    final SystemInstance systemInstance = SystemInstance.get();
    final Bus bus = getBus();
    // ensure cxf classes are loaded from container to avoid conflicts with app
    if ("true".equalsIgnoreCase(systemInstance.getProperty("openejb.cxf.CxfContainerClassLoader", "true"))) {
        bus.setExtension(new CxfContainerClassLoader(), ClassLoader.class);
    }
    // activate jmx, by default isEnabled() == false in InstrumentationManagerImpl
    final boolean hasMonitoring = hasMonitoring(systemInstance);
    if (hasMonitoring || "true".equalsIgnoreCase(systemInstance.getProperty("openejb.cxf.jmx", "true"))) {
        final InstrumentationManager mgr = bus.getExtension(InstrumentationManager.class);
        if (InstrumentationManagerImpl.class.isInstance(mgr)) {
            // just to keep everything consistent
            bus.setExtension(LocalMBeanServer.get(), MBeanServer.class);
            final InstrumentationManagerImpl manager = InstrumentationManagerImpl.class.cast(mgr);
            manager.setEnabled(true);
            manager.setServer(LocalMBeanServer.get());
            try {
                // avoid to bother our nice logs
                LogUtils.getL7dLogger(InstrumentationManagerImpl.class).setLevel(Level.WARNING);
            } catch (final Throwable th) {
            // no-op
            }
            // failed when bus was constructed or even if passed we switch the MBeanServer
            manager.init();
        }
    }
    if (hasMonitoring) {
        new CounterRepository().setBus(bus);
    }
    final ServiceConfiguration configuration = new ServiceConfiguration(systemInstance.getProperties(), systemInstance.getComponent(OpenEjbConfiguration.class).facilities.services);
    final Collection<ServiceInfo> serviceInfos = configuration.getAvailableServices();
    Properties properties = configuration.getProperties();
    if (properties == null) {
        properties = new Properties();
    }
    final String featuresIds = properties.getProperty(BUS_PREFIX + FEATURES);
    if (featuresIds != null) {
        final List<Feature> features = createFeatures(serviceInfos, featuresIds);
        if (features != null) {
            features.addAll(bus.getFeatures());
            bus.setFeatures(features);
        }
    }
    final Properties busProperties = ServiceInfos.serviceProperties(serviceInfos, properties.getProperty(BUS_PREFIX + ENDPOINT_PROPERTIES));
    if (busProperties != null) {
        bus.getProperties().putAll(PropertiesHelper.map(busProperties));
    }
    configureInterceptors(bus, BUS_PREFIX, serviceInfos, configuration.getProperties());
    systemInstance.getProperties().setProperty(BUS_CONFIGURED_FLAG, "true");
    systemInstance.fireEvent(new BusCreated(bus));
}
Also used : Bus(org.apache.cxf.Bus) CounterRepository(org.apache.cxf.management.counters.CounterRepository) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) Properties(java.util.Properties) BusCreated(org.apache.openejb.server.cxf.transport.event.BusCreated) Feature(org.apache.cxf.feature.Feature) AbstractFeature(org.apache.cxf.feature.AbstractFeature) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) ServiceInfo(org.apache.openejb.assembler.classic.ServiceInfo) InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) SystemInstance(org.apache.openejb.loader.SystemInstance)

Example 25 with Feature

use of org.apache.cxf.feature.Feature in project tomee by apache.

the class CxfRsHttpListener method configureFactory.

private void configureFactory(final Collection<Object> givenAdditionalProviders, final ServiceConfiguration serviceConfiguration, final JAXRSServerFactoryBean factory, final WebBeansContext ctx, final Application application) {
    CxfUtil.configureEndpoint(factory, serviceConfiguration, CXF_JAXRS_PREFIX);
    boolean enforceCxfBvalMapper = false;
    if (ctx == null || !ctx.getBeanManagerImpl().isInUse()) {
        // activate bval
        boolean bvalActive = Boolean.parseBoolean(SystemInstance.get().getProperty("openejb.cxf.rs.bval.active", serviceConfiguration.getProperties().getProperty(CXF_JAXRS_PREFIX + "bval.active", "true")));
        if (factory.getFeatures() == null && bvalActive) {
            factory.setFeatures(new ArrayList<>());
        } else if (bvalActive) {
            // check we should activate it and user didn't configure it
            for (final Feature f : factory.getFeatures()) {
                if (BeanValidationFeature.class.isInstance(f)) {
                    bvalActive = false;
                    break;
                }
            }
            for (final Interceptor<?> i : factory.getInInterceptors()) {
                if (BeanValidationInInterceptor.class.isInstance(i)) {
                    bvalActive = false;
                    break;
                }
            }
            for (final Interceptor<?> i : factory.getOutInterceptors()) {
                if (BeanValidationOutInterceptor.class.isInstance(i)) {
                    bvalActive = false;
                    break;
                }
            }
        }
        if (bvalActive) {
            // bval doesn't need the actual instance so faking it to avoid to lookup the bean
            // todo: close the factory
            final BeanValidationProvider provider = new BeanValidationProvider();
            ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
            final Validator validator = validatorFactory.getValidator();
            final BeanValidationInInterceptor in = new JAXRSBeanValidationInInterceptor() {

                @Override
                protected Object getServiceObject(final Message message) {
                    return CxfRsHttpListener.this.getServiceObject(message);
                }
            };
            in.setProvider(provider);
            in.setServiceObject(FAKE_SERVICE_OBJECT);
            factory.getInInterceptors().add(in);
            final BeanValidationOutInterceptor out = new JAXRSBeanValidationOutInterceptor() {

                @Override
                protected Object getServiceObject(final Message message) {
                    return CxfRsHttpListener.this.getServiceObject(message);
                }

                @Override
                protected void handleValidation(final Message message, final Object resourceInstance, final Method method, final List<Object> arguments) {
                    final MethodDescriptor constraintsForMethod = validator.getConstraintsForClass(resourceInstance.getClass()).getConstraintsForMethod(method.getName(), method.getParameterTypes());
                    if (constraintsForMethod != null && constraintsForMethod.hasConstrainedReturnValue()) {
                        super.handleValidation(message, resourceInstance, method, arguments);
                    }
                }
            };
            out.setEnforceOnlyBeanConstraints(true);
            out.setProvider(provider);
            out.setServiceObject(FAKE_SERVICE_OBJECT);
            factory.getOutInterceptors().add(out);
            // and add a mapper to get back a 400 like for bval
            enforceCxfBvalMapper = true;
        }
    }
    final Collection<ServiceInfo> services = serviceConfiguration.getAvailableServices();
    final String staticSubresourceResolution = serviceConfiguration.getProperties().getProperty(CXF_JAXRS_PREFIX + STATIC_SUB_RESOURCE_RESOLUTION_KEY);
    if (staticSubresourceResolution != null) {
        factory.setStaticSubresourceResolution("true".equalsIgnoreCase(staticSubresourceResolution));
    }
    // resource comparator
    final String resourceComparator = serviceConfiguration.getProperties().getProperty(RESOURCE_COMPARATOR_KEY);
    if (resourceComparator != null) {
        try {
            ResourceComparator instance = (ResourceComparator) ServiceInfos.resolve(services, resourceComparator);
            if (instance == null) {
                instance = (ResourceComparator) Thread.currentThread().getContextClassLoader().loadClass(resourceComparator).newInstance();
            }
            factory.setResourceComparator(instance);
        } catch (final Exception e) {
            LOGGER.error("Can't create the resource comparator " + resourceComparator, e);
        }
    }
    // static resources
    final String staticResources = serviceConfiguration.getProperties().getProperty(STATIC_RESOURCE_KEY);
    if (staticResources != null) {
        final String[] resources = staticResources.split(",");
        for (final String r : resources) {
            final String trimmed = r.trim();
            if (!trimmed.isEmpty()) {
                staticResourcesList.add(Pattern.compile(trimmed));
            }
        }
    }
    // providers
    Set<String> providersConfig = null;
    {
        final String provider = serviceConfiguration.getProperties().getProperty(PROVIDERS_KEY);
        if (provider != null) {
            providersConfig = new HashSet<>();
            for (final String p : Arrays.asList(provider.split(","))) {
                providersConfig.add(p.trim());
            }
        }
        {
            if (GLOBAL_PROVIDERS != null) {
                if (providersConfig == null) {
                    providersConfig = new HashSet<>();
                }
                providersConfig.addAll(Arrays.asList(GLOBAL_PROVIDERS.split(",")));
            }
        }
    }
    // another property to configure the scanning of providers but this one is consistent with current cxf config
    // the other one is more generic but need another file
    final String key = CXF_JAXRS_PREFIX + "skip-provider-scanning";
    final boolean ignoreAutoProviders = "true".equalsIgnoreCase(SystemInstance.get().getProperty(key, serviceConfiguration.getProperties().getProperty(key, "false")));
    final List<Object> additionalProviders = new ArrayList<Object>(ignoreAutoProviders ? Collections.EMPTY_LIST : givenAdditionalProviders);
    for (final Class<?> clzz : application.getClasses()) {
        if (isProvider(clzz) && !additionalProviders.contains(clzz)) {
            additionalProviders.add(clzz);
        }
    }
    List<Object> providers = null;
    if (providersConfig != null) {
        providers = ServiceInfos.resolve(services, providersConfig.toArray(new String[providersConfig.size()]), OpenEJBProviderFactory.INSTANCE);
        if (providers != null && additionalProviders != null && !additionalProviders.isEmpty()) {
            providers.addAll(providers(serviceConfiguration.getAvailableServices(), additionalProviders, ctx));
        }
    }
    if (providers == null) {
        providers = new ArrayList<>(4);
        if (additionalProviders != null && !additionalProviders.isEmpty()) {
            providers.addAll(providers(serviceConfiguration.getAvailableServices(), additionalProviders, ctx));
        }
    }
    if (!ignoreAutoProviders) {
        addMandatoryProviders(providers, serviceConfiguration);
        if (enforceCxfBvalMapper) {
            if (!shouldSkipProvider(CxfResponseValidationExceptionMapper.class.getName())) {
                providers.add(new CxfResponseValidationExceptionMapper());
            }
        }
    }
    SystemInstance.get().fireEvent(new ExtensionProviderRegistration(AppFinder.findAppContextOrWeb(Thread.currentThread().getContextClassLoader(), AppFinder.AppContextTransformer.INSTANCE), providers));
    if (!providers.isEmpty()) {
        factory.setProviders(providers);
    }
}
Also used : Message(org.apache.cxf.message.Message) JAXRSBeanValidationOutInterceptor(org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) BeanValidationFeature(org.apache.cxf.validation.BeanValidationFeature) Feature(org.apache.cxf.feature.Feature) EJBRestServiceInfo(org.apache.openejb.server.rest.EJBRestServiceInfo) ServiceInfo(org.apache.openejb.assembler.classic.ServiceInfo) Arrays.asList(java.util.Arrays.asList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JAXRSBeanValidationOutInterceptor(org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) BeanValidationInInterceptor(org.apache.cxf.validation.BeanValidationInInterceptor) JAXRSBeanValidationInInterceptor(org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor) BeanValidationOutInterceptor(org.apache.cxf.validation.BeanValidationOutInterceptor) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) BeanValidationFeature(org.apache.cxf.validation.BeanValidationFeature) BeanValidationInInterceptor(org.apache.cxf.validation.BeanValidationInInterceptor) JAXRSBeanValidationInInterceptor(org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor) ResourceComparator(org.apache.cxf.jaxrs.ext.ResourceComparator) ValidatorFactory(javax.validation.ValidatorFactory) Method(java.lang.reflect.Method) MethodDescriptor(javax.validation.metadata.MethodDescriptor) JAXRSBeanValidationInInterceptor(org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor) ResponseConstraintViolationException(org.apache.cxf.validation.ResponseConstraintViolationException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) EndpointException(org.apache.cxf.endpoint.EndpointException) ServletException(javax.servlet.ServletException) BusException(org.apache.cxf.BusException) InjectionException(javax.enterprise.inject.InjectionException) BeanValidationProvider(org.apache.cxf.validation.BeanValidationProvider) JAXRSBeanValidationOutInterceptor(org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor) BeanValidationOutInterceptor(org.apache.cxf.validation.BeanValidationOutInterceptor) ExtensionProviderRegistration(org.apache.openejb.server.cxf.rs.event.ExtensionProviderRegistration) Validator(javax.validation.Validator)

Aggregations

Feature (org.apache.cxf.feature.Feature)37 ArrayList (java.util.ArrayList)16 Bus (org.apache.cxf.Bus)8 Endpoint (org.apache.cxf.endpoint.Endpoint)7 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)7 List (java.util.List)6 Server (org.apache.cxf.endpoint.Server)6 AbstractFeature (org.apache.cxf.feature.AbstractFeature)6 LoggingFeature (org.apache.cxf.feature.LoggingFeature)6 IOException (java.io.IOException)5 QName (javax.xml.namespace.QName)5 Interceptor (org.apache.cxf.interceptor.Interceptor)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)4 Message (org.apache.cxf.message.Message)4 AbstractServiceFactoryBean (org.apache.cxf.service.factory.AbstractServiceFactoryBean)4 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)3 EndpointImpl (org.apache.cxf.jaxws.EndpointImpl)3 FactoryBeanListener (org.apache.cxf.service.factory.FactoryBeanListener)3