You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ws-thredds-sync-widget/src/main/java/org/gcube/portlets/widgets/wsthreddssync/server/GenericUtils.java

47 lines
1.1 KiB
Java

package org.gcube.portlets.widgets.wsthreddssync.server;
import java.net.MalformedURLException;
import java.net.URL;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class GenericUtils.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Mar 3, 2021
*/
public class GenericUtils {
public static Logger LOG = LoggerFactory.getLogger(GenericUtils.class);
/**
* Gets the gateway client hostname.
*
* @param httpServletRequest the http servlet request
* @return the gateway client hostname
*/
public static String getGatewayClientHostname(HttpServletRequest httpServletRequest) {
try {
String clientURL = httpServletRequest.getRequestURL().toString();
URL gURL = new URL(clientURL);
StringBuilder theURL = new StringBuilder();
// theURL.append(gURL.getProtocol());
// theURL.append("://");
theURL.append(gURL.getHost());
return theURL.toString();
} catch (MalformedURLException e) {
LOG.warn("Failed to determine the gateway from the client url: "+httpServletRequest.getRequestURL());
return null;
}
}
}