Search in sources :

Example 1 with SearchBean

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

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

the class TikaContentExtractor method extractMetadataToSearchBean.

/**
 * Extract the metadata only from the input stream. Depending on media type validation,
 * the detector could be run against input stream in order to ensure that parser supports this
 * type of content.
 * @param in input stream to extract the metadata from
 * @return the extracted metadata converted to SearchBean or null if extraction is not possible
 *         or was unsuccessful
 */
public SearchBean extractMetadataToSearchBean(final InputStream in) {
    TikaContent tc = extractMetadata(in);
    if (tc == null) {
        return null;
    }
    Metadata metadata = tc.getMetadata();
    SearchBean bean = new SearchBean();
    for (final String property : metadata.names()) {
        bean.set(property, metadata.get(property));
    }
    return bean;
}
Also used : Metadata(org.apache.tika.metadata.Metadata) SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean)

Example 3 with SearchBean

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

the class HBaseVisitorTest method testScanWithFilterVisitor.

@Test
@Ignore("Enable as soon as it is understood how to run HBase tests in process")
public void testScanWithFilterVisitor() throws Exception {
    Scan scan = new Scan();
    SearchCondition<SearchBean> sc = new FiqlParser<SearchBean>(SearchBean.class).parse("name==CXF");
    HBaseQueryVisitor<SearchBean> visitor = new HBaseQueryVisitor<SearchBean>("book");
    sc.accept(visitor);
    Filter filter = visitor.getQuery();
    scan.setFilter(filter);
    ResultScanner rs = table.getScanner(scan);
    try {
        int count = 0;
        for (Result r = rs.next(); r != null; r = rs.next()) {
            assertEquals("row2", new String(r.getRow()));
            assertEquals("CXF", new String(r.getValue(BOOK_FAMILY, NAME_QUALIFIER)));
            count++;
        }
        assertEquals(1, count);
    } finally {
        rs.close();
    }
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Filter(org.apache.hadoop.hbase.filter.Filter) SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) Scan(org.apache.hadoop.hbase.client.Scan) Result(org.apache.hadoop.hbase.client.Result) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with SearchBean

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

the class LuceneQueryVisitorFiqlTest method testThatMultipleQueriesForTheSameFieldAreThreadSafe.

@Test
public void testThatMultipleQueriesForTheSameFieldAreThreadSafe() throws InterruptedException, ExecutionException {
    final LuceneQueryVisitor<SearchBean> visitor = new LuceneQueryVisitor<SearchBean>();
    final ExecutorService executorService = Executors.newFixedThreadPool(5);
    final Collection<Future<?>> futures = new ArrayList<Future<?>>();
    for (int i = 0; i < 5; ++i) {
        final int index = i;
        futures.add(executorService.submit(new Runnable() {

            @Override
            public void run() {
                final SearchCondition<SearchBean> filter = getParser().parse("name==text" + index);
                visitor.reset();
                visitor.visit(filter);
                assertNotNull("Query should not be null", visitor.getQuery());
                assertThat(visitor.getQuery().toString(), equalTo("name:text" + index));
            }
        }));
    }
    executorService.shutdown();
    assertTrue("All threads should be terminated", executorService.awaitTermination(5, TimeUnit.SECONDS));
    for (final Future<?> future : futures) {
        // The exception will be raised if queries are messed up
        future.get();
    }
}
Also used : SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 5 with SearchBean

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

the class TikaContentExtractorTest method testExtractedTextContentMatchesSearchCriteria.

@Test
public void testExtractedTextContentMatchesSearchCriteria() throws Exception {
    SearchCondition<SearchBean> sc = parser.parse("Author==Bertrand*");
    final SearchBean bean = extractor.extractMetadataToSearchBean(getClass().getResourceAsStream("/files/testPDF.pdf"));
    assertNotNull("Document should not be null", bean);
    assertTrue(sc.isMet(bean));
}
Also used : SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) Test(org.junit.Test)

Aggregations

SearchBean (org.apache.cxf.jaxrs.ext.search.SearchBean)11 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 ConditionType (org.apache.cxf.jaxrs.ext.search.ConditionType)2 SyncopeFiqlSearchCondition (org.apache.syncope.common.lib.search.SyncopeFiqlSearchCondition)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)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 SearchContextProvider (org.apache.cxf.jaxrs.ext.search.SearchContextProvider)1 LuceneQueryVisitor (org.apache.cxf.jaxrs.ext.search.lucene.LuceneQueryVisitor)1 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)1