I have spring MVC controller having several APIs, I want to get the URI of API that has been hit from the front end
I have a filter extending oncePerRequestFilter which intercepts every api call, the filter has method which accepts HttpServletRequest,HttpServletResponse and filterChain.
I can get the uri using request.getRequestURI()
but in case of uri having template path variables lets say uri ="q/v1/ruleset/{rulesetId}"
i am getting the final uri, for example API has been hit for rulesetid=23
, the uri i am getting from request.getRequestURI()
is
"q/v1/ruleset/23"
but what i want is uri ="q/v1/ruleset/{rulesetId}"
,
is there any method to get the expected result, I know , i can always get the desired result by some manipulation, but i want to make the things generic, please help
I have controller containing API
@RequestMapping(value = "/ruleset/{rulesetid}", method =
RequestMethod.GET)
public RuleSet getRuleSet(@PathVariable(value = "rulesetid")
final Long ruleSetId) {
return storeMixin.getRuleSet(ruleSetId);
}
Filter
@Component
@Order(1)
public class CatalogFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,FilterChain filterChain) throws
IOException, ServletException {
long startTime = System.currentTimeMillis();
filterChain.doFilter(request, response);
long elapsed = System.currentTimeMillis() - startTime;
String name = request.getRequestURI();
String requestType = request.getMethod();
Integer httpCode = response.getStatus();
}
}