當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。