spark.Request.body()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(250)

本文整理了Java中spark.Request.body方法的一些代码示例,展示了Request.body的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.body方法的具体详情如下:
包路径:spark.Request
类名称:Request
方法名:body

Request.body介绍

[英]Returns the request body sent by the client
[中]返回客户端发送的请求正文

代码示例

代码示例来源:origin: perwendel/spark

@Override
public String body() {
  return delegate.body();
}

代码示例来源:origin: gocd/gocd

private PipelineScheduleOptions getScheduleOptions(Request req) {
    if (StringUtils.isBlank(req.body())) {
      return new PipelineScheduleOptions();
    }
    GsonTransformer gsonTransformer = GsonTransformer.getInstance();
    JsonReader jsonReader = gsonTransformer.jsonReaderFrom(req.body());
    return PipelineScheduleOptionsRepresenter.fromJSON(jsonReader);
  }
}

代码示例来源:origin: gocd/gocd

protected Map<String, Object> readRequestBodyAsJSON(Request req) {
  Map<String, Object> map = GsonTransformer.getInstance().fromJson(req.body(), new TypeToken<Map<String, Object>>() {
  }.getType());
  if (map == null) {
    return Collections.emptyMap();
  }
  return map;
}

代码示例来源:origin: gocd/gocd

@Override
public Role buildEntityFromRequestBody(Request req) {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  return RoleRepresenter.fromJSON(jsonReader);
}

代码示例来源:origin: gocd/gocd

@Override
public Role buildEntityFromRequestBody(Request req) {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  return RoleRepresenter.fromJSON(jsonReader);
}

代码示例来源:origin: gocd/gocd

@Override
public AdminsConfig buildEntityFromRequestBody(Request req) {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  return AdminsConfigRepresenter.fromJSON(jsonReader);
}

代码示例来源:origin: gocd/gocd

@Override
public EnvironmentConfig buildEntityFromRequestBody(Request req) {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  return EnvironmentRepresenter.fromJSON(jsonReader);
}

代码示例来源:origin: gocd/gocd

@Override
public ArtifactStore buildEntityFromRequestBody(Request req) {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  return ArtifactStoreRepresenter.fromJSON(jsonReader);
}

代码示例来源:origin: gocd/gocd

@Override
public ConfigRepoConfig buildEntityFromRequestBody(Request req) {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  return ConfigRepoConfigRepresenterV1.fromJSON(jsonReader);
}

代码示例来源:origin: gocd/gocd

@Override
public AdminsConfig buildEntityFromRequestBody(Request req) {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  return AdminsConfigRepresenter.fromJSON(jsonReader);
}

代码示例来源:origin: gocd/gocd

@Override
public PipelineConfigs buildEntityFromRequestBody(Request req) {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  return PipelineGroupRepresenter.fromJSON(jsonReader);
}

代码示例来源:origin: gocd/gocd

private String getOrHaltForGroupName(Request req) {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  if (!jsonReader.hasJsonObject("group") || StringUtils.isBlank(jsonReader.getString("group"))) {
    throw haltBecauseOfReason("Pipeline group must be specified for creating a pipeline.");
  }
  return jsonReader.getString("group");
}

代码示例来源:origin: gocd/gocd

public String bulkDeleteAgents(Request request, Response response) throws IOException {
  final JsonReader reader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
  final List<String> uuids = toList(reader.optJsonArray("uuids").orElse(new JsonArray()));
  final HttpOperationResult result = new HttpOperationResult();
  agentService.deleteAgents(currentUsername(), result, uuids);
  return renderHTTPOperationResult(result, request, response);
}

代码示例来源:origin: gocd/gocd

@Override
public DataSharingSettings buildEntityFromRequestBody(Request request) {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
  return DataSharingSettingsRepresenter.fromJSON(jsonReader, currentUsername(), timeProvider, dataSharingSettingsService.get());
}

代码示例来源:origin: gocd/gocd

public String pause(Request req, Response res) throws IOException {
  HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
  JsonReader requestBody = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  String pipelineName = req.params("pipeline_name");
  String pauseCause = requestBody.optString("pause_cause").orElse(null);
  pipelinePauseService.pause(pipelineName, pauseCause, currentUsername(), result);
  return renderHTTPOperationResult(result, req, res);
}

代码示例来源:origin: gocd/gocd

@Override
public PipelineConfig buildEntityFromRequestBody(Request req) {
  ConfigHelperOptions options = new ConfigHelperOptions(goConfigService.getCurrentConfig(), passwordDeserializer);
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  if ("PUT".equalsIgnoreCase(req.requestMethod())) {
    return PipelineConfigRepresenter.fromJSON(jsonReader, options);
  }
  return PipelineConfigRepresenter.fromJSON(jsonReader.readJsonObject("pipeline"), options);
}

代码示例来源:origin: gocd/gocd

public String bulkDelete(Request req, Response res) throws Exception {
  BulkUpdateUsersOperationResult result = new BulkUpdateUsersOperationResult();
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  List<String> users = jsonReader.readStringArrayIfPresent("users").orElse(Collections.emptyList());
  userService.deleteUsers(users, result);
  if (!result.isSuccessful()) {
    res.status(result.httpCode());
    return writerForTopLevelObject(req, res, outputWriter -> BulkDeletionFailureResultRepresenter.toJSON(outputWriter, result));
  }
  return renderHTTPOperationResult(result, req, res);
}

代码示例来源:origin: gocd/gocd

public String encrypt(Request request, Response response) throws CryptoException, IOException {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
  String value = jsonReader.getString("value");
  String encrypt = cipher.encrypt(value);
  return writerForTopLevelObject(request, response, writer -> EncryptedValueRepresenter.toJSON(writer, encrypt));
}

代码示例来源:origin: gocd/gocd

public String bulkUpdateUsersState(Request req, Response res) throws Exception {
  BulkUpdateUsersOperationResult result = new BulkUpdateUsersOperationResult();
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  List<String> users = jsonReader.readStringArrayIfPresent("users").orElse(Collections.emptyList());
  boolean shouldEnable = jsonReader.readJsonObject("operations").getBoolean("enable");
  userService.bulkEnableDisableUsers(users, shouldEnable, result);
  if (!result.isSuccessful()) {
    res.status(result.httpCode());
    return writerForTopLevelObject(req, res, outputWriter -> BulkDeletionFailureResultRepresenter.toJSON(outputWriter, result));
  }
  return renderHTTPOperationResult(result, req, res);
}

代码示例来源:origin: gocd/gocd

public String bulkUpdate(Request req, Response res) throws IOException {
  JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body());
  GoCDRolesBulkUpdateRequest bulkUpdateRequest = GoCDRolesBulkUpdateRequestRepresenter.fromJSON(jsonReader);
  HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
  roleConfigService.bulkUpdate(bulkUpdateRequest, SessionUtils.currentUsername(), result);
  if (result.isSuccessful()) {
    RolesConfig goCDRoles = roleConfigService.getRoles().ofType("gocd");
    return writerForTopLevelObject(req, res, writer -> RolesRepresenter.toJSON(writer, goCDRoles));
  } else {
    return renderHTTPOperationResult(result, req, res);
  }
}

相关文章