use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project camel by apache.
the class CamelCatalogRestMain method run.
public void run() {
LOGGER.info("Starting ...");
catalog = new CamelCatalogRest();
connectorCatalog = new CamelConnectorCatalogRest();
// setup Apache CXF REST server
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(CamelCatalogRest.class, CamelConnectorCatalogRest.class);
sf.setResourceProvider(CamelCatalogRest.class, new SingletonResourceProvider(catalog));
sf.setResourceProvider(CamelConnectorCatalogRest.class, new SingletonResourceProvider(connectorCatalog));
Swagger2Feature swagger = new Swagger2Feature();
swagger.setBasePath("/");
swagger.setScanAllResources(false);
swagger.setPrettyPrint(true);
swagger.setSupportSwaggerUi(true);
swagger.setTitle("Camel Catalog and Connector Catalog REST Api");
swagger.setDescription("REST Api for the Camel Catalog and Connector Catalog");
swagger.setVersion(catalog.getCatalogVersion());
swagger.setContact("Apache Camel");
sf.getFeatures().add(swagger);
// to use jackson for json
sf.setProvider(JacksonJsonProvider.class);
sf.setAddress("http://localhost:" + port);
// create and start the CXF server (non blocking)
server = sf.create();
server.start();
LOGGER.info("CamelCatalog REST Api started");
LOGGER.info("");
LOGGER.info("\tRest API base path: http://localhost:{}/camel-catalog", port);
LOGGER.info("\tRest API version: http://localhost:{}/camel-catalog/catalogVersion", port);
LOGGER.info("");
LOGGER.info("CamelConnectorCatalog REST Api started");
LOGGER.info("");
LOGGER.info("\tRest API base path: http://localhost:{}/camel-connector-catalog", port);
LOGGER.info("");
LOGGER.info("\tSwagger Doc: http://localhost:{}/swagger.json", port);
LOGGER.info("\tSwagger UI: http://localhost:{}/api-docs?url=/swagger.json", port);
LOGGER.info("");
LOGGER.info("Press Enter to stop");
Console console = System.console();
console.readLine();
LOGGER.info("Stopping ...");
server.stop();
server.destroy();
LOGGER.info("CamelCatalog REST Api stopped");
System.exit(0);
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project ddf by codice.
the class TestPlugin method startServer.
private static void startServer() {
LOGGER.info("Starting server.");
endpoint = mock(MockRestEndpoint.class);
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(MockRestEndpoint.class);
sf.setAddress(ENDPOINT_ADDRESS);
sf.setResourceProvider(MockRestEndpoint.class, new SingletonResourceProvider(endpoint, true));
LOGGER.info("Creating server.");
server = sf.create();
}
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);
}
}
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 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);
}
Aggregations