added getPortalURL method

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/portal-manager@126148 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-03-23 17:33:58 +00:00
parent 219a71698f
commit 92dcadac5c
2 changed files with 27 additions and 0 deletions

View File

@ -30,6 +30,12 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>

View File

@ -7,6 +7,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -92,6 +94,24 @@ public class PortalContext {
public static String getPortalInstanceName() {
return getConfiguration().getGatewayName();
}
/**
*
* @param httpServletRequest
* @return the gateway URL until the first slash, e.g. http(s)://mynode.d4science.org:8080, if the URL uses standard http(s) port like 80 or 443 the port is not returned.
*/
public String getGatewayURL(HttpServletRequest httpServletRequest) {
String serverName = httpServletRequest.getServerName();
String toReturn = (httpServletRequest.isSecure()) ? "https://" : "http://" ;
//server name
toReturn += serverName;
//port
if (httpServletRequest.isSecure())
toReturn += (httpServletRequest.getServerPort() == 443) ? "" : ":"+httpServletRequest.getServerPort() ;
else
toReturn += (httpServletRequest.getServerPort() == 80) ? "" : ":"+httpServletRequest.getServerPort() ;
return toReturn;
}
/**
* read the infrastructure gateway name from a property file and returns it
*/
@ -172,4 +192,5 @@ public class PortalContext {
private static String getCatalinaHome() {
return (System.getenv("CATALINA_HOME").endsWith("/") ? System.getenv("CATALINA_HOME") : System.getenv("CATALINA_HOME")+"/");
}
}