Exemplo n.º 1
0
  private void execGet(HttpAction action, String name) {
    if (name == null) log.info(format("[%d] Tasks", action.id));
    else log.info(format("[%d] Task %s", action.id, name));

    JsonValue responseBody = null;

    if (name == null) {
      JsonBuilder builder = new JsonBuilder();
      builder.startArray();

      for (AsyncPool pool : pools) {
        for (AsyncTask aTask : pool.tasks()) {
          // builder.value(aTask.getTaskId()) ;
          descOneTask(builder, aTask);
        }
      }
      builder.finishArray();
      responseBody = builder.build();
    } else {
      for (AsyncPool pool : pools) {
        // Assumes first is only.
        AsyncTask aTask = pool.getTask(name);
        if (aTask != null) {
          JsonBuilder builder = new JsonBuilder();
          descOneTask(builder, aTask);
          responseBody = builder.build();
        }
      }
    }

    if (responseBody == null) ServletOps.errorNotFound("Task '" + name + "' not found");
    ServletOps.setNoCache(action);
    ServletOps.sendJsonReponse(action, responseBody);
  }
Exemplo n.º 2
0
 protected void doCommon(HttpServletRequest request, HttpServletResponse response) {
   try {
     ServletOps.setNoCache(response);
     response.setContentType(contentTypeTextPlain);
     response.setCharacterEncoding(charsetUTF8);
     response.setStatus(HttpSC.OK_200);
     ServletOutputStream out = response.getOutputStream();
     out.println(DateTimeUtils.nowAsXSDDateTimeString());
   } catch (IOException ex) {
     Fuseki.serverLog.warn("ping :: IOException :: " + ex.getMessage());
   }
 }
Exemplo n.º 3
0
  @Override
  protected void execCommonWorker(HttpAction action) {
    String name = extractItemName(action);
    if (name != null) {
      if (name.startsWith(prefix)) name = name.substring(prefix.length());
      else log.warn("Unexpected task name : " + name);
    }

    String method = action.request.getMethod();
    if (method.equals(METHOD_GET)) execGet(action, name);
    else if (method.equals(METHOD_POST)) execPost(action, name);
    else ServletOps.error(HttpSC.METHOD_NOT_ALLOWED_405);
  }
Exemplo n.º 4
0
  @Override
  protected JsonObject execute(ValidationAction action) {
    JsonBuilder obj = new JsonBuilder();
    obj.startObject();

    String args[] = getArgs(action, paramIRI);
    if (args.length == 0) ServletOps.errorBadRequest("No IRIs supplied");

    obj.key(jIRIs);
    obj.startArray();

    for (String iriStr : args) {
      obj.startObject();
      obj.key(jIRI).value(iriStr);

      IRI iri = iriFactory.create(iriStr);

      List<String> errors = new ArrayList<>();
      List<String> warnings = new ArrayList<>();

      if (iri.isRelative()) warnings.add("Relative IRI: " + iriStr);

      Iterator<Violation> vIter = iri.violations(true);
      for (; vIter.hasNext(); ) {
        Violation v = vIter.next();
        String str = v.getShortMessage();
        if (v.isError()) errors.add(str);
        else warnings.add(str);
      }

      obj.key(jErrors);
      obj.startArray();
      for (String msg : errors) obj.value(msg);
      obj.finishArray();

      obj.key(jWarnings);
      obj.startArray();
      for (String msg : warnings) obj.value(msg);
      obj.finishArray();

      obj.finishObject();
    }

    obj.finishArray();

    obj.finishObject();
    return obj.build().getAsObject();
  }