Example usage for org.springframework.web.context.request RequestContextHolder getRequestAttributes

List of usage examples for org.springframework.web.context.request RequestContextHolder getRequestAttributes

Introduction

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

Prototype

@Nullable
public static RequestAttributes getRequestAttributes() 

Source Link

Document

Return the RequestAttributes currently bound to the thread.

Usage

From source file:com.nec.core.context.RequestContext.java

public static HttpServletRequest getRequest() {
    return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}

From source file:com.baomidou.framework.spring.SpringHelper.java

/**
 * ? HttpServletRequest/* ww  w  .  j  a  va  2  s.c om*/
 */
public static HttpServletRequest getHttpServletRequest() {
    return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}

From source file:io.jmnarloch.spring.request.correlation.CorrelationTestUtils.java

/**
 * Sets the request correlation id./*from   ww  w  .j  a  va2 s  .c o  m*/
 *
 * @param requestId the request id
 */
public static void setRequestId(String requestId) {
    RequestContextHolder.getRequestAttributes().setAttribute(RequestCorrelationConsts.ATTRIBUTE_NAME,
            new DefaultRequestCorrelation(requestId), RequestAttributes.SCOPE_REQUEST);
}

From source file:org.perconsys.controllers.BasicController.java

public static HttpSession getSession() {
    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    return attr.getRequest().getSession(true);
}

From source file:io.jmnarloch.spring.request.correlation.support.RequestCorrelationUtils.java

/**
 * Retrieves the current request correlation id if present.
 *
 * @return the correlation id or {@code null}
 *///from   ww  w  . j a v a2s .c  om
@SuppressWarnings("unchecked")
public static String getCurrentCorrelationId() {

    final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes != null) {
        Object correlationId = requestAttributes.getAttribute(RequestCorrelationConsts.ATTRIBUTE_NAME,
                RequestAttributes.SCOPE_REQUEST);

        if (correlationId instanceof RequestCorrelation) {
            return ((RequestCorrelation) correlationId).getRequestId();
        }
    }
    return null;
}

From source file:costumetrade.common.util.IPUtils.java

public static String getClientIpAddress() {

    ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    if (sra == null) {
        return "";
    }/*from   w ww  . j a v a  2 s  . co m*/
    HttpServletRequest req = sra.getRequest();
    return getClientIpAddress(req);
}

From source file:org.openlmis.fulfillment.service.HttpContextHelper.java

/**
 * Static method returning current HTTP Request.
 *
 * @return HttpServletRequest//from   ww  w.j a va2 s . co  m
 */
static HttpServletRequest getCurrentHttpRequest() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();

    return requestAttributes instanceof ServletRequestAttributes
            ? ((ServletRequestAttributes) requestAttributes).getRequest()
            : null;
}

From source file:com.excilys.ebi.bank.web.tld.Functions.java

public static String ctx() {

    HttpServletRequest request = ServletRequestAttributes.class
            .cast(RequestContextHolder.getRequestAttributes()).getRequest();
    return request.getContextPath();
}

From source file:com.jigsforjava.web.context.JigsWebApplicationContext.java

public static UrlMapper getUrlMapper() {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes();/*from   w  ww .jav  a 2 s .  c  o m*/
    return getUrlMapper(attributes.getRequest());
}

From source file:cz.cvut.portal.kos.utils.PortalRequestAccessor.java

public static PortletRequest getCurrentRequest() {
    RequestAttributes attributes = RequestContextHolder.getRequestAttributes();

    if (attributes instanceof PortletRequestAttributes) {
        return ((PortletRequestAttributes) attributes).getRequest();
    }/*from   ww w.j av a 2s  . com*/
    throw new IllegalStateException("Does not run within a PortletContext");
}