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

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

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

Request.requestMethod介绍

[英]Returns request method e.g. GET, POST, PUT, ...
[中]返回请求方法,例如GET、POST、PUT。。。

代码示例

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

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

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

public static Filter onlyOn(Filter filter, String... allowedMethods) {
  return (request, response) -> {
    if (Sets.newHashSet(allowedMethods).contains(request.requestMethod())) {
      filter.handle(request, response);
    }
  };
}

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

private void checkAdminUserAnd403OnlyForPatch(Request request, Response response) {
  if ("PATCH".equals(request.requestMethod())) {
    apiAuthenticationHelper.checkAdminUserAnd403(request, response);
  }
}

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

private void checkSecurityOr403(Request request, Response response) {
  if (Arrays.asList("GET", "HEAD").contains(request.requestMethod().toUpperCase())) {
    apiAuthenticationHelper.checkUserAnd403(request, response);
    return;
  }
  apiAuthenticationHelper.checkAdminUserAnd403(request, response);
}

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

protected void verifyContentType(Request request, Response response) throws IOException {
  if (!UPDATE_HTTP_METHODS.contains(request.requestMethod().toUpperCase())) {
    return;
  }
  boolean requestHasBody = request.contentLength() >= 1 || request.raw().getInputStream().available() >= 1 || "chunked".equalsIgnoreCase(request.headers("Transfer-Encoding"));
  if (requestHasBody) {
    if (!isJsonContentType(request)) {
      throw haltBecauseJsonContentTypeExpected();
    }
  } else if (request.headers().stream().noneMatch(headerName -> headerName.toLowerCase().equals("x-gocd-confirm"))) {
    throw haltBecauseConfirmHeaderMissing();
  }
}

代码示例来源: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

response.header("Content-Type", image.getContentType());
this.setEtagHeader(response, image.getHash());
if (request.requestMethod().equals("head")) {
  return new byte[0];
} else {

代码示例来源:origin: cinchapi/concourse

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

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

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

代码示例来源:origin: bwssytems/ha-bridge

log.debug("HueMulator " + request.requestMethod() + " called on api/* with request <<<" + request.pathInfo() + ">>>, and body <<<" + request.body() + ">>>");
if(bridgeSettingMaster.getBridgeSecurity().isSecure()) {
  String pathInfo = request.pathInfo();

代码示例来源:origin: apache/james-project

@Override
public void handle(Request request, Response response) throws Exception {
  if (request.requestMethod() != OPTIONS) {
    Optional<String> bearer = Optional.ofNullable(request.headers(AUTHORIZATION_HEADER_NAME))
      .filter(value -> value.startsWith(AUTHORIZATION_HEADER_PREFIX))
      .map(value -> value.substring(AUTHORIZATION_HEADER_PREFIX.length()));
    checkHeaderPresent(bearer);
    checkValidSignature(bearer);
    checkIsAdmin(bearer);
    String login = jwtTokenVerifier.extractLogin(bearer.get());
    request.attribute(LOGIN, login);
  }
}

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

@Override
  public void handle(Request request, Response response) throws Exception {
    Metrics.log.debug(request.requestMethod() + " " + request.pathInfo());

    response.header("Access-Control-Allow-Origin", "*");
    response.type("application/json");
  }
}

代码示例来源:origin: xjdr/xio

private static Object setupSparkResponse(String name, Request req, Response res) {
 res.type("application/json");
 Optional<String> echoValue = Optional.ofNullable(req.headers("x-echo"));
 Optional<String> optionalMethod = Optional.ofNullable(req.requestMethod());
 String methodValue = "";
 if (optionalMethod.isPresent()) {
  methodValue = optionalMethod.get();
 }
 Optional<String> tagValue = Optional.ofNullable(name);
 res.header("x-echo", echoValue.orElse("none"));
 res.header("x-method", methodValue);
 res.header("x-tag", tagValue.orElse("no tag"));
 Kraken kraken = new Kraken("Release", "the Kraken");
 return new Gson().toJson(kraken);
}

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

@Override
  public void handle(Exception exception, Request request, Response response) {
    Metrics.log.error(request.requestMethod() + " " + request.pathInfo(), exception);

    response.body(ExceptionUtils.getStackTrace(exception));
    response.type("text/plain");
    response.status(500);
  }
}

代码示例来源:origin: yeriomin/token-dispenser

notFound("Not found");
before((req, res) -> {
  LOG.info(req.requestMethod() + " " + req.url());
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Request-Method", "GET");

代码示例来源:origin: lamarios/Homedash2

res.header("Pragma", "no-cache"); // HTTP 1.0.
res.header("Expires", "0"); // Proxies.
logger.info("{} -> {}", req.requestMethod(), req.url());

代码示例来源:origin: mgtechsoftware/smockin

LiveLoggingUtils.MOCK_TRAFFIC_LOGGER.info(LiveLoggingUtils.buildLiveLogInboundFileEntry(request.attribute(GeneralUtils.LOG_REQ_ID), request.requestMethod(), request.pathInfo(), reqHeaders, request.body(), false));
  liveLoggingHandler.broadcast(LiveLoggingUtils.buildLiveLogInboundDTO(request.attribute(GeneralUtils.LOG_REQ_ID), request.requestMethod(), request.pathInfo(), reqHeaders, request.body(), false));
});

代码示例来源:origin: apache/james-project

@Override
  public void handle(Request request, Response response) throws Exception {
    Closeable mdcCloseable = MDCBuilder.create()
      .addContext(MDCBuilder.IP, request.ip())
      .addContext(MDCBuilder.HOST, request.host())
      .addContext(VERB, request.requestMethod())
      .addContext(MDCBuilder.PROTOCOL, "webadmin")
      .addContext(MDCBuilder.ACTION, request.pathInfo())
      .addContext(MDCBuilder.USER, request.attribute(AuthenticationFilter.LOGIN))
      .build();
    request.attribute(MDC_CLOSEABLE, mdcCloseable);
  }
}

代码示例来源:origin: apache/james-project

private void configureExceptionHanding() {
  service.notFound((req, res) -> ErrorResponder.builder()
    .statusCode(NOT_FOUND_404)
    .type(NOT_FOUND)
    .message(String.format("%s %s can not be found", req.requestMethod(), req.pathInfo()))
    .asString());
  service.internalServerError((req, res) -> ErrorResponder.builder()
    .statusCode(INTERNAL_SERVER_ERROR_500)
    .type(SERVER_ERROR)
    .message("WebAdmin encountered an unexpected internal error")
    .asString());
  service.exception(JsonExtractException.class, (ex, req, res) -> {
    res.status(BAD_REQUEST_400);
    res.body(ErrorResponder.builder()
      .statusCode(BAD_REQUEST_400)
      .type(INVALID_ARGUMENT)
      .message("JSON payload of the request is not valid")
      .cause(ex)
      .asString());
  });
}

代码示例来源:origin: langurmonkey/gaiasky

logger.debug("======== Handling API call via HTTP {}: ========", request.requestMethod());
logger.debug("* Parameter extracted:");
logger.debug("  command = ", request.params(":cmd"));

相关文章