Search in sources :

Example 66 with SingletonResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.

the class BookServerWebSocket method createServer.

@Override
protected Server createServer(Bus bus) throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStoreWebSocket.class, BookStorePerRequest.class);
    sf.setProvider(new StreamingResponseProvider<Book>());
    sf.setResourceProvider(BookStoreWebSocket.class, new SingletonResourceProvider(new BookStoreWebSocket(), true));
    sf.setAddress("ws://localhost:" + port + "/websocket");
    return sf.create();
}
Also used : Book(org.apache.cxf.systest.jaxrs.Book) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 67 with SingletonResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.

the class ReactorServer method run.

@Override
protected void run() {
    Bus bus = BusFactory.getDefaultBus();
    // Make sure default JSONProvider is not loaded
    bus.setProperty("skip.default.json.provider.registration", true);
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.getProperties(true).put("useStreamingSubscriber", false);
    sf.setProvider(new JacksonJsonProvider());
    new ReactorCustomizer().customize(sf);
    sf.setResourceClasses(FluxService.class, MonoService.class);
    sf.setResourceProvider(FluxService.class, new SingletonResourceProvider(new FluxService(), true));
    sf.setResourceProvider(MonoService.class, new SingletonResourceProvider(new MonoService(), true));
    sf.setAddress("http://localhost:" + PORT + "/reactor");
    server1 = sf.create();
    JAXRSServerFactoryBean sf2 = new JAXRSServerFactoryBean();
    sf2.setProvider(new JacksonJsonProvider());
    sf2.setProvider(new IllegalArgumentExceptionMapper());
    sf2.setProvider(new IllegalStateExceptionMapper());
    new ReactorCustomizer().customize(sf2);
    sf2.setResourceClasses(FluxService.class);
    sf2.setResourceProvider(FluxService.class, new SingletonResourceProvider(new FluxService(), true));
    sf2.setAddress("http://localhost:" + PORT + "/reactor2");
    server2 = sf2.create();
}
Also used : Bus(org.apache.cxf.Bus) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ReactorCustomizer(org.apache.cxf.jaxrs.reactor.server.ReactorCustomizer)

Example 68 with SingletonResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.

the class BookHttpsServer method run.

protected void run() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    // default lifecycle is per-request, change it to singleton
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore()));
    sf.setAddress("https://localhost:" + PORT + "/");
    sf.create();
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.BookStore) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 69 with SingletonResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.

the class AbstractBookServerHttp2 method run.

protected void run() {
    SpringBusFactory factory = new SpringBusFactory();
    Bus bus = factory.createBus(context);
    bus.setProperty(HttpServerEngineSupport.ENABLE_HTTP2, true);
    setBus(bus);
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setBus(bus);
    sf.setResourceClasses(BookStore.class);
    sf.setProvider(new StreamingResponseProvider<Book>());
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
    sf.setAddress(scheme + "://localhost:" + port + "/http2");
    server = sf.create();
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Book(org.apache.cxf.customer.book.Book) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 70 with SingletonResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.

the class BookServerAsyncClient method createServer.

@Override
protected Server createServer(Bus bus) throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.setProvider(new BooleanReaderWriter());
    sf.getProperties(true).put("default.content.type", "*/*");
    return sf.create();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Aggregations

SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)84 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)63 Bus (org.apache.cxf.Bus)17 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)15 ArrayList (java.util.ArrayList)14 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)14 ResourceProvider (org.apache.cxf.jaxrs.lifecycle.ResourceProvider)9 HashMap (java.util.HashMap)7 Before (org.junit.Before)7 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)5 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)5 Map (java.util.Map)4 ReactiveIOCustomizer (org.apache.cxf.jaxrs.rx3.server.ReactiveIOCustomizer)4 DetectorResource (org.apache.tika.server.resource.DetectorResource)4 MetadataResource (org.apache.tika.server.resource.MetadataResource)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Feature (org.apache.cxf.feature.Feature)3 ReactiveIOCustomizer (org.apache.cxf.jaxrs.rx2.server.ReactiveIOCustomizer)3 Message (org.apache.cxf.message.Message)3