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();
  }
}

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 ( ) ; } }
processes a " query " using a user constructed solrqueryrequest , and closes the request at the end .
