Search in sources :

Example 11 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project tomee by apache.

the class CxfRsHttpListener method newFactory.

private JAXRSServerFactoryBean newFactory(final String prefix, final String service, final String endpoint) {
    final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean() {

        @Override
        protected Endpoint createEndpoint() throws BusException, EndpointException {
            final Endpoint created = super.createEndpoint();
            created.put(ManagedEndpoint.SERVICE_NAME, service);
            created.put(ManagedEndpoint.ENDPOINT_NAME, endpoint);
            return created;
        }
    };
    factory.setDestinationFactory(transportFactory);
    factory.setBus(CxfUtil.getBus());
    factory.setAddress(prefix);
    return factory;
}
Also used : ManagedEndpoint(org.apache.cxf.endpoint.ManagedEndpoint) Endpoint(org.apache.cxf.endpoint.Endpoint) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Example 12 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project bamboobsc by billchen198318.

the class CxfServerBean method start.

public static void start(PublishingCXFServlet servlet, ServletConfig servletConfig, Bus bus, boolean loadBusManual) {
    logger.info("start");
    CxfServerBean.servlet = servlet;
    CxfServerBean.servletConfig = servletConfig;
    CxfServerBean.bus = bus;
    if (server != null && serverFactoryBean != null) {
        logger.warn("Server is found , not start");
        return;
    }
    try {
        if (loadBusManual) {
            logger.info("load bus manual mode");
            CxfServerBean.bus = servlet.loadBusManual(servletConfig);
            restartNum = restartNum + 1;
        }
        BusFactory.setDefaultBus(CxfServerBean.bus);
        serverFactoryBean = new JAXRSServerFactoryBean();
        serverFactoryBean.setBus(CxfServerBean.bus);
        List<TbSysWsConfig> configs = getSystemWsConfigs();
        publishDefault(configs);
        int r = publishRest(serverFactoryBean, configs);
        BindingFactoryManager manager = serverFactoryBean.getBus().getExtension(BindingFactoryManager.class);
        bindingFactory = new JAXRSBindingFactory();
        bindingFactory.setBus(serverFactoryBean.getBus());
        manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, bindingFactory);
        if (r > 0) {
            server = serverFactoryBean.create();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    logger.info("end");
}
Also used : JAXRSBindingFactory(org.apache.cxf.jaxrs.JAXRSBindingFactory) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) TbSysWsConfig(com.netsteadfast.greenstep.po.hbm.TbSysWsConfig) Endpoint(javax.xml.ws.Endpoint) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 13 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project camel by apache.

the class CxfRsEndpointBeansTest method testCxfBusInjection.

@Test
public void testCxfBusInjection() {
    CxfRsEndpoint serviceEndpoint = context.getEndpoint("cxfrs:bean:serviceEndpoint", CxfRsEndpoint.class);
    CxfRsEndpoint routerEndpoint = context.getEndpoint("cxfrs:bean:routerEndpoint", CxfRsEndpoint.class);
    JAXRSServerFactoryBean server = routerEndpoint.createJAXRSServerFactoryBean();
    JAXRSClientFactoryBean client = serviceEndpoint.createJAXRSClientFactoryBean();
    assertEquals("These cxfrs endpoints don't share the same bus", server.getBus().getId(), client.getBus().getId());
}
Also used : CxfRsEndpoint(org.apache.camel.component.cxf.jaxrs.CxfRsEndpoint) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Test(org.junit.Test)

Example 14 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project camel by apache.

the class CamelConnectorCatalogRestTest method setup.

@Before
public void setup() {
    catalog = new CamelConnectorCatalogRest();
    port = AvailablePortFinder.getNextAvailable(9000);
    // setup Apache CXF REST server
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(CamelConnectorCatalogRest.class);
    sf.setResourceProvider(CamelConnectorCatalogRest.class, new SingletonResourceProvider(catalog));
    // 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) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) Before(org.junit.Before)

Example 15 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)

Aggregations

JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)17 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)7 Before (org.junit.Before)4 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)3 JAXRSBindingFactory (org.apache.cxf.jaxrs.JAXRSBindingFactory)3 ArrayList (java.util.ArrayList)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 ManagedEndpoint (org.apache.cxf.endpoint.ManagedEndpoint)2 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)2 Swagger2Feature (org.apache.cxf.jaxrs.swagger.Swagger2Feature)2 CommonsDigester (org.apache.tika.parser.utils.CommonsDigester)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)1 TbSysWsConfig (com.netsteadfast.greenstep.po.hbm.TbSysWsConfig)1 Console (java.io.Console)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Level (java.util.logging.Level)1