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


Java HttpStatus.TOO_MANY_REQUESTS属性代码示例

本文整理汇总了Java中org.springframework.http.HttpStatus.TOO_MANY_REQUESTS属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus.TOO_MANY_REQUESTS属性的具体用法?Java HttpStatus.TOO_MANY_REQUESTS怎么用?Java HttpStatus.TOO_MANY_REQUESTS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.springframework.http.HttpStatus的用法示例。


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

示例1: run

@Override
public Object run() {

    try {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletResponse response = ctx.getResponse();

        if (!rateLimiter.tryAcquire()) {
            HttpStatus httpStatus = HttpStatus.TOO_MANY_REQUESTS;

            response.setContentType(MediaType.TEXT_PLAIN_VALUE);
            response.setStatus(httpStatus.value());
            ctx.setResponseStatusCode(httpStatus.value());
            ctx.setSendZuulResponse(false);
        }
    } catch (Exception e) {
        ReflectionUtils.rethrowRuntimeException(e);
    }
    return null;
}
 
开发者ID:kenly333,项目名称:service-hive,代码行数:20,代码来源:RateLimitZuulFilter.java

示例2: create

/**
 * Handle a POST method by creating a new Milkshake.
 *  Queries appropriate fruit service to check for inventory and consume the fruit into the milkshake
 *
 * @param flavor to create
 * @return a newly created Milkshake
 */
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody Milkshake create(@RequestParam Flavor flavor) {

  try {
    FlavorProvider provider = getFlavorProvider(flavor);
    provider.getIngredients();
  } catch (IngredientException e) {
    throw new HttpClientErrorException(HttpStatus.TOO_MANY_REQUESTS, e.getMessage());
  }

  Milkshake milkshake = new Milkshake();
  milkshake.setId(counter.incrementAndGet());
  milkshake.setFlavor(flavor);
  return milkshake;
}
 
开发者ID:stelligent,项目名称:mu-workshop-lab3,代码行数:22,代码来源:MilkshakeController.java

示例3: processRateLimitException

@ExceptionHandler(RateLimitException.class)
@ResponseBody
@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
public ErrorVM processRateLimitException(RateLimitException exception) {
    return new ErrorVM("error.rateLimit", exception.getMessage());
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:6,代码来源:ExceptionTranslator.java

示例4: handleException

@ResponseBody
@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
@ExceptionHandler({TooManyRequestsException.class})
public Map<String, String> handleException(TooManyRequestsException e) {
  return ImmutableMap.of("code", "1911002", "message", e.getMessage());
}
 
开发者ID:chuangxian,项目名称:lib-edge,代码行数:6,代码来源:GlobalExceptionHandler.java


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