I have a simple Spring MVC application that will redirect the user to a new page after certain controller actions. For example:
@Controller
public class ResponseController {
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String saveObj(HttpServletRequest request, @ModelAttribute(“someObject”) Object obj) {
// logic to validate and save object
return "redirect:/obj/" + id;
}
}
This Spring MVC application is running behind a loadbalancer with several other instances. Each have their own hostname. The loadbalancer is configured with SSL and the instances are not.
What I would like to know is the best practice to override the default redirect behavior. Currently, the application starts with https://mysite.com, but after a user performs an action that requires a redirect, the application redirects the user to http://some.hostnameX.com.
Currently, I have a property that is used to help redirect the user to mysite.com.
loadbalancer.url=https://mysite.com
Then, in the controller, I have the following:
@Value("loadbalancer.url")
String loadbalanerUrl;
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String saveObj(HttpServletRequest request, @ModelAttribute(“someObject”) Object obj){
// logic to validate and save object
return "redirect:" + loadbalancerUrl + "/obj/" + id;
}
Is there a better way to override this behavior?