當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。