Example usage for org.springframework.web.context.request RequestAttributes SCOPE_REQUEST

List of usage examples for org.springframework.web.context.request RequestAttributes SCOPE_REQUEST

Introduction

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

Prototype

int SCOPE_REQUEST

To view the source code for org.springframework.web.context.request RequestAttributes SCOPE_REQUEST.

Click Source Link

Document

Constant that indicates request scope.

Usage

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

/**
 * Sets the request correlation id.//from  www .  j av a 2 s  .co  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:com.github.dactiv.common.spring.mvc.SpringMvcHolder.java

/**
 * ?request attribute/* w w w  .j  a  v  a  2s. com*/
 * 
 * @param name ??
 * 
 * @return Object
 */
public static <T> T getRequestAttribute(String name) {
    return (T) getAttribute(name, RequestAttributes.SCOPE_REQUEST);
}

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  a  2s  . c  o  m*/
@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:com.github.dactiv.common.spring.mvc.SpringMvcHolder.java

/**
 * request attribute/*  w w  w . jav a2  s.co  m*/
 * 
 * @param name ??
 * @param value 
 */
public static void addRequestAttribute(String name, Object value) {
    addAttribute(name, value, RequestAttributes.SCOPE_REQUEST);
}

From source file:com.wms.multitenant.tenant.resolver.CurrentTenantResolverImpl.java

@Override
public String resolveCurrentTenantIdentifier() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes != null) {
        String identifier = (String) requestAttributes.getAttribute("Current_Tenant",
                RequestAttributes.SCOPE_REQUEST);
        if (identifier != null) {
            return identifier;
        }/*from  w  ww  .j a  v  a 2  s  . c  o m*/
    }
    return "";
}

From source file:net.jforum.core.support.spring.HttpServletResponseFactoryBean.java

/**
 * @see org.springframework.beans.factory.FactoryBean#getObject()
 *//*ww  w .  j av a2  s. c  o  m*/
public HttpServletResponse getObject() throws Exception {
    RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
    return (HttpServletResponse) attributes.getAttribute(ConfigKeys.HTTP_SERVLET_RESPONSE,
            RequestAttributes.SCOPE_REQUEST);
}

From source file:com.springsource.greenhouse.utils.Location.java

/**
 * Get the location of the user associated with the current request, if resolvable.
 *//*ww  w  . ja  va  2 s . co m*/
public static Location getCurrentLocation() {
    RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
    return attributes != null
            ? (Location) attributes.getAttribute(UserLocationHandlerInterceptor.USER_LOCATION_ATTRIBUTE,
                    RequestAttributes.SCOPE_REQUEST)
            : null;
}

From source file:org.opensprout.osaf.web.session.PrefixedSessionAttributeStore.java

@Override
public void storeAttribute(WebRequest request, String attributeName, Object attributeValue) {
    String prefix = (String) request.getAttribute(SessionAttributeNameInterceptor.SESSION_ATTR_PREFIX,
            RequestAttributes.SCOPE_REQUEST);
    super.storeAttribute(request, prefix + attributeName, attributeValue);
}

From source file:com.example.notes.ExceptionSupressingErrorAttributes.java

@Override
public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) {
    Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
    errorAttributes.remove("exception");
    Object message = requestAttributes.getAttribute("javax.servlet.error.message",
            RequestAttributes.SCOPE_REQUEST);
    if (message != null) {
        errorAttributes.put("message", message);
    }//from  w ww  .  j  a v  a 2  s  .com
    return errorAttributes;
}

From source file:net.groupbuy.template.directive.ExecuteTimeDirective.java

@SuppressWarnings("rawtypes")
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {
    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    if (requestAttributes != null) {
        Long executeTime = (Long) requestAttributes.getAttribute(
                ExecuteTimeInterceptor.EXECUTE_TIME_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);
        if (executeTime != null) {
            setLocalVariable(VARIABLE_NAME, executeTime, env, body);
        }/*from   ww  w .  j av a  2  s.c  o m*/
    }
}