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


Java SolrQueryResponse.getException方法代码示例

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


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

示例1: query

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
/**
 * Processes a "query" using a user constructed SolrQueryRequest, and closes the request at the end.
 *
 * @param handler the name of the request handler to process the request
 * @param req the Query to process, will be closed.
 * @return The XML response to the query
 * @exception Exception any exception in the response.
 * @exception IOException if there is a problem writing the XML
 * @see LocalSolrQueryRequest
 */
public String query(String handler, SolrQueryRequest req) throws Exception {
  try (SolrCore core = getCoreInc()) {
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
    core.execute(core.getRequestHandler(handler),req,rsp);
    if (rsp.getException() != null) {
      throw rsp.getException();
    }
    StringWriter sw = new StringWriter(32000);
    QueryResponseWriter responseWriter = core.getQueryResponseWriter(req);
    responseWriter.write(sw,req,rsp);

    req.close();

    return sw.toString();
  } finally {
    req.close();
    SolrRequestInfo.clearRequestInfo();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:TestHarness.java

示例2: write

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException
{
    Gson gson = new GsonBuilder().registerTypeAdapter(ResponseValue.class, new ResponseValueSerializer()).create();
    Exception e = response.getException();
    int status = (int)response.getResponseHeader().get("status");
    KnowledgeGraphResponse model = (KnowledgeGraphResponse)response.getValues().get("relatednessResponse");
    if(e != null) {
        if(model == null) {
            model = new KnowledgeGraphResponse();
        }
        model.error = new Error(e.getMessage(), status);
    }
    writer.write(gson.toJson(model, KnowledgeGraphResponse.class));
}
 
开发者ID:careerbuilder,项目名称:semantic-knowledge-graph,代码行数:15,代码来源:KnowledgeGraphResponseWriter.java

示例3: queryAndResponse

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
/** It is the users responsibility to close the request object when done with it.
 * This method does not set/clear SolrRequestInfo */
public SolrQueryResponse queryAndResponse(String handler, SolrQueryRequest req) throws Exception {
  try (SolrCore core = getCoreInc()) {
    SolrQueryResponse rsp = new SolrQueryResponse();
    core.execute(core.getRequestHandler(handler), req, rsp);
    if (rsp.getException() != null) {
      throw rsp.getException();
    }
    return rsp;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:TestHarness.java

示例4: checkHttpCachingVeto

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
/**
 * Checks if the downstream request handler wants to avoid HTTP caching of
 * the response.
 * 
 * @param solrRsp The Solr response object
 * @param resp The HTTP servlet response object
 * @param reqMethod The HTTP request type
 */
public static void checkHttpCachingVeto(final SolrQueryResponse solrRsp,
    HttpServletResponse resp, final Method reqMethod) {
  // For POST we do nothing. They never get cached
  if (Method.POST == reqMethod || Method.OTHER == reqMethod) {
    return;
  }
  // If the request handler has not vetoed and there is no
  // exception silently return
  if (solrRsp.isHttpCaching() && solrRsp.getException() == null) {
    return;
  }
  
  // Otherwise we tell the caches that we don't want to cache the response
  resp.setHeader("Cache-Control", "no-cache, no-store");

  // For HTTP/1.0 proxy caches
  resp.setHeader("Pragma", "no-cache");

  // This sets the expiry date to a date in the past
  // As long as no time machines get invented this is safe
  resp.setHeader("Expires", "Sat, 01 Jan 2000 01:00:00 GMT");

  // We signal "just modified" just in case some broken
  // proxy cache does not follow the above headers
  resp.setDateHeader("Last-Modified", System.currentTimeMillis());
  
  // We override the ETag with something different
  resp.setHeader("ETag", '"'+Long.toHexString(System.currentTimeMillis())+'"');
}
 
开发者ID:europeana,项目名称:search,代码行数:38,代码来源:HttpCacheHeaderUtil.java

示例5: handlePing

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
protected void handlePing(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
{
  
  SolrParams params = req.getParams();
  SolrCore core = req.getCore();
  
  // Get the RequestHandler
  String qt = params.get( CommonParams.QT );//optional; you get the default otherwise
  SolrRequestHandler handler = core.getRequestHandler( qt );
  if( handler == null ) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, 
        "Unknown RequestHandler (qt): "+qt );
  }
  
  if( handler instanceof PingRequestHandler ) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, 
        "Cannot execute the PingRequestHandler recursively" );
  }
  
  // Execute the ping query and catch any possible exception
  Throwable ex = null;
  try {
    SolrQueryResponse pingrsp = new SolrQueryResponse();
    core.execute(handler, req, pingrsp );
    ex = pingrsp.getException();
  }
  catch( Exception e ) {
    ex = e;
  }
  
  // Send an error or an 'OK' message (response code will be 200)
  if( ex != null ) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, 
        "Ping query caused exception: "+ex.getMessage(), ex );
  }
  rsp.add( "status", "OK" );
}
 
开发者ID:europeana,项目名称:search,代码行数:38,代码来源:PingRequestHandler.java

示例6: getResponse

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
/** make sure to close req after you are done using the response */
public SolrQueryResponse getResponse(SolrQueryRequest req) throws Exception {
  SolrQueryResponse rsp = new SolrQueryResponse();
  h.getCore().execute(h.getCore().getRequestHandler(null),req,rsp);
  if (rsp.getException() != null) {
    throw rsp.getException();
  }
  return rsp;
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:TestWriterPerf.java

示例7: if

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
/** Put status, QTime, and possibly request handler and params, in the response header */
public static void postDecorateResponse
    (SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp) {
  // TODO should check that responseHeader has not been replaced by handler
  NamedList<Object> responseHeader = rsp.getResponseHeader();
  final int qtime=(int)(rsp.getEndTime() - req.getStartTime());
  int status = 0;
  Exception exception = rsp.getException();
  if( exception != null ){
    if( exception instanceof SolrException )
      status = ((SolrException)exception).code();
    else
      status = 500;
  }
  responseHeader.add("status",status);
  responseHeader.add("QTime",qtime);

  if (rsp.getToLog().size() > 0) {
    rsp.getToLog().add("status",status);
    rsp.getToLog().add("QTime",qtime);
  }

  SolrParams params = req.getParams();
  if( null != handler && params.getBool(CommonParams.HEADER_ECHO_HANDLER, false) ) {
    responseHeader.add("handler", handler.getName() );
  }

  // Values for echoParams... false/true/all or false/explicit/all ???
  String ep = params.get( CommonParams.HEADER_ECHO_PARAMS, null );
  if( ep != null ) {
    EchoParamStyle echoParams = EchoParamStyle.get( ep );
    if( echoParams == null ) {
      throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Invalid value '" + ep + "' for " + CommonParams.HEADER_ECHO_PARAMS 
          + " parameter, use '" + EchoParamStyle.EXPLICIT + "' or '" + EchoParamStyle.ALL + "'" );
    }
    if( echoParams == EchoParamStyle.EXPLICIT ) {
      responseHeader.add("params", req.getOriginalParams().toNamedList());
    } else if( echoParams == EchoParamStyle.ALL ) {
      responseHeader.add("params", req.getParams().toNamedList());
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:43,代码来源:SolrCore.java

示例8: testEnablingServer

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
public void testEnablingServer() throws Exception {

    assertTrue(!healthcheckFile.exists());

    // first make sure that ping responds back that the service is disabled
    SolrQueryResponse sqr = makeRequest(handler, req());
    SolrException se = (SolrException) sqr.getException();
    assertEquals(
      "Response should have been replaced with a 503 SolrException.",
      se.code(), SolrException.ErrorCode.SERVICE_UNAVAILABLE.code);

    // now enable

    makeRequest(handler, req("action", "enable"));

    assertTrue(healthcheckFile.exists());
    assertNotNull(FileUtils.readFileToString(healthcheckFile, "UTF-8"));

    // now verify that the handler response with success

    SolrQueryResponse rsp = makeRequest(handler, req());
    assertEquals("OK", rsp.getValues().get("status"));

    // enable when already enabled shouldn't cause any problems
    makeRequest(handler, req("action", "enable"));
    assertTrue(healthcheckFile.exists());

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

示例9: testDisablingServer

import org.apache.solr.response.SolrQueryResponse; //导入方法依赖的package包/类
public void testDisablingServer() throws Exception {

    assertTrue(! healthcheckFile.exists());
        
    healthcheckFile.createNewFile();

    // first make sure that ping responds back that the service is enabled

    SolrQueryResponse rsp = makeRequest(handler, req());
    assertEquals("OK", rsp.getValues().get("status"));

    // now disable
    
    makeRequest(handler, req("action", "disable"));
    
    assertFalse(healthcheckFile.exists());

    // now make sure that ping responds back that the service is disabled    
    SolrQueryResponse sqr = makeRequest(handler, req());
    SolrException se = (SolrException) sqr.getException();
    assertEquals(
      "Response should have been replaced with a 503 SolrException.",
      se.code(), SolrException.ErrorCode.SERVICE_UNAVAILABLE.code);
    
    // disable when already disabled shouldn't cause any problems
    makeRequest(handler, req("action", "disable"));
    assertFalse(healthcheckFile.exists());
    
  }
 
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:PingRequestHandlerTest.java


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