Example #1
0
  @Override
  protected void validate(HttpAction action) {
    HttpServletRequest request = action.request;

    if (HttpNames.METHOD_OPTIONS.equals(request.getMethod())) return;

    if (!HttpNames.METHOD_POST.equalsIgnoreCase(request.getMethod()))
      ServletOps.errorMethodNotAllowed("SPARQL Update : use POST");

    ContentType ct = FusekiLib.getContentType(action);
    if (ct == null) ct = ctSPARQLUpdate;

    if (matchContentType(ctSPARQLUpdate, ct)) {
      String charset = request.getCharacterEncoding();
      if (charset != null && !charset.equalsIgnoreCase(charsetUTF8))
        ServletOps.errorBadRequest("Bad charset: " + charset);
      validate(action, paramsPOST);
      return;
    }

    if (isHtmlForm(ct)) {
      int x =
          countParamOccurences(request, paramUpdate) + countParamOccurences(request, paramRequest);
      if (x == 0) ServletOps.errorBadRequest("SPARQL Update: No 'update=' parameter");
      if (x != 1) ServletOps.errorBadRequest("SPARQL Update: Multiple 'update=' parameters");

      String requestStr = request.getParameter(paramUpdate);
      if (requestStr == null) requestStr = request.getParameter(paramRequest);
      if (requestStr == null) ServletOps.errorBadRequest("SPARQL Update: No update= in HTML form");
      validate(action, paramsForm);
      return;
    }

    ServletOps.error(
        HttpSC.UNSUPPORTED_MEDIA_TYPE_415,
        "Must be "
            + contentTypeSPARQLUpdate
            + " or "
            + contentTypeHTMLForm
            + " (got "
            + ct.getContentType()
            + ")");
  }
Example #2
0
  /**
   * 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.
  }