本文整理汇总了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;
}
示例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;
}
示例3: processRateLimitException
@ExceptionHandler(RateLimitException.class)
@ResponseBody
@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
public ErrorVM processRateLimitException(RateLimitException exception) {
return new ErrorVM("error.rateLimit", exception.getMessage());
}
示例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());
}