Search in sources :

Example 81 with JAXRSServerFactoryBean

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

the class JAXRSUtilsTest method testInjectApplicationInSingleton.

@Test
public void testInjectApplicationInSingleton() throws Exception {
    CustomerApplication app = new CustomerApplication();
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    Customer customer = new Customer();
    sf.setServiceBeanObjects(customer);
    sf.setApplication(app);
    sf.setStart(false);
    Server server = sf.create();
    assertSame(app, customer.getApplication1());
    assertSame(app, customer.getApplication2());
    @SuppressWarnings("unchecked") ThreadLocalProxy<UriInfo> proxy = (ThreadLocalProxy<UriInfo>) app.getUriInfo();
    assertNotNull(proxy);
    invokeCustomerMethod(sf.getServiceFactory().getClassResourceInfo().get(0), customer, server);
    assertSame(app, customer.getApplication2());
    assertTrue(proxy.get() instanceof UriInfo);
}
Also used : ThreadLocalProxy(org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy) Server(org.apache.cxf.endpoint.Server) CustomerApplication(org.apache.cxf.jaxrs.CustomerApplication) Customer(org.apache.cxf.jaxrs.Customer) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) UriInfo(javax.ws.rs.core.UriInfo) ThreadLocalUriInfo(org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo) Test(org.junit.Test)

Example 82 with JAXRSServerFactoryBean

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

the class JAXRSUtilsTest method testInjectCustomContext.

@Test
public void testInjectCustomContext() throws Exception {
    final CustomerContext contextImpl = new CustomerContext() {

        public String get() {
            return "customerContext";
        }
    };
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    Customer customer = new Customer();
    sf.setServiceBeanObjects(customer);
    sf.setProvider(new ContextProvider<CustomerContext>() {

        public CustomerContext createContext(Message message) {
            return contextImpl;
        }
    });
    sf.setStart(false);
    Server s = sf.create();
    assertTrue(customer.getCustomerContext() instanceof ThreadLocalProxy<?>);
    invokeCustomerMethod(sf.getServiceFactory().getClassResourceInfo().get(0), customer, s);
    CustomerContext context = customer.getCustomerContext();
    assertEquals("customerContext", context.get());
}
Also used : Message(org.apache.cxf.message.Message) Server(org.apache.cxf.endpoint.Server) Customer(org.apache.cxf.jaxrs.Customer) CustomerContext(org.apache.cxf.jaxrs.Customer.CustomerContext) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Test(org.junit.Test)

Example 83 with JAXRSServerFactoryBean

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

the class ResourceUtilsTest method shouldCreateApplicationWhichInheritsApplicationPath.

@Test
public void shouldCreateApplicationWhichInheritsApplicationPath() throws Exception {
    JAXRSServerFactoryBean application = ResourceUtils.createApplication(new SuperApplication(), false, false, false, null);
    assertEquals("/base", application.getAddress());
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Test(org.junit.Test)

Example 84 with JAXRSServerFactoryBean

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

the class SpringResourceFactoryTest method testFactory.

@Test
public void testFactory() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxrs/spring/servers2.xml" });
    verifyFactory(ctx, "sfactory1", true);
    verifyFactory(ctx, "sfactory2", false);
    Object serverBean = ctx.getBean("server1");
    assertNotNull(serverBean);
    JAXRSServerFactoryBean factoryBean = (JAXRSServerFactoryBean) serverBean;
    List<ClassResourceInfo> list = factoryBean.getServiceFactory().getClassResourceInfo();
    assertNotNull(list);
    assertEquals(4, list.size());
    assertSame(BookStoreConstructor.class, list.get(0).getServiceClass());
    assertSame(BookStoreConstructor.class, list.get(0).getResourceClass());
    assertSame(BookStore.class, list.get(1).getServiceClass());
    assertSame(BookStore.class, list.get(1).getResourceClass());
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Test(org.junit.Test)

Example 85 with JAXRSServerFactoryBean

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

the class JAXRSCdiResourceExtension method customize.

/**
 * Look and apply the available JAXRSServerFactoryBean extensions to customize its
 * creation (f.e. add features, providers, assign transport, ...)
 * @param beanManager bean manager
 * @param bean JAX-RS server factory bean about to be created
 */
private void customize(final BeanManager beanManager, final JAXRSServerFactoryBean bean) {
    JAXRSServerFactoryCustomizationUtils.customize(bean);
    final Collection<Bean<?>> extensionBeans = beanManager.getBeans(JAXRSServerFactoryCustomizationExtension.class);
    for (final Bean<?> extensionBean : extensionBeans) {
        final JAXRSServerFactoryCustomizationExtension extension = (JAXRSServerFactoryCustomizationExtension) beanManager.getReference(extensionBean, JAXRSServerFactoryCustomizationExtension.class, createCreationalContext(beanManager, extensionBean));
        extension.customize(bean);
    }
}
Also used : JAXRSServerFactoryCustomizationExtension(org.apache.cxf.jaxrs.ext.JAXRSServerFactoryCustomizationExtension) ProcessBean(javax.enterprise.inject.spi.ProcessBean) Bean(javax.enterprise.inject.spi.Bean) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Aggregations

JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)126 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)65 Bus (org.apache.cxf.Bus)21 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)18 ArrayList (java.util.ArrayList)15 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)14 Test (org.junit.Test)13 HashMap (java.util.HashMap)10 Server (org.apache.cxf.endpoint.Server)10 Application (javax.ws.rs.core.Application)9 Before (org.junit.Before)8 Map (java.util.Map)7 IOException (java.io.IOException)5 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)5 ResourceProvider (org.apache.cxf.jaxrs.lifecycle.ResourceProvider)5 Bean (org.springframework.context.annotation.Bean)5 InputStream (java.io.InputStream)4 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)4 Feature (org.apache.cxf.feature.Feature)4 JAXRSBindingFactory (org.apache.cxf.jaxrs.JAXRSBindingFactory)4