Search in sources :

Example 1 with ContentStreamLoader

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;
}
Also used : ContentStreamLoader(org.apache.solr.handler.loader.ContentStreamLoader) HashMap(java.util.HashMap) CSVLoader(org.apache.solr.handler.loader.CSVLoader) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) MapSolrParams(org.apache.solr.common.params.MapSolrParams) JsonLoader(org.apache.solr.handler.loader.JsonLoader) JavabinLoader(org.apache.solr.handler.loader.JavabinLoader) XMLLoader(org.apache.solr.handler.loader.XMLLoader)

Example 2 with ContentStreamLoader

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));
    }
}
Also used : ContentStreamLoader(org.apache.solr.handler.loader.ContentStreamLoader) ContentStream(org.apache.solr.common.util.ContentStream) SolrException(org.apache.solr.common.SolrException)

Example 3 with ContentStreamLoader

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();
}
Also used : ContentStreamLoader(org.apache.solr.handler.loader.ContentStreamLoader) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) BufferingRequestProcessor(org.apache.solr.update.processor.BufferingRequestProcessor) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) NamedList(org.apache.solr.common.util.NamedList) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Test(org.junit.Test)

Example 4 with ContentStreamLoader

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();
        }
    }
}
Also used : ContentStreamLoader(org.apache.solr.handler.loader.ContentStreamLoader) ContentStream(org.apache.solr.common.util.ContentStream) SolrParams(org.apache.solr.common.params.SolrParams) UpdateRequestProcessorChain(org.apache.solr.update.processor.UpdateRequestProcessorChain) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) SolrException(org.apache.solr.common.SolrException)

Aggregations

ContentStreamLoader (org.apache.solr.handler.loader.ContentStreamLoader)4 SolrException (org.apache.solr.common.SolrException)2 SolrParams (org.apache.solr.common.params.SolrParams)2 ContentStream (org.apache.solr.common.util.ContentStream)2 HashMap (java.util.HashMap)1 BinaryRequestWriter (org.apache.solr.client.solrj.impl.BinaryRequestWriter)1 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 MapSolrParams (org.apache.solr.common.params.MapSolrParams)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1 NamedList (org.apache.solr.common.util.NamedList)1 CSVLoader (org.apache.solr.handler.loader.CSVLoader)1 JavabinLoader (org.apache.solr.handler.loader.JavabinLoader)1 JsonLoader (org.apache.solr.handler.loader.JsonLoader)1 XMLLoader (org.apache.solr.handler.loader.XMLLoader)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)1 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)1 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)1 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)1