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);
}
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;
}
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();
}
}
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();
}
}
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));
}
Aggregations