Exemple #1
0
  protected void execute(String queryString, HttpAction action) {
    String queryStringLog = ServletOps.formatForLog(queryString);
    if (action.verbose) action.log.info(format("[%d] Query = \n%s", action.id, queryString));
    else action.log.info(format("[%d] Query = %s", action.id, queryStringLog));

    Query query = null;
    try {
      // NB syntax is ARQ (a superset of SPARQL)
      query = QueryFactory.create(queryString, QueryParseBase, Syntax.syntaxARQ);
      queryStringLog = formatForLog(query);
      validateQuery(action, query);
    } catch (ActionErrorException ex) {
      throw ex;
    } catch (QueryParseException ex) {
      ServletOps.errorBadRequest(
          "Parse error: \n" + queryString + "\n\r" + messageForQueryException(ex));
    }
    // Should not happen.
    catch (QueryException ex) {
      ServletOps.errorBadRequest("Error: \n" + queryString + "\n\r" + ex.getMessage());
    }

    // Assumes finished whole thing by end of sendResult.
    try {
      action.beginRead();
      Dataset dataset = decideDataset(action, query, queryStringLog);
      try (QueryExecution qExec = createQueryExecution(query, dataset); ) {
        SPARQLResult result = executeQuery(action, qExec, query, queryStringLog);
        // Deals with exceptions itself.
        sendResults(action, result, query.getPrologue());
      }
    } catch (QueryParseException ex) {
      // Late stage static error (e.g. bad fixed Lucene query string).
      ServletOps.errorBadRequest(
          "Query parse error: \n" + queryString + "\n\r" + messageForQueryException(ex));
    } catch (QueryCancelledException ex) {
      // Additional counter information.
      incCounter(action.getEndpoint().getCounters(), QueryTimeouts);
      throw ex;
    } finally {
      action.endRead();
    }
  }