Search in sources :

Example 41 with JAXRSServerFactoryBean

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);
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Console(java.io.Console) Swagger2Feature(org.apache.cxf.jaxrs.swagger.Swagger2Feature) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 42 with JAXRSServerFactoryBean

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();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 43 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) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Bean(javax.enterprise.inject.spi.Bean)

Example 44 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 45 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)

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