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);
}
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());
}
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());
}
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());
}
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);
}
}
Aggregations