public static String baseUriOf(final HttpServletRequest request){
  final StringBuffer requestUrl=request.getRequestURL();
  return requestUrl != null ? requestUrl.substring(0,requestUrl.indexOf(request.getServletPath())) : "";
}

public static String baseUriOf ( final HttpServletRequest request ) { final StringBuffer requestUrl = request . getRequestURL ( ) ; return requestUrl != null ? requestUrl . substring ( 0 , requestUrl . indexOf ( request . getServletPath ( ) ) ) : "" ; }
returns the baseuri of the request : http : / / www . example . com : 8080 / example
