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

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

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

Request.bodyAsBytes介绍

暂无

代码示例

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

@Override
public byte[] bodyAsBytes() {
  return delegate.bodyAsBytes();
}

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

/**
 * @return the request body sent by the client
 */
public String body() {
  if (body == null) {
    body = StringUtils.toString(bodyAsBytes(), servletRequest.getCharacterEncoding());
  }
  return body;
}

代码示例来源:origin: com.sparkjava/spark-core

@Override
public byte[] bodyAsBytes() {
  return delegate.bodyAsBytes();
}

代码示例来源:origin: com.conveyal/r5

/**
 * Deserializes an object of the given type from the body of the supplied Spark request.
 */
public static <T> T objectFromRequestBody(spark.Request request, Class<T> classe) {
  try {
    return lenientObjectMapper.readValue(request.bodyAsBytes(), classe);
  } catch (Exception e) {
    e.printStackTrace();
    return null;
  }
}

代码示例来源:origin: conveyal/r5

/**
 * Deserializes an object of the given type from the body of the supplied Spark request.
 */
public static <T> T objectFromRequestBody(spark.Request request, Class<T> classe) {
  try {
    return lenientObjectMapper.readValue(request.bodyAsBytes(), classe);
  } catch (Exception e) {
    e.printStackTrace();
    return null;
  }
}

代码示例来源:origin: com.sparkjava/spark-core

/**
 * @return the request body sent by the client
 */
public String body() {
  if (body == null) {
    body = StringUtils.toString(bodyAsBytes(), servletRequest.getCharacterEncoding());
  }
  return body;
}

代码示例来源:origin: beryx/text-io

@Override
  public void init() {
    post("/" + getPathForPostInit(), (request, response) -> {
      logger.trace("Received INIT");
      String initData = new String(request.bodyAsBytes(), StandardCharsets.UTF_8);
      return configureResponseData(response, handleInit(request, initData));
    });

    get("/" + getPathForGetData(), "application/json", (request, response) -> {
      logger.trace("Received GET");
      return configureResponseData(response, handleGetData(request));
    });

    post("/" + getPathForPostInput(), (request, response) -> {
      logger.trace("Received POST");
      boolean userInterrupt = Boolean.parseBoolean(request.headers("textio-user-interrupt"));
      String handlerId = request.headers("textio-handler-id");
      String input = new String(request.body().getBytes(), StandardCharsets.UTF_8);
      return configureResponseData(response, handlePostInput(request, input, userInterrupt, handlerId));
    });
  }
}

相关文章