当前位置: 首页>>代码示例>>Java>>正文


Java SolrQueryResponse.setException方法代码示例

本文整理汇总了Java中org.apache.solr.response.SolrQueryResponse.setException方法的典型用法代码示例。如果您正苦于以下问题:Java SolrQueryResponse.setException方法的具体用法?Java SolrQueryResponse.setException怎么用?Java SolrQueryResponse.setException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.response.SolrQueryResponse的用法示例。


在下文中一共展示了SolrQueryResponse.setException方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isHiddenFile

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
public static boolean isHiddenFile(SolrQueryRequest req, SolrQueryResponse rsp, String fnameIn, boolean reportError,
                                   Set<String> hiddenFiles) {
  String fname = fnameIn.toUpperCase(Locale.ROOT);
  if (hiddenFiles.contains(fname) || hiddenFiles.contains("*")) {
    if (reportError) {
      log.error("Cannot access " + fname);
      rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Can not access: " + fnameIn));
    }
    return true;
  }

  // This is slightly off, a valid path is something like ./schema.xml. I don't think it's worth the effort though
  // to fix it to handle all possibilities though.
  if (fname.indexOf("..") >= 0 || fname.startsWith(".")) {
    if (reportError) {
      log.error("Invalid path: " + fname);
      rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Invalid path: " + fnameIn));
    }
    return true;
  }

  // Make sure that if the schema is managed, we don't allow editing. Don't really want to put
  // this in the init since we're not entirely sure when the managed schema will get initialized relative to this
  // handler.
  SolrCore core = req.getCore();
  IndexSchema schema = core.getLatestSchema();
  if (schema instanceof ManagedIndexSchema) {
    String managed = schema.getResourceName();

    if (fname.equalsIgnoreCase(managed)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:europeana,项目名称:search,代码行数:36,代码来源:ShowFileRequestHandler.java

示例2: getAdminFileFromZooKeeper

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
public static String getAdminFileFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp, SolrZkClient zkClient,
                                               Set<String> hiddenFiles)
    throws KeeperException, InterruptedException {
  String adminFile = null;
  SolrCore core = req.getCore();

  final ZkSolrResourceLoader loader = (ZkSolrResourceLoader) core
      .getResourceLoader();
  String confPath = loader.getCollectionZkPath();

  String fname = req.getParams().get("file", null);
  if (fname == null) {
    adminFile = confPath;
  } else {
    fname = fname.replace('\\', '/'); // normalize slashes
    if (isHiddenFile(req, rsp, fname, true, hiddenFiles)) {
      return null;
    }
    if (fname.startsWith("/")) { // Only files relative to conf are valid
      fname = fname.substring(1);
    }
    adminFile = confPath + "/" + fname;
  }

  // Make sure the file exists, is readable and is not a hidden file
  if (!zkClient.exists(adminFile, true)) {
    log.error("Can not find: " + adminFile);
    rsp.setException(new SolrException(SolrException.ErrorCode.NOT_FOUND, "Can not find: "
        + adminFile));
    return null;
  }

  return adminFile;
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:ShowFileRequestHandler.java

示例3: getAdminFileFromFileSystem

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
public static File getAdminFileFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp,
                                              Set<String> hiddenFiles) {
  File adminFile = null;
  final SolrResourceLoader loader = req.getCore().getResourceLoader();
  File configdir = new File( loader.getConfigDir() );
  if (!configdir.exists()) {
    // TODO: maybe we should just open it this way to start with?
    try {
      configdir = new File( loader.getClassLoader().getResource(loader.getConfigDir()).toURI() );
    } catch (URISyntaxException e) {
      log.error("Can not access configuration directory!");
      rsp.setException(new SolrException( SolrException.ErrorCode.FORBIDDEN, "Can not access configuration directory!", e));
      return null;
    }
  }
  String fname = req.getParams().get("file", null);
  if( fname == null ) {
    adminFile = configdir;
  }
  else {
    fname = fname.replace( '\\', '/' ); // normalize slashes
    if( hiddenFiles.contains( fname.toUpperCase(Locale.ROOT) ) ) {
      log.error("Can not access: "+ fname);
      rsp.setException(new SolrException( SolrException.ErrorCode.FORBIDDEN, "Can not access: "+fname ));
      return null;
    }
    if( fname.indexOf( ".." ) >= 0 ) {
      log.error("Invalid path: "+ fname);
      rsp.setException(new SolrException( SolrException.ErrorCode.FORBIDDEN, "Invalid path: "+fname ));
      return null;
    }
    adminFile = new File( configdir, fname );
  }
  return adminFile;
}
 
开发者ID:europeana,项目名称:search,代码行数:36,代码来源:ShowFileRequestHandler.java

示例4: showFromFileSystem

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
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 );
      path = path.replace( '\\', '/' ); // normalize slashes

      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);
}
 
开发者ID:europeana,项目名称:search,代码行数:64,代码来源:ShowFileRequestHandler.java


注:本文中的org.apache.solr.response.SolrQueryResponse.setException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。