Search in sources :

Example 1 with QueryContextProvider

use of org.apache.cxf.jaxrs.ext.search.QueryContextProvider 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExceptionMapper (javax.ws.rs.ext.ExceptionMapper)1 Bus (org.apache.cxf.Bus)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)1 Interceptor (org.apache.cxf.interceptor.Interceptor)1 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)1 ResponseExceptionMapper (org.apache.cxf.jaxrs.client.ResponseExceptionMapper)1 QueryContextProvider (org.apache.cxf.jaxrs.ext.search.QueryContextProvider)1 SearchBean (org.apache.cxf.jaxrs.ext.search.SearchBean)1 SearchContextProvider (org.apache.cxf.jaxrs.ext.search.SearchContextProvider)1 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)1 BinaryDataProvider (org.apache.cxf.jaxrs.provider.BinaryDataProvider)1 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)1 Message (org.apache.cxf.message.Message)1 AbstractPhaseInterceptor (org.apache.cxf.phase.AbstractPhaseInterceptor)1