Search in sources :

Example 26 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project cxf by apache.

the class Server method cxfServer.

@Bean
org.apache.cxf.endpoint.Server cxfServer(@Qualifier("cxf") final Tracer tracer) {
    final JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
    endpoint.setBus(bus);
    endpoint.setAddress("/");
    endpoint.setServiceBean(new Catalog());
    endpoint.setProvider(new OpenTracingFeature(tracer));
    endpoint.setProvider(new JacksonJsonProvider());
    return endpoint.create();
}
Also used : JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) OpenTracingFeature(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingFeature) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 27 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project cxf by apache.

the class SampleRestApplication method rsServer.

@Bean
public Server rsServer() {
    JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
    endpoint.setBus(bus);
    endpoint.setServiceBeans(Arrays.<Object>asList(new HelloServiceImpl1(), new HelloServiceImpl2()));
    endpoint.setAddress("/");
    endpoint.setFeatures(Arrays.asList(createOpenApiFeature(), new LoggingFeature()));
    return endpoint.create();
}
Also used : HelloServiceImpl2(sample.rs.service.hello2.HelloServiceImpl2) HelloServiceImpl1(sample.rs.service.hello1.HelloServiceImpl1) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 28 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project cxf by apache.

the class JAXRSCdiResourceExtension method load.

public void load(@Observes final AfterDeploymentValidation event, final BeanManager beanManager) {
    // no need of creational context, it only works for app scoped instances anyway
    final Bean<?> busBean = beanManager.resolve(beanManager.getBeans(CdiBusBean.CXF));
    bus = (Bus) beanManager.getReference(busBean, Bus.class, beanManager.createCreationalContext(busBean));
    // Adding the extension for dynamic providers registration and instantiation
    if (bus.getExtension(ServerConfigurableFactory.class) == null) {
        bus.setExtension(new CdiServerConfigurableFactory(beanManager), ServerConfigurableFactory.class);
    }
    for (final Bean<?> application : applicationBeans) {
        final Application instance = (Application) beanManager.getReference(application, application.getBeanClass(), createCreationalContext(beanManager, application));
        // create a server factory bean with all services and providers discovered.
        if (instance.getSingletons().isEmpty() && instance.getClasses().isEmpty()) {
            final JAXRSServerFactoryBean factory = createFactoryInstance(instance, loadServices(beanManager, Collections.<Class<?>>emptySet()), loadProviders(beanManager, Collections.<Class<?>>emptySet()), loadFeatures(beanManager, Collections.<Class<?>>emptySet()));
            customize(beanManager, factory);
            factory.init();
        } else {
            // If there is an application with any singletons or classes defined, we will
            // create a server factory bean with only application singletons and classes.
            final JAXRSServerFactoryBean factory = createFactoryInstance(instance, beanManager);
            customize(beanManager, factory);
            factory.init();
        }
    }
}
Also used : ServerConfigurableFactory(org.apache.cxf.jaxrs.provider.ServerConfigurableFactory) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Application(javax.ws.rs.core.Application)

Example 29 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project cxf by apache.

the class JAXRSCdiResourceExtension method createFactoryInstance.

/**
 * Create the JAXRSServerFactoryBean from the application and all discovered service and provider instances.
 * @param application application instance
 * @param services all discovered services
 * @param providers all discovered providers
 * @return JAXRSServerFactoryBean instance
 */
private JAXRSServerFactoryBean createFactoryInstance(final Application application, final List<?> services, final List<?> providers, final List<? extends Feature> features) {
    final JAXRSServerFactoryBean instance = ResourceUtils.createApplication(application, false, false, false, bus);
    instance.setServiceBeans(new ArrayList<>(services));
    instance.setProviders(providers);
    instance.setProviders(loadExternalProviders());
    instance.setFeatures(features);
    return instance;
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Example 30 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project cxf by apache.

the class JAXRSCdiResourceExtension method createFactoryInstance.

/**
 * Create the JAXRSServerFactoryBean from the objects declared by application itself.
 * @param application application instance
 * @return JAXRSServerFactoryBean instance
 */
private JAXRSServerFactoryBean createFactoryInstance(final Application application, final BeanManager beanManager) {
    final JAXRSServerFactoryBean instance = ResourceUtils.createApplication(application, false, false, false, bus);
    final ClassifiedClasses classified = classes2singletons(application, beanManager);
    instance.setProviders(classified.getProviders());
    instance.getFeatures().addAll(classified.getFeatures());
    for (final CdiResourceProvider resourceProvider : classified.getResourceProviders()) {
        instance.setResourceProvider(resourceProvider.getResourceClass(), resourceProvider);
    }
    return instance;
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Aggregations

JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)63 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)30 Bus (org.apache.cxf.Bus)11 Test (org.junit.Test)10 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)7 ArrayList (java.util.ArrayList)7 Application (javax.ws.rs.core.Application)6 HashMap (java.util.HashMap)5 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)5 ResourceProvider (org.apache.cxf.jaxrs.lifecycle.ResourceProvider)4 Before (org.junit.Before)4 Map (java.util.Map)3 UriInfo (javax.ws.rs.core.UriInfo)3 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)3 Server (org.apache.cxf.endpoint.Server)3 JAXRSBindingFactory (org.apache.cxf.jaxrs.JAXRSBindingFactory)3 Bean (org.springframework.context.annotation.Bean)3 Annotation (java.lang.annotation.Annotation)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 ManagedEndpoint (org.apache.cxf.endpoint.ManagedEndpoint)2