Search in sources :

Example 6 with ContentStreamBase

use of org.apache.solr.common.util.ContentStreamBase in project lucene-solr by apache.

the class TestCSVLoader method loadLocal.

void loadLocal(String... args) throws Exception {
    LocalSolrQueryRequest req = (LocalSolrQueryRequest) req(args);
    // TODO: stop using locally defined streams once stream.file and
    // stream.body work everywhere
    List<ContentStream> cs = new ArrayList<>(1);
    ContentStreamBase f = new ContentStreamBase.FileStream(new File(filename));
    f.setContentType("text/csv");
    cs.add(f);
    req.setContentStreams(cs);
    h.query("/update", req);
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) ContentStream(org.apache.solr.common.util.ContentStream) ArrayList(java.util.ArrayList) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 7 with ContentStreamBase

use of org.apache.solr.common.util.ContentStreamBase in project lucene-solr by apache.

the class ShowFileRequestHandler method showFromFileSystem.

// Return the file indicated (or the directory listing) from the local file system.
private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) {
    File adminFile = getAdminFileFromFileSystem(req, rsp, hiddenFiles);
    if (adminFile == null) {
        // exception already recorded
        return;
    }
    // Make sure the file exists, is readable and is not a hidden file
    if (!adminFile.exists()) {
        log.error("Can not find: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]");
        rsp.setException(new SolrException(ErrorCode.NOT_FOUND, "Can not find: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]"));
        return;
    }
    if (!adminFile.canRead() || adminFile.isHidden()) {
        log.error("Can not show: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]");
        rsp.setException(new SolrException(ErrorCode.NOT_FOUND, "Can not show: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]"));
        return;
    }
    // Show a directory listing
    if (adminFile.isDirectory()) {
        // it's really a directory, just go for it.
        int basePath = adminFile.getAbsolutePath().length() + 1;
        NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>();
        for (File f : adminFile.listFiles()) {
            String path = f.getAbsolutePath().substring(basePath);
            // normalize slashes
            path = path.replace('\\', '/');
            if (isHiddenFile(req, rsp, f.getName().replace('\\', '/'), false, hiddenFiles)) {
                continue;
            }
            SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>();
            files.add(path, fileInfo);
            if (f.isDirectory()) {
                fileInfo.add("directory", true);
            } else {
                // TODO? content type
                fileInfo.add("size", f.length());
            }
            fileInfo.add("modified", new Date(f.lastModified()));
        }
        rsp.add("files", files);
    } else {
        // Include the file contents
        //The file logic depends on RawResponseWriter, so force its use.
        ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
        params.set(CommonParams.WT, "raw");
        req.setParams(params);
        ContentStreamBase content = new ContentStreamBase.FileStream(adminFile);
        content.setContentType(req.getParams().get(USE_CONTENT_TYPE));
        rsp.add(RawResponseWriter.CONTENT, content);
    }
    rsp.setHttpCaching(false);
}
Also used : File(java.io.File) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrException(org.apache.solr.common.SolrException) Date(java.util.Date) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 8 with ContentStreamBase

use of org.apache.solr.common.util.ContentStreamBase in project lucene-solr by apache.

the class ShowFileRequestHandler method showFromZooKeeper.

// Get a list of files from ZooKeeper for from the path in the file= parameter.
private void showFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer coreContainer) throws KeeperException, InterruptedException, UnsupportedEncodingException {
    SolrZkClient zkClient = coreContainer.getZkController().getZkClient();
    String adminFile = getAdminFileFromZooKeeper(req, rsp, zkClient, hiddenFiles);
    if (adminFile == null) {
        return;
    }
    // Show a directory listing
    List<String> children = zkClient.getChildren(adminFile, null, true);
    if (children.size() > 0) {
        NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>();
        for (String f : children) {
            if (isHiddenFile(req, rsp, f, false, hiddenFiles)) {
                continue;
            }
            SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>();
            files.add(f, fileInfo);
            List<String> fchildren = zkClient.getChildren(adminFile + "/" + f, null, true);
            if (fchildren.size() > 0) {
                fileInfo.add("directory", true);
            } else {
                // TODO? content type
                fileInfo.add("size", f.length());
            }
        // TODO: ?
        // fileInfo.add( "modified", new Date( f.lastModified() ) );
        }
        rsp.add("files", files);
    } else {
        // Include the file contents
        // The file logic depends on RawResponseWriter, so force its use.
        ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
        params.set(CommonParams.WT, "raw");
        req.setParams(params);
        ContentStreamBase content = new ContentStreamBase.ByteArrayStream(zkClient.getData(adminFile, null, null, true), adminFile);
        content.setContentType(req.getParams().get(USE_CONTENT_TYPE));
        rsp.add(RawResponseWriter.CONTENT, content);
    }
    rsp.setHttpCaching(false);
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Aggregations

ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)8 ContentStream (org.apache.solr.common.util.ContentStream)4 ArrayList (java.util.ArrayList)3 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)3 File (java.io.File)2 SolrException (org.apache.solr.common.SolrException)2 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)2 URL (java.net.URL)1 Date (java.util.Date)1 V2HttpCall (org.apache.solr.api.V2HttpCall)1 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)1 MapSolrParams (org.apache.solr.common.params.MapSolrParams)1 SolrParams (org.apache.solr.common.params.SolrParams)1 CommandOperation (org.apache.solr.common.util.CommandOperation)1 NamedList (org.apache.solr.common.util.NamedList)1 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)1 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)1 SolrQueryRequestBase (org.apache.solr.request.SolrQueryRequestBase)1 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)1 UpdateRequestProcessorChain (org.apache.solr.update.processor.UpdateRequestProcessorChain)1