From 64382a7bb07488d19b30077bf576fbe977100e0c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 23 May 2016 10:45:14 +0200 Subject: [PATCH] Continued a bit: - added support for port number - use context path + servlet path --- .../mxchange/jcoreee/utils/FacesUtils.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/org/mxchange/jcoreee/utils/FacesUtils.java b/src/org/mxchange/jcoreee/utils/FacesUtils.java index cb3aede..a7e20d3 100644 --- a/src/org/mxchange/jcoreee/utils/FacesUtils.java +++ b/src/org/mxchange/jcoreee/utils/FacesUtils.java @@ -38,23 +38,41 @@ public class FacesUtils { // Get request scheme and such ... String scheme = context.getRequestScheme(); - String hostName = context.getRequestServerName(); - String path = context.getRequestServletPath(); + String serverName = context.getRequestServerName(); + String contextPath = context.getRequestContextPath(); + String servletPath = context.getRequestServletPath(); + int port = context.getRequestServerPort(); // Is the path null? if (null == scheme) { // Throw NPE throw new NullPointerException("context.requestScheme is null"); //NOI18N - } else if (null == hostName) { + } else if (null == serverName) { // And throw again ... throw new NullPointerException("context.requestServerName is null"); //NOI18N - } else if (null == path) { + } + + if (null == contextPath) { // Set to empty string - path = ""; //NOI18N + contextPath = ""; //NOI18N } - // Construct full URL - String baseUrl = String.format("%s://%s%s", scheme, hostName, path); //NOI18N + if (null == servletPath) { + // Set to empty string + servletPath = ""; //NOI18N + } + + // Init variable + String baseUrl; + + // Unusual port found? + if ((port != 80) && (port != 443)) { + // Construct full URL + baseUrl = String.format("%s://%s:%d%s%s", scheme, serverName, port, contextPath, servletPath); //NOI18N + } else { + // Construct full URL + baseUrl = String.format("%s://%s%s%s", scheme, serverName, contextPath, servletPath); //NOI18N + } // Return it return baseUrl; -- 2.39.5