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


Java SolrException.code方法代码示例

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


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

示例1: waitForNon403or404or503

import org.apache.solr.common.SolrException; //导入方法依赖的package包/类
public  static void waitForNon403or404or503(HttpSolrServer collectionClient)
    throws Exception {
  SolrException exp = null;
  long timeoutAt = System.currentTimeMillis() + 30000;

  while (System.currentTimeMillis() < timeoutAt) {
    boolean missing = false;

    try {
      collectionClient.query(new SolrQuery("*:*"));
    } catch (SolrException e) {
      if (!(e.code() == 403 || e.code() == 503 || e.code() == 404)) {
        throw e;
      }
      exp = e;
      missing = true;
    }
    if (!missing) {
      return;
    }
    Thread.sleep(50);
  }

  fail("Could not find the new collection - " + exp.code() + " : " + collectionClient.getBaseURL());
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:AbstractFullDistribZkTestBase.java

示例2: getReturnCode

import org.apache.solr.common.SolrException; //导入方法依赖的package包/类
public static int getReturnCode( Runnable runnable )
{
  try {
    runnable.run();
  }
  catch( SolrException sx ) {
    return sx.code();
  }
  catch( Exception ex ) {
    ex.printStackTrace();
    return 500;
  }
  return 200;
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:SolrParamTest.java

示例3: getErrorInfo

import org.apache.solr.common.SolrException; //导入方法依赖的package包/类
/**
 * Adds the given Throwable's message to the given NamedList.
 * <p/>
 * If the response code is not a regular code, the Throwable's
 * stack trace is both logged and added to the given NamedList.
 * <p/>
 * Status codes less than 100 are adjusted to be 500.
 */
public static int getErrorInfo(Throwable ex, NamedList info, Logger log) {
  int code = 500;
  if (ex instanceof SolrException) {
    SolrException solrExc = (SolrException)ex;
    code = solrExc.code();
    NamedList<String> errorMetadata = solrExc.getMetadata();
    if (errorMetadata != null)
      info.add("metadata", errorMetadata);
  }
  
  for (Throwable th = ex; th != null; th = th.getCause()) {
    String msg = th.getMessage();
    if (msg != null) {
      info.add("msg", msg);
      break;
    }
  }
  
  // For any regular code, don't include the stack trace
  if (code == 500 || code < 100) {
    StringWriter sw = new StringWriter();
    ex.printStackTrace(new PrintWriter(sw));
    SolrException.log(log, null, ex);
    info.add("trace", sw.toString());

    // non standard codes have undefined results with various servers
    if (code < 100) {
      log.warn("invalid return code: " + code);
      code = 500;
    }
  }
  
  info.add("code", code);
  return code;
}
 
开发者ID:europeana,项目名称:search,代码行数:44,代码来源:ResponseUtils.java

示例4: processAdd

import org.apache.solr.common.SolrException; //导入方法依赖的package包/类
public void processAdd(AddUpdateCommand cmd) throws IOException {
  if (!isLeader(cmd)) {
    super.processAdd(cmd);
    return;
  }

  final SolrInputDocument newDoc = cmd.getSolrInputDocument();

  Object newVersion = newDoc.getFieldValue(versionFieldName);
  if ( null == newVersion ) {
    throw new SolrException(BAD_REQUEST, "Doc does not have versionField: " + versionFieldName);
  }

  for (int i=0; ;i++) {
    // Log a warning every 256 retries.... even a few retries should normally be very unusual.
    if ((i&0xff) == 0xff) {
      log.warn("Unusual number of optimistic concurrency retries: retries=" + i + " cmd=" + cmd);
    }

    if (!isVersionNewEnough(cmd.getIndexedId(), newVersion)) {
      // drop older update
      return;
    }

    try {
      cmd.setVersion(oldSolrVersion);  // use optimistic concurrency to ensure that the doc has not changed in the meantime
      super.processAdd(cmd);
      return;
    } catch (SolrException e) {
      if (e.code() == 409) {
        // log.info ("##################### CONFLICT ADDING newDoc=" + newDoc + " newVersion=" + newVersion );
        continue;  // if a version conflict, retry
      }
      throw e;  // rethrow
    }

  }
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:DocBasedVersionConstraintsProcessorFactory.java

示例5: watchCoreStartAt

import org.apache.solr.common.SolrException; //导入方法依赖的package包/类
/**
 * Polls the SolrCore stats using the specified client until the "startTime" 
 * time for collection is after the specified "min".  Will loop for 
 * at most "timeout" milliseconds before throwing an assertion failure.
 * 
 * @param client The SolrServer to poll
 * @param timeout the max milliseconds to continue polling for
 * @param min the startTime value must exceed this value before the method will return, if null this method will return the first startTime value encountered.
 * @return the startTime value of collection
 */
private Date watchCoreStartAt(SolrServer client, final long timeout, 
                              final Date min) throws InterruptedException, IOException, SolrServerException {
  final long sleepInterval = 200;
  long timeSlept = 0;

  SolrParams p = params("action","status", "core", "collection1");
  while (timeSlept < timeout) {
    QueryRequest req = new QueryRequest(p);
    req.setPath("/admin/cores");
    try {
      NamedList data = client.request(req);
      for (String k : new String[] {"status","collection1"}) {
        Object o = data.get(k);
        assertNotNull("core status rsp missing key: " + k, o);
        data = (NamedList) o;
      }
      Date startTime = (Date) data.get("startTime");
      assertNotNull("core has null startTime", startTime);
      if (null == min || startTime.after(min)) {
        return startTime;
      }
    } catch (SolrException e) {
      // workarround for SOLR-4668
      if (500 != e.code()) {
        throw e;
      } // else server possibly from the core reload in progress...
    }

    timeSlept += sleepInterval;
    Thread.sleep(sleepInterval);
  }
  fail("timed out waiting for collection1 startAt time to exceed: " + min);
  return min; // compilation neccessity
}
 
开发者ID:europeana,项目名称:search,代码行数:45,代码来源:TestReplicationHandler.java

示例6: translateSolrException

import org.apache.solr.common.SolrException; //导入方法依赖的package包/类
private DataAccessException translateSolrException(String message, SolrException e) {
    if (e.code() == BAD_REQUEST.ordinal()) {
        return new InvalidDataAccessResourceUsageException(message, e);
    } else if (e.code() == UNAUTHORIZED.ordinal() || e.code() == FORBIDDEN.ordinal()) {
        return new PermissionDeniedDataAccessException(message, e);
    } else if (e.code() == NOT_FOUND.ordinal()) {
        return new InvalidDataAccessApiUsageException(message, e);
    } else {
        return new DataAccessResourceFailureException(message, e);
    }
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:12,代码来源:DefaultSolrDao.java


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