Reputation: 71
I am writing a Rest API using Spring boot. I want to calculate time between a request and the previous request, and if the time is less than 2 min I want to return an object json, trace and black list the elements of the request. How can i do this ?
Upvotes: 1
Views: 737
Reputation: 4579
Do something like this:
@RestController
@RequestMapping("/test")
public class TestController {
private static long lastRequest = Long.MAX_VALUE;
@RequestMapping("/post")
public String postTest() {
long currentTime = System.currentTimeMillis();
if (currentTime - lastRequest < 120000){
//DO WHAT YOU WANT
} else {
lastRequest = currentTime;
}
}
Upvotes: 1