コード例 #1
0
ファイル: SPARQL_Query.java プロジェクト: johnulist/jena
  /**
   * Helper method for validating request.
   *
   * @param request HTTP request
   * @param params parameters in a collection of Strings
   */
  protected void validateParams(HttpAction action, Collection<String> params) {
    HttpServletRequest request = action.request;
    ContentType ct = FusekiLib.getContentType(request);
    boolean mustHaveQueryParam = true;
    if (ct != null) {
      String incoming = ct.getContentType();

      if (matchContentType(ctSPARQLQuery, ct)) {
        mustHaveQueryParam = false;
        // Drop through.
      } else if (matchContentType(ctHTMLForm, ct)) {
        // Nothing specific to do
      } else ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Unsupported: " + incoming);
    }

    // GET/POST of a form at this point.

    if (mustHaveQueryParam) {
      int N = countParamOccurences(request, paramQuery);

      if (N == 0) ServletOps.errorBadRequest("SPARQL Query: No 'query=' parameter");
      if (N > 1) ServletOps.errorBadRequest("SPARQL Query: Multiple 'query=' parameters");

      // application/sparql-query does not use a query param.
      String queryStr = request.getParameter(HttpNames.paramQuery);

      if (queryStr == null)
        ServletOps.errorBadRequest("SPARQL Query: No query specified (no 'query=' found)");
      if (queryStr.isEmpty()) ServletOps.errorBadRequest("SPARQL Query: Empty query string");
    }

    if (params != null) {
      Enumeration<String> en = request.getParameterNames();
      for (; en.hasMoreElements(); ) {
        String name = en.nextElement();
        if (!params.contains(name))
          ServletOps.warning(
              action, "SPARQL Query: Unrecognize request parameter (ignored): " + name);
      }
    }
  }
コード例 #2
0
ファイル: SPARQL_Query.java プロジェクト: johnulist/jena
  /**
   * Validate the request, checking HTTP method and HTTP Parameters.
   *
   * @param action HTTP Action
   */
  @Override
  protected void validate(HttpAction action) {
    String method = action.request.getMethod().toUpperCase(Locale.ROOT);

    if (HttpNames.METHOD_OPTIONS.equals(method)) return;

    if (!HttpNames.METHOD_POST.equals(method) && !HttpNames.METHOD_GET.equals(method))
      ServletOps.errorMethodNotAllowed("Not a GET or POST request");

    if (HttpNames.METHOD_GET.equals(method) && action.request.getQueryString() == null) {
      ServletOps.warning(
          action, "Service Description / SPARQL Query / " + action.request.getRequestURI());
      ServletOps.errorNotFound("Service Description: " + action.request.getRequestURI());
    }

    // Use of the dataset describing parameters is check later.
    try {
      validateParams(action, allParams);
      validateRequest(action);
    } catch (ActionErrorException ex) {
      throw ex;
    }
    // Query not yet parsed.
  }