当前位置: 首页>>代码示例>>Java>>正文


Java Results类代码示例

本文整理汇总了Java中play.mvc.Results的典型用法代码示例。如果您正苦于以下问题:Java Results类的具体用法?Java Results怎么用?Java Results使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Results类属于play.mvc包,在下文中一共展示了Results类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onClientError

import play.mvc.Results; //导入依赖的package包/类
public CompletionStage<Result> onClientError(RequestHeader request, int statusCode, String message) {
    String errorMessage;
    switch (statusCode) {
        case 400:
            errorMessage = "BadRequest";
            break;
        case 403:
            errorMessage = "Forbidden";
            break;
        case 404:
            errorMessage = "NotFound";
            break;
        default:
            errorMessage = "OtherClientError";
    }
    HashMap<String, Object> errorResult = new HashMap<String, Object>() {
        {
            put("Message", "Client error occurred.");
            put("ExceptionMessage", errorMessage);
        }
    };
    return CompletableFuture.completedFuture(
            Results.status(statusCode, toJson(errorResult))
    );
}
 
开发者ID:Azure,项目名称:pcs-storage-adapter-java,代码行数:26,代码来源:ErrorHandler.java

示例2: createCommonResponse

import play.mvc.Results; //导入依赖的package包/类
/**
 * This method will create common response for all controller method
 * 
 * @param response Object
 * @param key String
 * @param request play.mvc.Http.Request
 * @return Result
 */
public Result createCommonResponse(Object response, String key, play.mvc.Http.Request request) {

  if (response instanceof Response) {
    Response courseResponse = (Response) response;
    if (!ProjectUtil.isStringNullOREmpty(key)) {
      Object value = courseResponse.getResult().get(JsonKey.RESPONSE);
      courseResponse.getResult().remove(JsonKey.RESPONSE);
      courseResponse.getResult().put(key, value);
    }
    return Results.ok(
        Json.toJson(BaseController.createSuccessResponse(request, (Response) courseResponse)));
  } else {
    ProjectCommonException exception = (ProjectCommonException) response;
    return Results.status(exception.getResponseCode(),
        Json.toJson(BaseController.createResponseOnException(request, exception)));
  }
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-service,代码行数:26,代码来源:BaseController.java

示例3: onClientError

import play.mvc.Results; //导入依赖的package包/类
@Override
public CompletionStage<Result> onClientError(Http.RequestHeader request, int statusCode, String message) {
    return CompletableFuture.supplyAsync(() -> {
        Logger.warn("onClientError: URL: {}, status: {}, msg: {}", request.uri(), statusCode, message);
        if (statusCode == play.mvc.Http.Status.BAD_REQUEST) {
            return Results.badRequest(Json.toJson(new ApiError(message)));
        }
        if (statusCode == play.mvc.Http.Status.NOT_FOUND) {
            return Results.notFound(Json.toJson(new ApiError(message)));
        }
        if (statusCode == Http.Status.UNAUTHORIZED || statusCode == Http.Status.FORBIDDEN) {
            return Results.unauthorized(Json.toJson(new ApiError(message)));
        }
        return Results.internalServerError(Json.toJson(new ApiError(message)));
    });
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:17,代码来源:SystemErrorHandler.java

示例4: onServerError

import play.mvc.Results; //导入依赖的package包/类
@Override
public CompletionStage<Result> onServerError(Http.RequestHeader request, Throwable exception) {
    return CompletableFuture.supplyAsync(() -> {
        Throwable cause = exception.getCause();
        String errorMessage = cause == null ? exception.getMessage() : cause.getMessage();
        Logger.error("onServerError: URL: {}, msg: {}", request.uri(), errorMessage);
        exception.printStackTrace();
        if (cause != null) {
            if (cause instanceof MalformedDataException) {
                return Results.badRequest(Json.toJson(errorMessage));
            }
            if (cause instanceof IllegalArgumentException) {
                return Results.badRequest(Json.toJson(new ApiError(errorMessage)));
            }
            if (cause instanceof OptimisticLockException) {
                return Results.badRequest("sitnet_error_data_has_changed");
            }
        }
        return Results.internalServerError(Json.toJson(new ApiError(errorMessage)));
    });
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:22,代码来源:SystemErrorHandler.java

示例5: custom

import play.mvc.Results; //导入依赖的package包/类
private Promise<Result> custom(
        String moduleId,
        String path,
        Function<WSRequest, Promise<WSResponse>> prepareAndFireRequest) {
    long userId = getUserIdForRequest();

    if (!UserModuleActivationPersistency.doesActivationExist(userId,
            moduleId)) {
        return Promise
                .pure(badRequestJson(AssistanceAPIErrors.moduleActivationNotActive));
    }

    ActiveAssistanceModule module = UserModuleActivationPersistency.activatedModuleEndpointsForUser(new String[]{moduleId})[0];

    WSRequest request = WS.url(module.restUrl("/custom/" + path));
    request.setHeader("ASSISTANCE-USER-ID", Long.toString(userId));
    Promise<WSResponse> responsePromise = prepareAndFireRequest.apply(request);

    return responsePromise.map((response) -> (Result) Results.status(response.getStatus(),
            response.getBody()));
}
 
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:22,代码来源:CustomAssistanceProxy.java

示例6: addStructure

import play.mvc.Results; //导入依赖的package包/类
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addStructure() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      Structure structure = Json.fromJson(json, Structure.class);

      try {
        structure = this.postgresStructureDao.create(structure);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(structure);
    },

    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
 
开发者ID:ground-context,项目名称:ground,代码行数:20,代码来源:StructureController.java

示例7: addStructureVersion

import play.mvc.Results; //导入依赖的package包/类
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addStructureVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();

      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
      ((ObjectNode) json).remove("parentIds");

      StructureVersion structureVersion = Json.fromJson(json, StructureVersion.class);

      try {
        structureVersion = this.postgresStructureVersionDao.create(structureVersion, parentIds);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(structureVersion);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
 
开发者ID:ground-context,项目名称:ground,代码行数:23,代码来源:StructureController.java

示例8: getLatest

import play.mvc.Results; //导入依赖的package包/类
public final CompletionStage<Result> getLatest(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "structure_leaves." + sourceKey,
          () -> Json.toJson(this.postgresStructureDao.getLeaves(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
 
开发者ID:ground-context,项目名称:ground,代码行数:17,代码来源:StructureController.java

示例9: getHistory

import play.mvc.Results; //导入依赖的package包/类
public final CompletionStage<Result> getHistory(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "structure_history." + sourceKey,
          () -> Json.toJson(this.postgresStructureDao.getHistory(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
 
开发者ID:ground-context,项目名称:ground,代码行数:17,代码来源:StructureController.java

示例10: getLineageEdge

import play.mvc.Results; //导入依赖的package包/类
public final CompletionStage<Result> getLineageEdge(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_edges." + sourceKey,
          () -> Json.toJson(this.postgresLineageEdgeDao.retrieveFromDatabase(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
 
开发者ID:ground-context,项目名称:ground,代码行数:17,代码来源:LineageEdgeController.java

示例11: getLineageEdgeVersion

import play.mvc.Results; //导入依赖的package包/类
public final CompletionStage<Result> getLineageEdgeVersion(Long id) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_edge_versions." + id,
          () -> Json.toJson(this.postgresLineageEdgeVersionDao.retrieveFromDatabase(id)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
 
开发者ID:ground-context,项目名称:ground,代码行数:17,代码来源:LineageEdgeController.java

示例12: createLineageEdge

import play.mvc.Results; //导入依赖的package包/类
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> createLineageEdge() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      LineageEdge lineageEdge = Json.fromJson(json, LineageEdge.class);
      try {
        lineageEdge = this.postgresLineageEdgeDao.create(lineageEdge);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(lineageEdge);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
 
开发者ID:ground-context,项目名称:ground,代码行数:18,代码来源:LineageEdgeController.java

示例13: createLineageEdgeVersion

import play.mvc.Results; //导入依赖的package包/类
public final CompletionStage<Result> createLineageEdgeVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();

      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
      ((ObjectNode) json).remove("parentIds");

      LineageEdgeVersion lineageEdgeVersion = Json.fromJson(json, LineageEdgeVersion.class);

      try {
        lineageEdgeVersion = this.postgresLineageEdgeVersionDao.create(lineageEdgeVersion, parentIds);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(lineageEdgeVersion);
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
 
开发者ID:ground-context,项目名称:ground,代码行数:22,代码来源:LineageEdgeController.java

示例14: getLatest

import play.mvc.Results; //导入依赖的package包/类
public final CompletionStage<Result> getLatest(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_edge_leaves." + sourceKey,
          () -> Json.toJson(this.postgresLineageEdgeDao.getLeaves(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
 
开发者ID:ground-context,项目名称:ground,代码行数:17,代码来源:LineageEdgeController.java

示例15: getHistory

import play.mvc.Results; //导入依赖的package包/类
public final CompletionStage<Result> getHistory(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_edge_history." + sourceKey,
          () -> Json.toJson(this.postgresLineageEdgeDao.getHistory(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
 
开发者ID:ground-context,项目名称:ground,代码行数:17,代码来源:LineageEdgeController.java


注:本文中的play.mvc.Results类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。