Example usage for org.springframework.web.context.request ServletRequestAttributes getRequest

List of usage examples for org.springframework.web.context.request ServletRequestAttributes getRequest

Introduction

In this page you can find the example usage for org.springframework.web.context.request ServletRequestAttributes getRequest.

Prototype

public final HttpServletRequest getRequest() 

Source Link

Document

Exposes the native HttpServletRequest that we're wrapping.

Usage

From source file:io.pivotal.cla.mvc.ClaRequest.java

private String syncUrl() throws Exception {
    ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes();/*from  w w w  .  j a v a 2s  .  c  o m*/
    HttpServletRequest request = requestAttributes.getRequest();
    return UrlBuilder.createSyncUrl(request, claName, repositoryId, pullRequestId);
}

From source file:io.pivotal.cla.mvc.ClaRequest.java

private String faqUrl() throws Exception {
    ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes();//w w w.  ja  va  2s . c o  m
    HttpServletRequest request = requestAttributes.getRequest();

    return UrlBuilder.createAboutUrl(request);
}

From source file:io.pivotal.cla.mvc.ClaRequest.java

private String signUrl() throws Exception {
    ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes();//from w w  w .  ja v a  2 s.  c  o  m
    HttpServletRequest request = requestAttributes.getRequest();

    return UrlBuilder.signUrl().request(request).claName(claName).repositoryId(repositoryId)
            .pullRequestId(pullRequestId).build();
}

From source file:org.dspace.webmvc.view.freemarker.SpringThemeAwareFreemarkerConfiguration.java

@Override
public Template getTemplate(String name, Locale locale, String encoding, boolean parse) throws IOException {

    String themePath = SpringThemeContextUtils.getProperty("theme.template.path");

    // If we have a theme path, attempt locating the template within the theme first
    if (themePath != null) {
        try {/*  w w w .j a  v a  2s. com*/
            return super.getTemplate(themePath + name, locale, encoding, parse);
        } catch (IOException ioe) {
            // Will throw an exception if there is no template in the theme path,
            // we will ignore it, and try the standard path locations
        }
    }

    String themeParentName = SpringThemeContextUtils.getProperty("theme.parent", null);
    if (!StringUtils.isEmpty(themeParentName)) {
        RequestAttributes ra = RequestContextHolder.currentRequestAttributes();
        if (ra instanceof ServletRequestAttributes) {
            ServletRequestAttributes sra = (ServletRequestAttributes) ra;
            ThemeSource ts = RequestContextUtils.getThemeSource(sra.getRequest());

            if (ts != null) {
                Theme parentTheme = ts.getTheme(themeParentName);

                while (parentTheme != null) {
                    themePath = SpringThemeUtils.getProperty(parentTheme, "theme.template.path", locale, null);
                    if (themePath != null) {
                        try {
                            return super.getTemplate(themePath + name, locale, encoding, parse);
                        } catch (IOException ioe) {
                            // Will throw an exception if there is no template in the theme path,
                            // we will ignore it, and try the standard path locations
                        }
                    }

                    themeParentName = SpringThemeUtils.getProperty(parentTheme, "theme.parent", locale, null);
                    parentTheme = ts.getTheme(themeParentName);
                }

            }
        }
    }

    // No template in the theme path, so get a template from the standard location
    return super.getTemplate(name, locale, encoding, parse);
}

From source file:org.jasig.cas.ticket.support.AbstractCasExpirationPolicy.java

/**
 * Gets the http request based on the//from   w  w  w.  java  2 s. c o m
 * {@link org.springframework.web.context.request.RequestContextHolder}.
 * @return the request or null
 */
protected final HttpServletRequest getRequest() {
    try {
        final ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder
                .currentRequestAttributes();
        if (attrs != null) {
            return attrs.getRequest();
        }
    } catch (final Exception e) {
        logger.trace("Unable to obtain the http request", e);
    }
    return null;
}

From source file:com.krawler.esp.database.MBasicDataSource.java

@Override
public Connection getConnection() throws SQLException {
    ServletRequestAttributes ss = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    String domain_key = "";
    try {// ww  w. j  av a  2 s .co  m
        domain_key = URLUtil.getDomainName(ss.getRequest());
    } catch (Exception ex) {
        System.out.print(ex);
    }
    if (!dataSourceMap.containsKey(domain_key)) {
        dataSourceMap.put(domain_key, createDataSource(domain_key));
    }
    super.dataSource = (DataSource) dataSourceMap.get(domain_key);
    return super.dataSource.getConnection();
}

From source file:ru.anr.base.facade.web.api.AbstractAPIController.java

/**
 * Construction of API Command with request specific params (taken from a
 * current request)/* w w  w . j  a v  a2  s  . co  m*/
 * 
 * @param commandId
 *            Identifier of command
 * @param apiVersion
 *            Version of API
 * @return An instance of API command
 */
protected APICommand buildAPI(String commandId, String apiVersion) {

    ServletRequestAttributes r = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    return CommandUtils.build(commandId, apiVersion, r.getRequest());
}

From source file:eu.supersede.fe.security.AuthenticationSuccessListener.java

@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    DatabaseUser userDetails = (DatabaseUser) event.getAuthentication().getPrincipal();

    HttpServletRequest req = attr.getRequest();
    String multiTenantId = req.getHeader("TenantId");
    userDetails.setTenantId(multiTenantId);
}

From source file:io.kahu.hawaii.rest.AbstractController.java

protected RequestLogBuilder requestLog() {

    String method = new Throwable().getStackTrace()[1].getMethodName();
    String type = logTypePrefix + "." + method;
    RequestLogBuilder builder = new RequestLogBuilder(logManager, type);

    try {/*from  w  w  w.  ja  v a  2 s  .c om*/
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = sra.getRequest();

        // path variables
        Map<String, String> pathVariables = (Map<String, String>) request
                .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        if (pathVariables != null) {
            for (Map.Entry<String, String> entry : pathVariables.entrySet()) {
                builder.param(entry.getKey(), entry.getValue());
            }
        }

        // request parameters
        Enumeration<?> requestParameters = request.getParameterNames();
        while (requestParameters.hasMoreElements()) {
            String key = (String) requestParameters.nextElement();
            String[] values = request.getParameterValues(key);
            builder.param(key, values);
        }

    } catch (Throwable t) {
        logManager.warn(CoreLoggers.SERVER, "Unable to log request", t);
        // ignore
    }
    return builder.excludeParam("_");
}

From source file:com.revolsys.ui.web.config.HttpServletRequestJexlContext.java

private HttpServletRequest getRequest() {
    final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes();//from   w ww .j  a  v a 2 s  . c o  m
    final HttpServletRequest request = requestAttributes.getRequest();
    return request;
}