WebUtils { public static String extractBaseURLFromRequest(final HttpServletRequest request) { final StringBuilder sb = new StringBuilder(); sb.append(request.getScheme()); sb.append(": sb.append(request.getServerName()); if (request.getServerPort() != 80) { sb.append(":"); sb.append(request.getServerPort()); } sb.append(request.getContextPath()); sb.append("/"); return sb.toString(); } private  WebUtils(); static String nl2br(final String string); static String replaceLeadingSpaces(final String string); static String extractBaseURLFromRequest(final HttpServletRequest request); static final String APPLICATION_OCTET_STREAM; static final String CONTENT_TYPE_TEXT_PLAIN; static final String CONTENT_DISPOSITION_HEADER; static final String NL; static final String NBSP; static final Pattern NL_REGEXP; }
@Test public void testExtractBaseURLFromRequest() throws Exception { MockHttpServletRequest request; request = new MockHttpServletRequest("GET", "foo/bar"); request.setServerName("www.test.com"); request.setServerPort(80); assertEquals("http: request = new MockHttpServletRequest("GET", "foo/bar"); request.setServerName("www.test.com"); request.setServerPort(123); assertEquals("http: }