Example usage for javax.servlet.http HttpServletRequest getServerName

List of usage examples for javax.servlet.http HttpServletRequest getServerName

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getServerName.

Prototype

public String getServerName();

Source Link

Document

Returns the host name of the server to which the request was sent.

Usage

From source file:com.ibm.sbt.sample.web.util.SnippetFactory.java

private static String computeSbtxSampleWebUrl(HttpServletRequest request) {
    return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + "/sbtx.sample.web";
}

From source file:com.ibm.sbt.sample.web.util.SnippetFactory.java

private static String computeSbtApiWebUrl(HttpServletRequest request) {
    return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + "/sbt.api.web";
}

From source file:com.netsteadfast.greenstep.util.ApplicationSiteUtils.java

private static boolean checkCrossSite(String host, HttpServletRequest request) {
    boolean corssSite = false;
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
    String basePath80 = request.getScheme() + "://" + request.getServerName();
    basePath = basePath.toLowerCase();//from w  w  w.j  a v  a  2  s .c  o m
    basePath80 = basePath80.toLowerCase();
    if (request.getServerPort() == 80 || request.getServerPort() == 443) {
        if (basePath.indexOf(host) == -1 && basePath80.indexOf(host) == -1) {
            corssSite = true;
        }
    } else {
        if (basePath.indexOf(host) == -1) {
            corssSite = true;
        }
    }
    return corssSite;
}

From source file:com.liferay.portal.util.CookieKeys.java

public static String getDomain(HttpServletRequest request) {

    // See LEP-4602 and   LEP-4618.

    if (Validator.isNotNull(PropsValues.SESSION_COOKIE_DOMAIN)) {
        return PropsValues.SESSION_COOKIE_DOMAIN;
    }/*  ww  w .j  a  v a 2 s . co m*/

    String host = request.getServerName();

    return getDomain(host);
}

From source file:org.slc.sli.dashboard.security.SLIAuthenticationEntryPoint.java

/**
 * @param request//  ww  w.j a va2s  .  co m
 *            - request to be determined
 * @return if the ENV is non-local ( this is due to local jetty server does not
 *         handle secure protocol ) and the protocol is HTTPS, return true.
 *         Otherwise, return false.
 */
static boolean isSecureRequest(HttpServletRequest request) {

    String serverName = request.getServerName();
    boolean isSecureEnvironment = (!serverName.substring(0, serverName.indexOf("."))
            .equals(NONSECURE_ENVIRONMENT_NAME));

    return (request.isSecure() && isSecureEnvironment);
}

From source file:com.flexive.war.filter.FxRequestUtils.java

/**
 * Returns the server name as seen by the client. Takes into account proxies
 * like Apache2 which may alter the server name in their requests.
 *
 * @param request   the request// w w  w . j ava  2s .co  m
 * @return  the server name as seen by the client
 */
public static String getExternalServerName(HttpServletRequest request) {
    if (request.getHeader("x-forwarded-host") != null) {
        // use external (forwarded) host - FX-330
        return request.getHeader("x-forwarded-host");
    } else {
        // use our own server name
        return request.getServerName()
                + (request.getServerPort() == 80 || (request.isSecure() && request.getServerPort() == 443) ? ""
                        : ":" + request.getServerPort());
    }
}

From source file:com.beginner.core.utils.ProjectUtil.java

/**
 * ?// w ww  .j ava  2  s . c  o m
 * @return String http://ip?:??/??/
 */
public static String basePath() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    return basePath;
}

From source file:com.manydesigns.elements.servlet.ServletUtils.java

public static String getApplicationBaseUrl(HttpServletRequest req) {
    String scheme = req.getScheme();
    int port = req.getServerPort();
    String portString;/*from  ww  w.  ja  va  2s .  c o  m*/
    if ((scheme.equals("http") && port == 80) || (scheme.equals("https") && port == 443)) {
        portString = "";
    } else {
        portString = ":" + port;
    }
    return scheme + "://" + req.getServerName() + portString + req.getContextPath();
}

From source file:eionet.util.SecurityUtil.java

/**
 *
 * @return//from  w w w .ja v a 2  s . c o  m
 */
private static String getUrlWithContextPath(HttpServletRequest request) {

    StringBuffer url = new StringBuffer(request.getScheme());
    url.append("://").append(request.getServerName());
    if (request.getServerPort() > 0) {
        url.append(":").append(request.getServerPort());
    }
    url.append(request.getContextPath());
    return url.toString();
}

From source file:com.liusoft.dlog4j.util.RequestUtils.java

/**
 * COOKIE/*from  w ww.  jav a 2  s. com*/
 * 
 * @param name
 * @param value
 * @param maxAge
 */
public static void setCookie(HttpServletRequest request, HttpServletResponse response, String name,
        String value, int maxAge) {
    Cookie cookie = new Cookie(name, value);
    cookie.setMaxAge(maxAge);
    String serverName = request.getServerName();
    String domain = getDomainOfServerName(serverName);
    if (domain != null && domain.indexOf('.') != -1) {
        cookie.setDomain('.' + domain);
    }
    cookie.setPath("/");
    response.addCookie(cookie);
}