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.tc.utils.XSPUtils.java

public static String buildHostAndWebPath(FacesContext context, Database db) throws NotesException {
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    final StringBuilder url = new StringBuilder(48);
    String webPath = db.getFilePath().replace("\\", "/");

    String scheme = request.getScheme();

    url.append(scheme);/* w  w w. j  a va2  s.  co  m*/
    url.append("://");
    url.append(request.getServerName());

    int port = request.getServerPort();
    if (port > 0 && (("http".equalsIgnoreCase(scheme) && port != 80)
            || ("https".equalsIgnoreCase(scheme) && port != 443))) {
        url.append(':');
        url.append(port);
    }

    url.append('/');
    url.append(webPath);
    return url.toString();
}

From source file:com.tc.utils.XSPUtils.java

public static String buildXpageUrl(HttpServletRequest request, String xpage, Document doc)
        throws NotesException {
    final StringBuilder url = new StringBuilder(48);

    String webPath = doc.getParentDatabase().getFilePath().replace("\\", "/");

    String scheme = request.getScheme();

    url.append(scheme);//from  w  w w.  j  a v a  2 s .  c o  m
    url.append("://");
    url.append(request.getServerName());

    int port = request.getServerPort();
    if (port > 0 && (("http".equalsIgnoreCase(scheme) && port != 80)
            || ("https".equalsIgnoreCase(scheme) && port != 443))) {
        url.append(':');
        url.append(port);
    }

    url.append(webPath);
    url.append('/');
    url.append(xpage);
    url.append("?documentId=" + doc.getUniversalID());
    url.append("&action=openDocument");

    return url.toString();
}

From source file:fr.paris.lutece.util.http.SecurityUtil.java

/**
 * Write request variables into the dump stringbuffer
 * @param sb The dump stringbuffer/*w ww. j  a v  a 2 s . com*/
 * @param request The HTTP request
 */
private static void dumpVariables(StringBuffer sb, HttpServletRequest request) {
    dumpVariable(sb, "AUTH_TYPE", request.getAuthType());
    dumpVariable(sb, "REQUEST_METHOD", request.getMethod());
    dumpVariable(sb, "PATH_INFO", request.getPathInfo());
    dumpVariable(sb, "PATH_TRANSLATED", request.getPathTranslated());
    dumpVariable(sb, "QUERY_STRING", request.getQueryString());
    dumpVariable(sb, "REQUEST_URI", request.getRequestURI());
    dumpVariable(sb, "SCRIPT_NAME", request.getServletPath());
    dumpVariable(sb, "LOCAL_ADDR", request.getLocalAddr());
    dumpVariable(sb, "SERVER_PROTOCOL", request.getProtocol());
    dumpVariable(sb, "REMOTE_ADDR", request.getRemoteAddr());
    dumpVariable(sb, "REMOTE_HOST", request.getRemoteHost());
    dumpVariable(sb, "HTTPS", request.getScheme());
    dumpVariable(sb, "SERVER_NAME", request.getServerName());
    dumpVariable(sb, "SERVER_PORT", String.valueOf(request.getServerPort()));
}

From source file:org.simbasecurity.core.service.http.ChangePasswordController.java

private String reconstructSimbaWebURL(HttpServletRequest request) {
    return request.getScheme() + "://" + request.getServerName()
            + (request.getServerPort() != 80 ? ":" + request.getServerPort() : "") + request.getContextPath();
}

From source file:br.com.devopsnapratica.controller.account.LoginController.java

@Override
public String getResetPasswordUrl(HttpServletRequest request) {
    String url = request.getScheme() + "://" + request.getServerName()
            + getResetPasswordPort(request, request.getScheme() + "/");

    if (request.getContextPath() != null && !"".equals(request.getContextPath())) {
        url = url + request.getContextPath() + "/login/resetPassword";
    } else {//w  w w  .j a v a  2s.  co  m
        url = url + "/login/resetPassword";
    }
    return url;
}

From source file:com.github.javarch.jsf.context.FacesContextUtils.java

/**
 * Retorna o caminho da aplicao, incluindo protocolo http.
 * /*from   www.java 2 s  .co m*/
 * @return Caminho da aplicao
 */
public String getApplicationPath() {
    HttpServletRequest request = getRequest();
    return request.getScheme() + "://" + request.getServerName()
            + (request.getServerPort() != 80 ? ":" + request.getServerPort() : "") + request.getContextPath();
}

From source file:org.ngrinder.agent.controller.AgentDownloadController.java

private String downloadFile(String owner, String region, ModelMap modelMap, HttpServletRequest request) {
    String connectingIP = request.getServerName();
    int port = getConfig().getControllerPort();
    try {//from ww  w. jav  a2  s.  c  o  m
        if (isClustered()) {
            checkNotEmpty(region, "region should be provided to download agent in cluster mode.");
            RegionInfo regionInfo = checkNotNull(regionService.getOne(region),
                    "selecting region '" + region + "'" + " is not valid");
            port = regionInfo.getControllerPort();
            connectingIP = regionInfo.getIp();
        }
        final File agentPackage = agentPackageService.createAgentPackage(region, connectingIP, port, owner);
        modelMap.clear();
        return "redirect:/agent/download/" + agentPackage.getName();
    } catch (Exception e) {
        throw processException(e);
    }
}

From source file:company.gonapps.loghut.controller.LogoutController.java

@RequestMapping(value = "/logout.do", method = RequestMethod.GET)
public String logout(HttpServletRequest request) throws Exception {
    request.getSession(false).invalidate();
    return "redirect:" + request.getScheme() + "://" + request.getServerName()
            + getSettingDao().getSetting("admin.url") + "/login_form.do";
}

From source file:org.ow2.chameleon.everest.servlet.PathSerializer.java

public PathSerializer(HttpServletRequest request, String servletPath) {
    if (request != null) {
        m_server = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + servletPath;/*from w w w.  java  2  s.c  om*/
    } else {
        // No request, just keep the path as it is.
        m_server = "";
    }
}

From source file:cn.tiup.httpproxy.ProxyServlet.java

private static String getHost(HttpServletRequest request) {
    StringBuffer requestURL = request.getRequestURL();
    try {/*from  www.  ja  v  a  2s . co  m*/
        URI uri = new URI(requestURL.toString());
        int port = uri.getPort();
        if (port > 0 && port != 80 && port != 443) {
            return uri.getHost() + ":" + Integer.toString(port);
        } else {
            return uri.getHost();
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return request.getServerName();
}