]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreee/utils/FacesUtils.java
Continued a bit:
[jcore-utils.git] / src / org / mxchange / jcoreee / utils / FacesUtils.java
index cb3aede8f505423c353a87439731cdc83bca840d..f0db70434b137f475691902027ddce088443ffa2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Cho-Time GmbH
+ * Copyright (C) 2016, 2017 Roland Häder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@ import javax.faces.context.FacesContext;
 /**
  * An utilities class for JSF
  * <p>
- * @author Roland Haeder<rhaeder@cho-time.de>
+ * @author Roland Häder<roland@mxchange.org>
  */
 public class FacesUtils {
 
@@ -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;