Search in sources :

Example 1 with Swagger2Feature

use of org.apache.cxf.jaxrs.swagger.Swagger2Feature in project camel by apache.

the class CamelCatalogSwaggerTest method setup.

@Before
public void setup() {
    catalog = new CamelCatalogRest();
    port = AvailablePortFinder.getNextAvailable(9000);
    // setup Apache CXF REST server
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(CamelCatalogRest.class);
    sf.setResourceProvider(CamelCatalogRest.class, new SingletonResourceProvider(catalog));
    Swagger2Feature swagger = new Swagger2Feature();
    swagger.setBasePath("/");
    swagger.setScanAllResources(false);
    swagger.setPrettyPrint(true);
    swagger.setSupportSwaggerUi(true);
    swagger.setTitle("Camel Catalog REST Api");
    swagger.setDescription("REST Api for the Camel 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();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Swagger2Feature(org.apache.cxf.jaxrs.swagger.Swagger2Feature) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) Before(org.junit.Before)

Example 2 with Swagger2Feature

use of org.apache.cxf.jaxrs.swagger.Swagger2Feature 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)

Aggregations

JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)2 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)2 Swagger2Feature (org.apache.cxf.jaxrs.swagger.Swagger2Feature)2 Console (java.io.Console)1 Before (org.junit.Before)1