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:nl.surfnet.coin.selfservice.control.ServiceDetailController.java

private String getBaseUrl(HttpServletRequest request) {
    int serverPort = request.getServerPort();
    String baseUrl;//w  ww .jav a2 s.c om
    if (serverPort != 80) {
        baseUrl = String.format("%s://%s:%d%s/", request.getScheme(), request.getServerName(),
                request.getServerPort(), request.getContextPath());
    } else {
        baseUrl = String.format("%s://%s%s/", request.getScheme(), request.getServerName(),
                request.getContextPath());
    }
    return baseUrl;
}

From source file:org.alfresco.module.vti.web.actions.VtiWelcomeInfoAction.java

private String getVtiUrl(HttpServletRequest request) {
    String url = request.getScheme() + "://" + request.getServerName();
    if (request.getServerPort() != 80 && request.getServerPort() != 443) {
        url += ":" + request.getServerPort();
    }/*from   w  w  w  . j  a v a2  s  .  c o m*/
    url += vtiPathHelper.getAlfrescoContext();
    if (!url.endsWith("/")) {
        url += "/";
    }
    return url;
}

From source file:org.apache.struts.util.RequestUtils.java

/**
 * <p>Return the string representing the scheme, server, and port number
 * of the current request. Server-relative URLs can be created by simply
 * appending the server-relative path (starting with '/') to this.</p>
 *
 * @param request The servlet request we are processing
 * @return URL representing the scheme, server, and port number of the
 *         current request//from  ww  w  .jav  a  2  s .  c o m
 * @since Struts 1.2.0
 */
public static StringBuffer requestToServerUriStringBuffer(HttpServletRequest request) {
    StringBuffer serverUri = createServerUriStringBuffer(request.getScheme(), request.getServerName(),
            request.getServerPort(), request.getRequestURI());

    return serverUri;
}

From source file:org.n52.tamis.rest.forward.processes.jobs.StatusRequestForwarder.java

private String constructTamisBaseUrl(HttpServletRequest request) {
    String target_baseUrl = request.getScheme() + "://" + request.getServerName() + ":"
            + request.getServerPort() + request.getContextPath();
    return target_baseUrl;
}

From source file:be.fedict.eid.dss.sp.bean.SignatureRequestServiceBean.java

@Override
public String getSPDestination() {

    HttpServletRequest httpServletRequest = getHttpServletRequest();

    return httpServletRequest.getScheme() + "://" + httpServletRequest.getServerName() + ":"
            + httpServletRequest.getServerPort() + httpServletRequest.getContextPath() + "/dss-response";

    // return "../eid-dss-sp/dss-response";
}

From source file:com.toughland.helpmechoose.common.Helper.java

public String getUrl(HttpServletRequest request) {
    return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/";
}

From source file:com.dotmarketing.portlets.contentlet.business.FileAssetTest.java

@Before
public void before() throws Exception {

    LicenseTestUtil.getLicense();//from w w w  . j  a  va 2  s .  co  m

    client = RestClientBuilder.newClient();
    HttpServletRequest request = ServletTestRunner.localRequest.get();
    String serverName = request.getServerName();
    long serverPort = request.getServerPort();
    webTarget = client.target("http://" + serverName + ":" + serverPort + "/");
}

From source file:ch.puzzle.modjprof.control.ControlServlet.java

private String getBaseUri(HttpServletRequest request) {
    String baseURI = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/";
    return baseURI;
}

From source file:com.sdl.odata.controller.AbstractODataController.java

/**
 * In cases when {@link HttpServletRequest} is wrapped, request url will consist values from top wrapper now.
 * Instead of schema, port and server name from inner {@link org.apache.coyote.Request}.
 * Default case is when service is behind load balancer and {@link org.apache.catalina.filters.RemoteIpFilter}
 * is used for X-Forwarded headers./*w  ww .  j  av a  2  s  .  co  m*/
 *
 * @param request wrapped/original request.
 * @return request URL based on values from wrapping Request.
 */
private StringBuilder getRequestURL(HttpServletRequest request) {
    String scheme = request.getScheme();
    int port = request.getServerPort();
    if (port < 0) {
        port = DEFAULT_PORT_NUMBER;
    }

    StringBuilder url = new StringBuilder();
    url.append(scheme);
    url.append("://");
    url.append(request.getServerName());
    if ((scheme.equals("http") && (port != DEFAULT_PORT_NUMBER))
            || (scheme.equals("https") && (port != DEFAULT_SSL_PORT_NUMBER))) {
        url.append(':');
        url.append(port);
    }
    url.append(request.getRequestURI());
    return url;
}

From source file:org.socialhistoryservices.pid.ws.WsdlAdapter.java

/**
 * We override this method because we need to be able to return absolute URLs.
 *
 * @param location Location of the wsdl/*from  ww  w  .  ja  va 2s  .  co m*/
 * @param request Http request
 * @return The absolute url
 */
@Override
protected String transformLocation(String location, HttpServletRequest request) {

    if (!location.startsWith("/"))
        return location;
    StringBuilder url = new StringBuilder(request.getScheme());
    url.append("://").append(request.getServerName()).append(':').append(request.getServerPort());
    // a relative path, prepend the context path
    url.append(request.getContextPath()).append(location);
    return url.toString();
}