In Spring web service, I have controller having multiple URL mapped method to handle requests. I want to map 2 urls to a single @GetMapping method like below:
@GetMapping(value = {"ex/{status}", "ex/retries/{status}"}, produces = "application/json")
public ResponseEntity<ResponsePOJO> getExRetries(@RequestParam("interval") Optional<String> intervalOptional, @PathVariable("status") String successStatus)
{
/**
*LOTS OF WORK
*/
//If this method was called via ex/{status} then call using true
getReport(true);
//BUT if it was called via ex/retries/{status} then call using false i.e getReport(true);
}
Now based on through which of the 2 urls this method was invoked, only change would be that in the last line method call will be with true otherwise false. Now if I implement 2 methods for those 2 urls mapping and just change last line method call that would result in code duplication.
Is there a way to find which url was used to invoke it, then I can use if condition to make correct call and avoid 2 methods for it and hence code duplication.