use of org.apache.solr.handler.loader.ContentStreamLoader in project lucene-solr by apache.
the class UpdateRequestHandler method createDefaultLoaders.
protected Map<String, ContentStreamLoader> createDefaultLoaders(NamedList args) {
SolrParams p = null;
if (args != null) {
p = SolrParams.toSolrParams(args);
}
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().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;
}
use of org.apache.solr.handler.loader.ContentStreamLoader in project lucene-solr by apache.
the class MetricsCollectorHandler method handleRequestBody.
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
if (coreContainer == null || coreContainer.isShutDown()) {
// silently drop request
return;
}
//log.info("#### " + req.toString());
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));
}
}
use of org.apache.solr.handler.loader.ContentStreamLoader in project lucene-solr by apache.
the class BinaryUpdateRequestHandlerTest method testRequestParams.
@Test
public void testRequestParams() throws Exception {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "1");
UpdateRequest ureq = new UpdateRequest();
ureq.add(doc);
ureq.setParam(UpdateParams.COMMIT_WITHIN, "100");
ureq.setParam(UpdateParams.OVERWRITE, Boolean.toString(false));
BinaryRequestWriter brw = new BinaryRequestWriter();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
SolrQueryResponse rsp = new SolrQueryResponse();
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(new NamedList());
SolrQueryRequest req = req();
ContentStreamLoader csl = handler.newLoader(req, p);
csl.load(req, rsp, brw.getContentStream(ureq), p);
AddUpdateCommand add = p.addCommands.get(0);
System.out.println(add.solrDoc);
assertEquals(false, add.overwrite);
assertEquals(100, add.commitWithin);
req.close();
}
use of org.apache.solr.handler.loader.ContentStreamLoader in project lucene-solr by apache.
the class ContentStreamHandlerBase method handleRequestBody.
@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();
}
}
}
Aggregations