0

I have a spring MVC application which is hosted on a server S. All the calls from a client C goes to S via loadbalancer L. The url that load balancer uses internally for server S is internalurl.com and the url that client uses is xyz.com.

The issue, is when I hit a url say xyz.com/admin/ on my mozilla browser, I expect it to get redirected to xyz.com/admin/home.html. But instead, it is redirecting to internalurl.com/admin/home.html and since internalurl.com is internal to load-balancer, I get "Network Access Message: The website cannot be found" on my browser with "internalurl.com/admin/home.html" in my browser addressbar

For redirection, I am using :

  public void doFilter(ServletRequest req, ServletResponse res,
                     FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    String strReferer = request.getHeader("Referer");

    String strConetextPath = request.getContextPath();

    if (strReferer != null && !strReferer.contains(strConetextPath)) {
        response.sendRedirect("/requestError.html");
    } 
    // redirect to home.html in case user tries to access /admin/
    // in case user is not already logged-in, user will be redirected to login.html
    else if (request.getRequestURI().equalsIgnoreCase("/admin/")) {
        response.sendRedirect("home.html");
    }else
        chain.doFilter(req, res);
}

Thanks in advance.

Sukhvir Singh
  • 168
  • 3
  • 12

1 Answers1

0

Its not an issue with SPring MVC at all. It shall be handled at the Proxy / Load balancer.

For any redirects happening at the Internal server level will have the internal server URL, which will not be known to the Client / Browser. As Client is aware of only the Web server (as u mentioned XYZ.com).

It’s a typical issue which is handled by the proxy or the load balancer using reverse proxy concept.

For e.g.: In case of Apache HTTP, we use ProxyPassReverse configuration, which would transform the all internal server url headers to point to XYZ.com before responding to the browser. This will ensure that browser calls only xyz.com

Hope it helps.

Thanks, JP

  • Hi JP, after your comment I checked reverse-proxy concepts and to me also it seems that it may be due to loadbalancer config. This comment proved informative. http://stackoverflow.com/a/8141490/2701227 – Sukhvir Singh Jul 10 '14 at 04:19