I am trying to forward the request to another url in spring boot.
I know how to forward the request from one endpoint to another endpoint in the same spring boot application. The code for this is like -
@GetMapping("/home")
public ModelAndView home(@PathVariable(name = "env", required = false) String env) {
return new ModelAndView("index");
}
@GetMapping("/forward")
String callForward(){
return "forward:/home";
}
Here If I go to http://localhost:8080/forward then it will be server by "/home" endpoint and we'll get the home page rendered. Interesting thing here is "url" in the browser remains same http://localhost:8080/forward.
My requirement is > I want to forward to the request to any third party url for example when http://localhost:8080/forward is called I want it to be served by https://google.com/forward.
How can I do it.
I am open to any solution which can fulfill the requirement.