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

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

Introduction

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

Prototype

@Nullable
Object getAttribute(String name, int scope);

Source Link

Document

Return the value for the scoped attribute of the given name, if any.

Usage

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

/**
 * Get the location of the user associated with the current request, if resolvable.
 *///from ww  w  .j  ava2s . c o  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:io.jmnarloch.spring.request.correlation.support.RequestCorrelationUtils.java

/**
 * Retrieves the current request correlation id if present.
 *
 * @return the correlation id or {@code null}
 *//*from w  w w.ja  va  2 s.co  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:ru.smsl.webkrona.util.FlashMap.java

/**
 * Returns the flash map typically stored in window or session scope and creates a new one, if not existing and if
 * needed.//from  www  .  j  a v  a  2  s  .  com
 * 
 * @param createIfNotExisting flag, indicating whether to create the flash map, if it does not exist already
 * @return the flash map currently bound to the session or window scope, if available
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> getFlashMap(boolean createIfNotExisting) {
    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    Map<String, Object> flashMap = (Map<String, Object>) requestAttributes.getAttribute(FLASH_MAP_ATTRIBUTE,
            getFlashMapScope());

    if (flashMap == null && createIfNotExisting) {
        flashMap = new HashMap<String, Object>();
        requestAttributes.setAttribute(FLASH_MAP_ATTRIBUTE, flashMap, getFlashMapScope());
    }

    return flashMap;
}

From source file:org.cloudfoundry.identity.uaa.util.UaaHttpRequestUtils.java

public static boolean isAcceptedInvitationAuthentication() {
    try {//w w w  .  ja  v a  2 s . c  o m
        RequestAttributes attr = RequestContextHolder.currentRequestAttributes();
        if (attr != null) {
            Boolean result = (Boolean) attr.getAttribute("IS_INVITE_ACCEPTANCE",
                    RequestAttributes.SCOPE_SESSION);
            if (result != null) {
                return result.booleanValue();
            }
        }
    } catch (IllegalStateException x) {
        //nothing bound on thread.
        logger.debug("Unable to retrieve request attributes looking for invitation.");

    }
    return false;
}

From source file:de.metas.ui.web.config.WebuiExceptionHandler.java

@SuppressWarnings("unchecked")
private static <T> T getAttribute(final RequestAttributes requestAttributes, final String name) {
    return (T) requestAttributes.getAttribute(name, RequestAttributes.SCOPE_REQUEST);
}

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

/**
 * @see org.springframework.beans.factory.FactoryBean#getObject()
 *//*  ww w . jav 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:org.jasig.portlet.calendar.adapter.exchange.ExchangeWsCredentialsProvider.java

@Override
public Credentials getCredentials(AuthScope authscope) {
    final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    final Credentials credentials = (Credentials) requestAttributes.getAttribute(
            ExchangeWsCredentialsProvider.EXCHANGE_CREDENTIALS_ATTRIBUTE, RequestAttributes.SCOPE_SESSION);
    return credentials;
}

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   ww  w  .j ava 2s  .com
    }
    return "";
}

From source file:uk.ac.ebi.intact.editor.util.HybridSessionThreadScope.java

@Override
public Object get(String name, ObjectFactory objectFactory) {
    Object scopedObject;/*from  ww w .  j  a v a 2 s .c om*/

    if (RequestContextHolder.getRequestAttributes() != null) {
        Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex();

        synchronized (mutex) {
            RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
            scopedObject = attributes.getAttribute(name, RequestAttributes.SCOPE_SESSION);

            if (scopedObject == null) {
                scopedObject = super.get(name, objectFactory);
                attributes.setAttribute(name, scopedObject, RequestAttributes.SCOPE_SESSION);
            }
        }
    } else {
        scopedObject = super.get(name, objectFactory);
    }

    return scopedObject;
}

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  w  w w .j a v a 2s  .com
    }
}