Example usage for javax.servlet.http HttpServletRequest getScheme

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

Introduction

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

Prototype

public String getScheme();

Source Link

Document

Returns the name of the scheme used to make this request, for example, <code>http</code>, <code>https</code>, or <code>ftp</code>.

Usage

From source file:org.itracker.web.servlets.GenericController.java

protected static void redirect(String url, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    String baseURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath();/*  ww  w . j av  a 2s . co m*/

    response.sendRedirect(baseURL + url);
}

From source file:org.jahia.utils.Url.java

/**
 * Returns the server URL, including scheme, host and port.
 * The URL is in the form <code><scheme><host>:<port></code>,
 * e.g. <code>http://www.jahia.org:8080</code>. The port is omitted in case
 * of standard HTTP (80) and HTTPS (443) ports.
 *
 * @return the server URL, including scheme, host and port
 *//*from  www .jav a 2 s .  c o  m*/
public static String getServer(HttpServletRequest request) {
    return getServer(request.getScheme(), request.getServerName(), request.getServerPort());
}

From source file:org.jahia.utils.Url.java

public static String getServer(HttpServletRequest request, String servername) {
    return getServer(request.getScheme(), servername, request.getServerPort());
}

From source file:ServletUtils.java

/**
 * NOT UNIT TESTED Returns the URL (including query parameters) minus the scheme, host, and
 * context path.  This method probably be moved to a more general purpose
 * class.//from   w w  w .j  ava 2s  . co  m
 */
public static String getRelativeUrl(HttpServletRequest request) {

    String baseUrl = null;

    if ((request.getServerPort() == 80) || (request.getServerPort() == 443))
        baseUrl = request.getScheme() + "://" + request.getServerName() + request.getContextPath();
    else
        baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath();

    StringBuffer buf = request.getRequestURL();

    if (request.getQueryString() != null) {
        buf.append("?");
        buf.append(request.getQueryString());
    }

    return buf.substring(baseUrl.length());
}

From source file:dk.dma.msinm.common.util.WebUtils.java

/**
 * Returns the base URL of the request/* w w  w  .j a v a2 s.c o  m*/
 * @param request the request
 * @return the base URL
 */
public static String getWebAppUrl(HttpServletRequest request, String... appends) {
    String result = String.format("%s://%s%s%s", request.getScheme(), request.getServerName(),
            request.getServerPort() == 80 || request.getServerPort() == 443 ? ""
                    : ":" + request.getServerPort(),
            request.getContextPath());
    for (String a : appends) {
        result = result + a;
    }
    return result;
}

From source file:org.benjp.listener.ServerBootstrap.java

public static String getServerBase() {
    String serverBase = PropertyManager.getProperty(PropertyManager.PROPERTY_CHAT_SERVER_BASE);
    if ("".equals(serverBase)) {
        HttpServletRequest request = Util.getPortalRequestContext().getRequest();
        String scheme = request.getScheme();
        String serverName = request.getServerName();
        int serverPort = request.getServerPort();
        serverBase = scheme + "://" + serverName;
        if (serverPort != 80)
            serverBase += ":" + serverPort;
    }//from w w w  .  j av a  2  s . com

    return serverBase;

}

From source file:be.fedict.eid.pkira.common.security.AbstractAuthenticationHandlerBean.java

public static final String getIssuer(HttpServletRequest request) {
    StringBuilder url = new StringBuilder();
    String scheme = request.getScheme();
    String hostName = request.getServerName();
    int port = request.getServerPort();

    url.append(scheme);/*from  w  ww . j a v a 2 s. co m*/
    url.append("://");
    url.append(hostName);
    if (port > 0 && ((scheme.equalsIgnoreCase("http") && port != 80)
            || (scheme.equalsIgnoreCase("https") && port != 443))) {
        url.append(':');
        url.append(port);
    }

    return url.toString();
}

From source file:com.pamarin.income.util.UrlUtils.java

/**
 * build pattern//www  .  j a  v a 2s . c  om
 * <ul>
 * <li>[http|s]://[domainName]:[port]/[contextRoot]</li>
 * <li>http://pamarin.com/</li>
 * <li>http://localhost:8080/</li>
 * <li>http://localhost/pamarin</li>
 * </ul>
 * ignore port 80 and 443
 *
 * @param request
 * @return
 */
public static String buildHostUrl(HttpServletRequest request) {
    String contextPath = request.getContextPath();
    String protocol = request.getScheme();
    String domain = request.getServerName();
    String port = request.getServerPort() + "";
    port = isReservePort(port) ? "" : (":" + port);

    return protocol + "://" + domain + port + contextPath;
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.RedirectUtils.java

/**
 * Build a redirect url./*from  www  .j a  v a2  s.  c  om*/
 * @param request  the request
 * @param response  the response
 * @param url the target url to redirect to
 * @return  the url
 */
public static String buildRedirectUrl(final HttpServletRequest request, final HttpServletResponse response,
        final String url) {

    if (!url.startsWith("http://") && !url.startsWith("https://")) {
        String scheme = request.getScheme();
        int serverPort = RESOLVER.getServerPort(request);
        boolean inHttp = "http".equalsIgnoreCase(scheme);
        boolean inHttps = "https".equalsIgnoreCase(scheme);
        boolean includePort = !((inHttp && serverPort == 80) || (inHttps && serverPort == 443));
        String port = includePort ? ":" + serverPort : "";
        return scheme + "://" + request.getServerName() + port + request.getContextPath() + url;
    }

    return url;
}

From source file:com.eryansky.common.web.utils.RequestUtil.java

public static String getAppURL(HttpServletRequest request) {
    StringBuffer url = new StringBuffer();
    int port = request.getServerPort();
    if (port < 0) {
        port = 80;/* w  ww  .j a  v a  2  s  .c o m*/
    }
    String scheme = request.getScheme();
    url.append(scheme);
    url.append("://");
    url.append(request.getServerName());
    if (((scheme.equals("http")) && (port != 80)) || ((scheme.equals("https")) && (port != 443))) {
        url.append(':');
        url.append(port);
    }
    url.append(request.getContextPath());
    return url.toString();
}