Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.handler.admin;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.invoke.MethodHandles;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.apache.solr.cloud.ZkSolrResourceLoader;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.RawResponseWriter;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.security.AuthorizationContext;
import org.apache.solr.security.PermissionNameProvider;
import org.apache.zookeeper.KeeperException;
import org.eclipse.jetty.http.MimeTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This handler uses the RawResponseWriter to give client access to files inside ${solr.home}/conf
*
*
If you want to selectively restrict access some configuration files, you can list these files
* in the {@link #HIDDEN} invariants. For example to hide synonyms.txt and anotherfile.txt, you
* would register:
*
*
*
* At present, there is only explicit file names (including path) or the glob '*' are supported.
* Variants like '*.xml' are NOT supported.ere
*
*
The ShowFileRequestHandler uses the {@link RawResponseWriter} (wt=raw) to return file
* contents. If you need to use a different writer, you will need to change the registered invariant
* param for wt.
*
*
If you want to override the contentType header returned for a given file, you can set it
* directly using: {@link #USE_CONTENT_TYPE}. For example, to get a plain text version of
* schema.xml, try:
*
*
*
* @since solr 1.3
*/
public class ShowFileRequestHandler extends RequestHandlerBase implements PermissionNameProvider {
public static final String HIDDEN = "hidden";
public static final String USE_CONTENT_TYPE = "contentType";
private static final Set KNOWN_MIME_TYPES;
protected Set hiddenFiles;
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
static {
KNOWN_MIME_TYPES = new HashSet<>(MimeTypes.getKnownMimeTypes());
KNOWN_MIME_TYPES.add("text/xml");
KNOWN_MIME_TYPES.add("text/javascript");
}
public ShowFileRequestHandler() {
super();
}
@Override
public void init(NamedList args) {
super.init(args);
hiddenFiles = initHidden(invariants);
}
public static Set initHidden(SolrParams invariants) {
Set hiddenRet = new HashSet<>();
// Build a list of hidden files
if (invariants != null) {
String[] hidden = invariants.getParams(HIDDEN);
if (hidden != null) {
for (String s : hidden) {
hiddenRet.add(s.toUpperCase(Locale.ROOT));
}
}
}
return hiddenRet;
}
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
throws InterruptedException, KeeperException, IOException {
CoreContainer coreContainer = req.getCoreContainer();
if (coreContainer.isZooKeeperAware()) {
showFromZooKeeper(req, rsp, coreContainer);
} else {
showFromFileSystem(req, rsp);
}
}
// 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 children = zkClient.getChildren(adminFile, null, true);
if (children.size() > 0) {
NamedList> files = new SimpleOrderedMap<>();
for (String f : children) {
if (isHiddenFile(req, rsp, f, false, hiddenFiles)) {
continue;
}
SimpleOrderedMap