本文整理匯總了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());
}