Example usage for org.springframework.security.web.servletapi SecurityContextHolderAwareRequestWrapper getServerPort

List of usage examples for org.springframework.security.web.servletapi SecurityContextHolderAwareRequestWrapper getServerPort

Introduction

In this page you can find the example usage for org.springframework.security.web.servletapi SecurityContextHolderAwareRequestWrapper getServerPort.

Prototype

public int getServerPort() 

Source Link

Document

The default behavior of this method is to return getServerPort() on the wrapped request object.

Usage

From source file:org.ngrinder.common.util.HttpContainerContext.java

/**
 * Get current container nGrinder context base path.
 * <p/>/*from  www . jav  a 2  s  .  com*/
 * E.g) if user requests http://hostname:port/context_path/realurl, This
 * will return http://hostname:port/context_path
 * <p/>
 * In case of providing "http.url" property in system.properties file, this
 * method will return pre-set value.
 *
 * @return ngrinder context base path on http request.
 */
public String getCurrentContextUrlFromUserRequest() {
    String httpUrl = StringUtils.trimToEmpty(config.getControllerProperties().getProperty(PROP_CONTROLLER_URL));
    // if provided
    if (StringUtils.isNotBlank(httpUrl)) {
        return httpUrl;
    }

    // if empty
    SecurityContextHolderAwareRequestWrapper request = cast(
            RequestContextHolder.currentRequestAttributes().resolveReference("request"));
    int serverPort = request.getServerPort();
    // If it's http default port it will ignore the port part.
    // However, if ngrinder is provided in HTTPS.. it can be a problem.
    // FIXME : Later fix above.
    String portString = (serverPort == DEFAULT_WEB_PORT) ? StringUtils.EMPTY : ":" + serverPort;
    return httpUrl + request.getScheme() + "://" + request.getServerName() + portString
            + request.getContextPath();
}