org.apache.solr.handler.loader.ContentStreamLoader Java Examples
The following examples show how to use
org.apache.solr.handler.loader.ContentStreamLoader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricsCollectorHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { if (coreContainer == null || coreContainer.isShutDown()) { // silently drop request return; } //log.info("#### {}", req); if (req.getContentStreams() == null) { // no content return; } for (ContentStream cs : req.getContentStreams()) { if (cs.getContentType() == null) { log.warn("Missing content type - ignoring"); continue; } ContentStreamLoader loader = loaders.get(cs.getContentType()); if (loader == null) { throw new SolrException(SolrException.ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Unsupported content type for stream: " + cs.getSourceInfo() + ", contentType=" + cs.getContentType()); } loader.load(req, rsp, cs, new MetricUpdateProcessor(metricManager)); } }
Example #2
Source File: UpdateRequestHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
protected Map<String,ContentStreamLoader> createDefaultLoaders(@SuppressWarnings({"rawtypes"})NamedList args) { SolrParams p = null; if(args!=null) { p = args.toSolrParams(); } Map<String,ContentStreamLoader> registry = new HashMap<>(); registry.put("application/xml", new XMLLoader().init(p) ); registry.put("application/json", new JsonLoader().init(p) ); registry.put("application/csv", new CSVLoader().init(p) ); registry.put("application/javabin", new JavabinLoader(instance).init(p) ); registry.put("text/csv", registry.get("application/csv") ); registry.put("text/xml", registry.get("application/xml") ); registry.put("text/json", registry.get("application/json")); pathVsLoaders.put(JSON_PATH,registry.get("application/json")); pathVsLoaders.put(DOC_PATH,registry.get("application/json")); pathVsLoaders.put(CSV_PATH,registry.get("application/csv")); pathVsLoaders.put(BIN_PATH,registry.get("application/javabin")); return registry; }
Example #3
Source File: RdfBulkUpdateRequestHandler.java From SolRDF with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("rawtypes") protected Map<String, ContentStreamLoader> createDefaultLoaders(final NamedList parameters) { final Map<String, ContentStreamLoader> registry = new HashMap<String, ContentStreamLoader>(); final ContentStreamLoader loader = new RdfDataLoader(); for (final Lang language : RDFLanguages.getRegisteredLanguages()) { registry.put(language.getContentType().toHeaderString(), loader); } registry.put(WebContent.contentTypeSPARQLUpdate, new Sparql11UpdateRdfDataLoader()); if (log.isDebugEnabled()) { prettyPrint(registry); } return registry; }
Example #4
Source File: ContentStreamHandlerBase.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { SolrParams params = req.getParams(); UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessorChain(params); UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp); try { ContentStreamLoader documentLoader = newLoader(req, processor); Iterable<ContentStream> streams = req.getContentStreams(); if (streams == null) { if (!RequestHandlerUtils.handleCommit(req, processor, params, false) && !RequestHandlerUtils.handleRollback(req, processor, params, false)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "missing content stream"); } } else { for (ContentStream stream : streams) { documentLoader.load(req, rsp, stream, processor); } // Perhaps commit from the parameters RequestHandlerUtils.handleCommit(req, processor, params, false); RequestHandlerUtils.handleRollback(req, processor, params, false); } } finally { // finish the request try { processor.finish(); } finally { processor.close(); } } }
Example #5
Source File: UpdateRequestHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void load(SolrQueryRequest req, SolrQueryResponse rsp, ContentStream stream, UpdateRequestProcessor processor) throws Exception { ContentStreamLoader loader = pathVsLoaders.get(req.getContext().get(PATH)); if(loader == null) { String type = req.getParams().get(UpdateParams.ASSUME_CONTENT_TYPE); if (type == null) { type = stream.getContentType(); } if (type == null) { // Normal requests will not get here. throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Missing ContentType"); } int idx = type.indexOf(';'); if (idx > 0) { type = type.substring(0, idx); } loader = loaders.get(type); if (loader == null) { throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Unsupported ContentType: " + type + " Not in: " + loaders.keySet()); } } if(loader.getDefaultWT()!=null) { setDefaultWT(req,loader); } loader.load(req, rsp, stream, processor); }
Example #6
Source File: UpdateRequestHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
private void setDefaultWT(SolrQueryRequest req, ContentStreamLoader loader) { SolrParams params = req.getParams(); if( params.get(CommonParams.WT) == null ) { String wt = loader.getDefaultWT(); // Make sure it is a valid writer if(req.getCore().getQueryResponseWriter(wt)!=null) { Map<String,String> map = new HashMap<>(1); map.put(CommonParams.WT, wt); req.setParams(SolrParams.wrapDefaults(params, new MapSolrParams(map))); } } }
Example #7
Source File: RdfUpdateRequestHandler.java From SolRDF with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("rawtypes") protected Map<String, ContentStreamLoader> createDefaultLoaders(final NamedList parameters) { final Map<String, ContentStreamLoader> registry = new HashMap<String, ContentStreamLoader>(); registry.put(WebContent.contentTypeHTMLForm, new Sparql11UpdateRdfDataLoader()); registry.put("application/rdf+xml", new Sparql11UpdateRdfDataLoader()); registry.put(WebContent.contentTypeSPARQLUpdate, new Sparql11UpdateRdfDataLoader()); if (log.isDebugEnabled()) { prettyPrint(registry); } return registry; }
Example #8
Source File: ExtractingRequestHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override protected ContentStreamLoader newLoader(SolrQueryRequest req, UpdateRequestProcessor processor) { return new ExtractingDocumentLoader(req, processor, config, parseContextConfig, factory); }
Example #9
Source File: UpdateRequestHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override protected ContentStreamLoader newLoader(SolrQueryRequest req, final UpdateRequestProcessor processor) { return instance; }
Example #10
Source File: RdfBulkUpdateRequestHandler.java From SolRDF with Apache License 2.0 | 4 votes |
@Override public void load( final SolrQueryRequest request, final SolrQueryResponse response, final ContentStream stream, final UpdateRequestProcessor processor) throws Exception { // Default ContentStream implementation starts reading the stream and // if it starts with '<' then it assumes a content type of "application/xml", // if it starts with '{' then it assumes a content type of "application/json" // This behaviour is wrong is SolRDF and maybe we need a custom ContentStream here // At the moment this is just a workaround: final String contentType = stream.getContentType() != null && !"application/xml".equals(stream.getContentType()) && !"application/json".equals(stream.getContentType()) ? stream.getContentType() : request.getParams().get(UpdateParams.ASSUME_CONTENT_TYPE); log.debug(MessageCatalog._00094_BULK_LOADER_CT, contentType); final Lang lang = RDFLanguages.contentTypeToLang(contentType); if (lang == null) { final String message = MessageFactory.createMessage(MessageCatalog._00095_INVALID_CT, contentType); log.error(message); throw new SolrException(ErrorCode.BAD_REQUEST, message); } final ContentStreamLoader delegate = (lang == Lang.NQ || lang == Lang.NQUADS || lang == Lang.TRIG) ? quadsLoader : triplesLoader; log.debug(MessageCatalog._00096_SELECTED_BULK_LOADER, contentType, delegate); delegate.load( request, response, new ContentStream() { @Override public InputStream getStream() throws IOException { return stream.getStream(); } @Override public String getSourceInfo() { return stream.getSourceInfo(); } @Override public Long getSize() { return stream.getSize(); } @Override public Reader getReader() throws IOException { return stream.getReader(); } @Override public String getName() { return stream.getName(); } @Override public String getContentType() { return contentType; } }, processor); }
Example #11
Source File: RdfBulkUpdateRequestHandler.java From SolRDF with Apache License 2.0 | 4 votes |
/** * Debugs the registry content. */ void prettyPrint(final Map<String, ContentStreamLoader> registry) { for (final Entry<String, ContentStreamLoader> entry : registry.entrySet()) { log.debug(MessageCatalog._00097_BULK_LOADER_REGISTRY_ENTRY, entry.getKey(), entry.getValue()); } }
Example #12
Source File: RdfUpdateRequestHandler.java From SolRDF with Apache License 2.0 | 4 votes |
/** * Debugs the registry content. */ void prettyPrint(final Map<String, ContentStreamLoader> registry) { for (final Entry<String, ContentStreamLoader> entry : registry.entrySet()) { log.debug(MessageCatalog._00098_UPDATE_HANDLER_REGISTRY_ENTRY, entry.getKey(), entry.getValue()); } }
Example #13
Source File: FlatDataUpdateRequestHandler.java From apache-solr-essentials with Apache License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") protected Map<String,ContentStreamLoader> createDefaultLoaders(NamedList args) { Map<String,ContentStreamLoader> registry = new HashMap<String,ContentStreamLoader>(); registry.put("text/plain", new FlatDataLoader()); return registry; }
Example #14
Source File: ContentStreamHandlerBase.java From lucene-solr with Apache License 2.0 | votes |
protected abstract ContentStreamLoader newLoader(SolrQueryRequest req, UpdateRequestProcessor processor);