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 AbstractSpringComponentScanServer method createJaxRsServer.
@Override
protected Server createJaxRsServer() {
JAXRSServerFactoryBean factoryBean = null;
String[] beanNames = applicationContext.getBeanNamesForAnnotation(ApplicationPath.class);
if (beanNames.length > 0) {
Set<String> componentScanPackagesSet = parseSetProperty(componentScanPackages);
Set<String> componentScanBeansSet = parseSetProperty(componentScanBeans);
for (String beanName : beanNames) {
if (isComponentMatched(beanName, componentScanPackagesSet, componentScanBeansSet)) {
Application app = applicationContext.getBean(beanName, Application.class);
factoryBean = createFactoryBeanFromApplication(app);
for (String cxfBeanName : applicationContext.getBeanNamesForAnnotation(org.apache.cxf.annotations.Provider.class)) {
if (isComponentMatched(cxfBeanName, componentScanPackagesSet, componentScanBeansSet)) {
addCxfProvider(getProviderBean(cxfBeanName));
}
}
break;
}
}
}
if (!StringUtils.isEmpty(classesScanPackages)) {
try {
final Map<Class<? extends Annotation>, Collection<Class<?>>> appClasses = ClasspathScanner.findClasses(classesScanPackages, ApplicationPath.class);
List<Application> apps = CastUtils.cast(JAXRSServerFactoryBeanDefinitionParser.createBeansFromDiscoveredClasses(super.applicationContext, appClasses.get(ApplicationPath.class), null));
if (apps.size() > 0) {
factoryBean = createFactoryBeanFromApplication(apps.get(0));
final Map<Class<? extends Annotation>, Collection<Class<?>>> cxfClasses = ClasspathScanner.findClasses(classesScanPackages, org.apache.cxf.annotations.Provider.class);
addCxfProvidersFromClasses(cxfClasses.get(org.apache.cxf.annotations.Provider.class));
}
} catch (Exception ex) {
throw new ServiceConstructionException(ex);
}
}
if (factoryBean != null) {
setFactoryCxfProviders(factoryBean);
return factoryBean.create();
}
return super.createJaxRsServer();
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project cxf by apache.
the class MultipartServer method run.
protected void run() {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(MultipartStore.class);
Map<String, Object> props = new HashMap<>();
props.put(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, String.valueOf(1024 * 10));
props.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, String.valueOf(1024 * 5));
props.put(AttachmentDeserializer.ATTACHMENT_MAX_HEADER_SIZE, String.valueOf(400));
sf.setProperties(props);
// default lifecycle is per-request, change it to singleton
sf.setResourceProvider(MultipartStore.class, new SingletonResourceProvider(new MultipartStore()));
sf.setAddress("http://localhost:" + PORT + "/");
server = sf.create();
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project cxf by apache.
the class BookServerWebSocket method run.
protected void run() {
Bus bus = BusFactory.getDefaultBus();
setBus(bus);
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setBus(bus);
sf.setResourceClasses(BookStoreWebSocket.class, BookStorePerRequest.class);
sf.setProvider(new StreamingResponseProvider<Book>());
sf.setResourceProvider(BookStoreWebSocket.class, new SingletonResourceProvider(new BookStoreWebSocket(), true));
sf.setAddress("ws://localhost:" + port + "/websocket");
server = sf.create();
BusFactory.setDefaultBus(null);
BusFactory.setThreadDefaultBus(null);
}
Aggregations