Search in sources :

Example 1 with SearchContextProvider

use of org.apache.cxf.jaxrs.ext.search.SearchContextProvider 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 2 with SearchContextProvider

use of org.apache.cxf.jaxrs.ext.search.SearchContextProvider in project tesb-rt-se by Talend.

the class PersonApplication method getSingletons.

@Override
public Set<Object> getSingletons() {
    Set<Object> classes = new HashSet<Object>();
    PersonInfoStorage storage = new PersonInfoStorage();
    try {
        Class.forName("org.hsqldb.jdbcDriver");
        EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("persistenceUnitOpenJPA");
        storage.setEntityManager(emFactory.createEntityManager());
        Map<String, String> beanPropertiesMap = new HashMap<String, String>();
        beanPropertiesMap.put("fatherName", "father.name");
        beanPropertiesMap.put("father", "father.name");
        beanPropertiesMap.put("childName", "children.name");
        storage.setBeanProperties(beanPropertiesMap);
        storage.init();
    } catch (Throwable ex) {
        throw new RuntimeException(ex);
    }
    PersonServiceImpl personService = new PersonServiceImpl();
    personService.setStorage(storage);
    classes.add(personService);
    SearchService searchService = new SearchService();
    searchService.setStorage(storage);
    classes.add(searchService);
    // custom providers
    classes.add(new PersonExceptionMapper());
    JSONProvider<?> provider = new JSONProvider<Object>();
    provider.setIgnoreNamespaces(true);
    classes.add(provider);
    classes.add(new SearchContextProvider());
    return classes;
}
Also used : HashMap(java.util.HashMap) PersonInfoStorage(service.advanced.PersonInfoStorage) SearchContextProvider(org.apache.cxf.jaxrs.ext.search.SearchContextProvider) PersonServiceImpl(service.advanced.PersonServiceImpl) EntityManagerFactory(javax.persistence.EntityManagerFactory) SearchService(service.advanced.SearchService) JSONProvider(org.apache.cxf.jaxrs.provider.json.JSONProvider) PersonExceptionMapper(service.advanced.PersonExceptionMapper) HashSet(java.util.HashSet)

Example 3 with SearchContextProvider

use of org.apache.cxf.jaxrs.ext.search.SearchContextProvider in project cxf by apache.

the class BookServer method createServer.

@Override
protected Server createServer(Bus bus) throws Exception {
    bus.setProperty(ExceptionMapper.class.getName(), new BusMapperExceptionMapper());
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class, SimpleBookStore.class, BookStorePerRequest.class, BookStoreRegex.class);
    // default lifecycle is per-request, change it to singleton
    final BinaryDataProvider<Object> p = new BinaryDataProvider<>();
    p.setProduceMediaTypes(Collections.singletonList("application/bar"));
    p.setEnableBuffering(true);
    p.setReportByteArraySize(true);
    final JAXBElementProvider<?> jaxbProvider = new JAXBElementProvider<>();
    jaxbProvider.setJaxbElementClassMap(Collections.singletonMap(BookNoXmlRootElement.class.getName(), "BookNoXmlRootElement"));
    sf.setProviders(Arrays.asList(p, new BookStore.PrimitiveIntArrayReaderWriter(), new BookStore.PrimitiveDoubleArrayReaderWriter(), new BookStore.StringArrayBodyReaderWriter(), new BookStore.StringListBodyReaderWriter(), new StreamingResponseProvider<Object>(), new ContentTypeModifyingMBW(), jaxbProvider, new FormatResponseHandler(), new GenericHandlerWriter(), new FaultyRequestHandler(), new SearchContextProvider(), new QueryContextProvider(), new BlockingRequestFilter(), new FaultyResponseFilter(), new BlockedExceptionMapper(), new ParamConverterImpl()));
    sf.setInInterceptors(Arrays.asList(new CustomInFaultyInterceptor(), new LoggingInInterceptor()));
    sf.setOutInterceptors(Arrays.asList(new CustomOutInterceptor(), new LoggingOutInterceptor()));
    sf.setOutFaultInterceptors(Arrays.asList(new CustomOutFaultInterceptor()));
    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);
    return sf.create();
}
Also used : 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) 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) StreamingResponseProvider(org.apache.cxf.jaxrs.provider.StreamingResponseProvider) QueryContextProvider(org.apache.cxf.jaxrs.ext.search.QueryContextProvider)

Aggregations

SearchContextProvider (org.apache.cxf.jaxrs.ext.search.SearchContextProvider)3 HashMap (java.util.HashMap)2 ExceptionMapper (javax.ws.rs.ext.ExceptionMapper)2 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)2 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)2 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)2 ResponseExceptionMapper (org.apache.cxf.jaxrs.client.ResponseExceptionMapper)2 QueryContextProvider (org.apache.cxf.jaxrs.ext.search.QueryContextProvider)2 SearchBean (org.apache.cxf.jaxrs.ext.search.SearchBean)2 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)2 BinaryDataProvider (org.apache.cxf.jaxrs.provider.BinaryDataProvider)2 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 Bus (org.apache.cxf.Bus)1 Interceptor (org.apache.cxf.interceptor.Interceptor)1 StreamingResponseProvider (org.apache.cxf.jaxrs.provider.StreamingResponseProvider)1 JSONProvider (org.apache.cxf.jaxrs.provider.json.JSONProvider)1 Message (org.apache.cxf.message.Message)1