Added port to getBaseUrl

This commit is contained in:
Giuseppe Digilio
2020-03-13 19:30:45 +01:00
parent 3989987a41
commit d665125788
2 changed files with 9 additions and 0 deletions

View File

@@ -425,6 +425,9 @@ public final class Utils {
try {
URL url = new URL(urlString);
String baseUrl = url.getProtocol() + "://" + url.getHost();
if (url.getPort() != -1) {
baseUrl += (":" + url.getPort());
}
return baseUrl;
} catch (MalformedURLException e) {
return null;

View File

@@ -39,6 +39,12 @@ public class UtilsTest extends AbstractUnitTest {
assertEquals("Test keep url", "https://demo.dspace.org",
Utils.getBaseUrl("https://demo.dspace.org"));
assertEquals("Test keep url", "http://localhost:8080",
Utils.getBaseUrl("http://localhost:8080"));
assertEquals("Test keep url", "http://localhost:8080",
Utils.getBaseUrl("http://localhost:8080/server"));
// This uses a bunch of reserved URI characters
assertNull("Test invalid URI returns null", Utils.getBaseUrl("&+,?/@="));
}