I have a simple rest controller which captures errors. I want to get the actual URL that the browser sent to server, but the servlet is giving me a different URL.
If I navigate to 127.0.0.1/abc
a 404 error is triggered, and it's routed to /error
handler as defined. However, the output gives me the result 127.0.0.1/error
instead of 127.0.0.1/abc
. How can I obtain the original URL?
@RestController
public class IndexController implements ErrorController {
@RequestMapping("/")
public String index() {
return "OK";
}
@RequestMapping("/error")
public String error(HttpServletRequest request) {
System.out.println("ERR: " + request.getRequestURL() + " : " + request.getRequestURI());
return "ERR";
}
@Override
public String getErrorPath() {
return "/error";
}
}