Search in sources :

Example 1 with JAXRSServerFactoryBean

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

the class CamelCatalogRestTest 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));
    // 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 2 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean 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 3 with JAXRSServerFactoryBean

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

the class CxfRsEndpointTest method testCxfRsEndpointSetProvider.

@Test
public void testCxfRsEndpointSetProvider() throws Exception {
    String endpointUri = "cxfrs://http://localhost:" + CTX + "" + "?resourceClass=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";
    CxfRsComponent component = new CxfRsComponent(context);
    CxfRsEndpoint endpoint = (CxfRsEndpoint) component.createEndpoint(endpointUri);
    JSONProvider<?> jsonProvider = new JSONProvider<Object>();
    jsonProvider.setDropRootElement(true);
    jsonProvider.setSupportUnwrapped(true);
    endpoint.setProvider(jsonProvider);
    JAXRSServerFactoryBean sfb = endpoint.createJAXRSServerFactoryBean();
    assertEquals("Get a wrong proider size", 1, sfb.getProviders().size());
    JAXRSClientFactoryBean cfb = endpoint.createJAXRSClientFactoryBean();
    assertEquals("Get a wrong proider size", 1, cfb.getProviders().size());
}
Also used : JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) JSONProvider(org.apache.cxf.jaxrs.provider.json.JSONProvider) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Test(org.junit.Test)

Example 4 with JAXRSServerFactoryBean

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

the class CxfBeanEndpoint method createServer.

private void createServer(List<Object> serviceBeans) {
    Object obj = serviceBeans.get(0).getClass().getAnnotation(WebService.class);
    if (obj != null) {
        JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();
        bean.setTransportId(CxfBeanTransportFactory.TRANSPORT_ID);
        bean.setServiceClass(serviceBeans.get(0).getClass());
        // set the bean instance as well, otherwise CXF will re-create a new instance of the class
        bean.setServiceBean(serviceBeans.get(0));
        if (bean.getJaxWsServiceFactory() != null) {
            bean.getJaxWsServiceFactory().setPopulateFromClass(isPopulateFromClass());
        }
        bean.setBus(bus);
        bean.setStart(true);
        bean.setAddress("camel://" + createEndpointUri());
        if (loggingFeatureEnabled) {
            bean.getFeatures().add(new LoggingFeature());
        }
        server = bean.create();
    } else {
        JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
        bean.setServiceBeans(serviceBeans);
        bean.setAddress("camel://" + createEndpointUri());
        bean.setStart(true);
        bean.setTransportId(CxfBeanTransportFactory.TRANSPORT_ID);
        bean.setBus(bus);
        if (loggingFeatureEnabled) {
            bean.getFeatures().add(new LoggingFeature());
        }
        bean.setProviders(providers);
        server = bean.create();
    }
}
Also used : LoggingFeature(org.apache.cxf.feature.LoggingFeature) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 5 with JAXRSServerFactoryBean

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

the class CxfRsConsumer method createServer.

protected Server createServer() {
    CxfRsEndpoint endpoint = (CxfRsEndpoint) getEndpoint();
    CxfRsInvoker cxfRsInvoker = new CxfRsInvoker(endpoint, this);
    JAXRSServerFactoryBean svrBean = endpoint.createJAXRSServerFactoryBean();
    Bus bus = endpoint.getBus();
    // We need to apply the bus setting from the CxfRsEndpoint which does not use the default bus
    if (bus != null) {
        svrBean.setBus(bus);
    }
    svrBean.setInvoker(cxfRsInvoker);
    return svrBean.create();
}
Also used : Bus(org.apache.cxf.Bus) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Aggregations

JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)125 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)65 Bus (org.apache.cxf.Bus)21 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)17 ArrayList (java.util.ArrayList)15 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)14 Test (org.junit.Test)13 HashMap (java.util.HashMap)10 Server (org.apache.cxf.endpoint.Server)10 Application (javax.ws.rs.core.Application)9 Before (org.junit.Before)8 Map (java.util.Map)7 IOException (java.io.IOException)5 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)5 ResourceProvider (org.apache.cxf.jaxrs.lifecycle.ResourceProvider)5 Bean (org.springframework.context.annotation.Bean)5 InputStream (java.io.InputStream)4 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)4 Feature (org.apache.cxf.feature.Feature)4 JAXRSBindingFactory (org.apache.cxf.jaxrs.JAXRSBindingFactory)4