Example usage for javax.servlet.http HttpServletRequest getServerPort

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

Introduction

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

Prototype

public int getServerPort();

Source Link

Document

Returns the port number to which the request was sent.

Usage

From source file:com.opendesign.utils.ControllerUtil.java

public static String getHostName(HttpServletRequest request) {

    String scheme = request.getScheme();
    String serverName = request.getServerName();
    int portNumber = request.getServerPort();
    String contextPath = request.getContextPath();

    String host = scheme + "://" + serverName + contextPath + ":" + portNumber;
    if (portNumber == 80) {
        host = scheme + "://" + serverName + contextPath;
    }//from   ww w  .ja v a  2  s.  c  o m

    return host;
}

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();/*from w  w  w . j  av  a2 s. com*/

    response.sendRedirect(baseURL + url);
}

From source file:alpha.portal.webapp.util.RequestUtil.java

/**
 * Convenience method to get the application's URL based on request
 * variables./*from  w ww.j ava  2s . co m*/
 * 
 * @param request
 *            the current request
 * @return URL to application
 */
public static String getAppURL(final HttpServletRequest request) {
    if (request == null)
        return "";

    final StringBuffer url = new StringBuffer();
    int port = request.getServerPort();
    if (port < 0) {
        port = 80; // Work around java.net.URL bug
    }
    final 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();
}

From source file:org.magnum.dataup.VideoServiceController.java

private static String getUrlBaseForLocalServer() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();//  w w w .ja v  a  2s  . c o  m
    String base = "http://" + request.getServerName()
            + ((request.getServerPort() != 80) ? ":" + request.getServerPort() : "");
    return base;
}

From source file:org.sventon.util.WebUtils.java

/**
 * Extracts the full request URL, including scheme, server name,
 * server port (if not 80) and context path.
 *
 * @param request The request.//from   w  w  w  .  j a  v a 2 s  .  c o m
 * @return The full URL, ending with a forward slash (/).
 */
public static String extractBaseURLFromRequest(final HttpServletRequest request) {
    final StringBuilder sb = new StringBuilder();
    sb.append(request.getScheme());
    sb.append("://");
    sb.append(request.getServerName());
    if (request.getServerPort() != 80) {
        sb.append(":");
        sb.append(request.getServerPort());
    }
    sb.append(request.getContextPath());
    sb.append("/");
    return sb.toString();
}

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

/**
 * Returns the base URL of the request//from w  ww  .j a va 2s .  c om
 * @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.apache.qpid.server.management.plugin.HttpManagementUtil.java

public static SocketAddress getSocketAddress(HttpServletRequest request) {
    return InetSocketAddress.createUnresolved(request.getServerName(), request.getServerPort());
}

From source file:com.matel.pg.components.OAuthController.java

/**
 *
 * @param request//from w  ww.j  a  v  a 2s .  c om
 * @return
 */
public static String getProtocolHostnameAndPort(final HttpServletRequest request) {
    String protocol = request.getProtocol().split("/")[0].toLowerCase();
    String hostname = request.getServerName();
    int port = request.getServerPort();

    StringBuilder result = new StringBuilder(protocol + "://" + hostname);
    if (port != 80) {
        result.append(":").append(port);
    }

    return result.toString();
}

From source file:eu.europeana.core.util.web.ControllerUtil.java

public static String getServletUrl(HttpServletRequest request) {
    String url = request.getRequestURL().toString();
    int index = url.indexOf(request.getServerName());
    url = url.substring(0, index) + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath();/*from  w w w . j a va  2s . c o m*/
    return url;
}

From source file:eu.europeana.core.util.web.ControllerUtil.java

public static String getFullServletUrl(HttpServletRequest request) {
    String url = request.getRequestURL().toString();
    int index = url.indexOf(request.getServerName());
    url = url.substring(0, index) + request.getServerName() + ":" + request.getServerPort()
            + request.getRequestURI();/* w w  w .jav a2  s.  c o  m*/
    return url;
}