Search in sources :

Example 21 with JAXRSServerFactoryBean

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

the class BookServer method run.

protected void run() {
    Bus bus = BusFactory.getDefaultBus();
    bus.setProperty(ExceptionMapper.class.getName(), new BusMapperExceptionMapper());
    setBus(bus);
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setBus(bus);
    sf.setResourceClasses(BookStore.class, SimpleBookStore.class, BookStorePerRequest.class);
    List<Object> providers = new ArrayList<>();
    // default lifecycle is per-request, change it to singleton
    BinaryDataProvider<Object> p = new BinaryDataProvider<Object>();
    p.setProduceMediaTypes(Collections.singletonList("application/bar"));
    p.setEnableBuffering(true);
    p.setReportByteArraySize(true);
    providers.add(p);
    providers.add(new BookStore.PrimitiveIntArrayReaderWriter());
    providers.add(new BookStore.PrimitiveDoubleArrayReaderWriter());
    providers.add(new BookStore.StringArrayBodyReaderWriter());
    providers.add(new BookStore.StringListBodyReaderWriter());
    providers.add(new StreamingResponseProvider<Object>());
    providers.add(new ContentTypeModifyingMBW());
    JAXBElementProvider<?> jaxbProvider = new JAXBElementProvider<Object>();
    Map<String, String> jaxbElementClassMap = new HashMap<>();
    jaxbElementClassMap.put(BookNoXmlRootElement.class.getName(), "BookNoXmlRootElement");
    jaxbProvider.setJaxbElementClassMap(jaxbElementClassMap);
    providers.add(jaxbProvider);
    providers.add(new FormatResponseHandler());
    providers.add(new GenericHandlerWriter());
    providers.add(new FaultyRequestHandler());
    providers.add(new SearchContextProvider());
    providers.add(new QueryContextProvider());
    providers.add(new BlockingRequestFilter());
    providers.add(new FaultyResponseFilter());
    providers.add(new BlockedExceptionMapper());
    providers.add(new ParamConverterImpl());
    sf.setProviders(providers);
    List<Interceptor<? extends Message>> inInts = new ArrayList<Interceptor<? extends Message>>();
    inInts.add(new CustomInFaultyInterceptor());
    inInts.add(new LoggingInInterceptor());
    sf.setInInterceptors(inInts);
    List<Interceptor<? extends Message>> outInts = new ArrayList<Interceptor<? extends Message>>();
    outInts.add(new CustomOutInterceptor());
    outInts.add(new LoggingOutInterceptor());
    sf.setOutInterceptors(outInts);
    List<Interceptor<? extends Message>> outFaultInts = new ArrayList<Interceptor<? extends Message>>();
    outFaultInts.add(new CustomOutFaultInterceptor());
    sf.setOutFaultInterceptors(outFaultInts);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.getProperties(true).put("org.apache.cxf.jaxrs.mediaTypeCheck.strict", true);
    sf.getProperties().put("search.visitor", new SQLPrinterVisitor<SearchBean>("books"));
    sf.getProperties().put("org.apache.cxf.http.header.split", true);
    sf.getProperties().put("default.content.type", "*/*");
    sf.getProperties().putAll(properties);
    server = sf.create();
    BusFactory.setDefaultBus(null);
    BusFactory.setThreadDefaultBus(null);
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) ResponseExceptionMapper(org.apache.cxf.jaxrs.client.ResponseExceptionMapper) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) Bus(org.apache.cxf.Bus) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) BinaryDataProvider(org.apache.cxf.jaxrs.provider.BinaryDataProvider) SearchContextProvider(org.apache.cxf.jaxrs.ext.search.SearchContextProvider) JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) QueryContextProvider(org.apache.cxf.jaxrs.ext.search.QueryContextProvider)

Example 22 with JAXRSServerFactoryBean

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

the class BookServerSub method run.

protected void run() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setStaticSubresourceResolution(true);
    sf.setResourceClasses(BookStoreSubObject.class);
    sf.setResourceProvider(BookStoreSubObject.class, new SingletonResourceProvider(new BookStoreSubObject(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    server = sf.create();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 23 with JAXRSServerFactoryBean

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

the class BookServerThrottled method run.

protected void run() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    List<Feature> features = new ArrayList<>();
    ThrottlingFeature tf = new ThrottlingFeature(new ThrottlingManagerImpl());
    features.add(tf);
    sf.setFeatures(features);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    server = sf.create();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ArrayList(java.util.ArrayList) ThrottlingFeature(org.apache.cxf.throttling.ThrottlingFeature) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) Feature(org.apache.cxf.feature.Feature) ThrottlingFeature(org.apache.cxf.throttling.ThrottlingFeature)

Example 24 with JAXRSServerFactoryBean

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

the class JAXRSLocalTransportTest method setUp.

@Before
public void setUp() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class, BookStoreSpring.class);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
    sf.setResourceProvider(BookStoreSpring.class, new SingletonResourceProvider(new BookStoreSpring(), true));
    sf.setProvider(new JacksonJsonProvider());
    List<Interceptor<? extends Message>> outInts = new ArrayList<Interceptor<? extends Message>>();
    outInts.add(new CustomOutInterceptor());
    sf.setOutInterceptors(outInts);
    List<Interceptor<? extends Message>> inInts = new ArrayList<Interceptor<? extends Message>>();
    inInts.add(new CustomInFaultyInterceptor());
    sf.setInInterceptors(inInts);
    sf.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    sf.setAddress("local://books");
    localServer = sf.create();
}
Also used : Message(org.apache.cxf.message.Message) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ArrayList(java.util.ArrayList) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) Interceptor(org.apache.cxf.interceptor.Interceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Before(org.junit.Before)

Example 25 with JAXRSServerFactoryBean

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

the class StatsConfig method jaxRsServer.

@Bean
@DependsOn("cxf")
Server jaxRsServer() {
    final JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint(new StatsApplication(), JAXRSServerFactoryBean.class);
    factory.setServiceBean(statsRestService);
    factory.setProvider(new JacksonJsonProvider());
    factory.setTransportId(SseHttpTransportFactory.TRANSPORT_ID);
    return factory.create();
}
Also used : JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) DependsOn(org.springframework.context.annotation.DependsOn) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Bean(org.springframework.context.annotation.Bean)

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