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

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

Introduction

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

Prototype

void setAttribute(String name, Object value, int scope);

Source Link

Document

Set the value for the scoped attribute of the given name, replacing an existing value (if any).

Usage

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   ww  w. ja va 2  s . c o m
 * 
 * @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:com.centeractive.ws.server.protocol.GenericSoapMessageFactory.java

private void setMessageFactoryForRequestContext(SaajSoapMessageFactory factory) {
    RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
    attributes.setAttribute(REQUEST_CONTEXT_ATTRIBUTE, factory, RequestAttributes.SCOPE_REQUEST);
}

From source file:org.jasig.portlet.emailpreview.dao.exchange.MailCredentialsProvider.java

@Override
public void clear() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes != null) {
        // Exchange
        requestAttributes.setAttribute(MailCredentialsProvider.EXCHANGE_CREDENTIALS_ATTRIBUTE, null,
                RequestAttributes.SCOPE_REQUEST);

        // Javamail
        requestAttributes.setAttribute(MailCredentialsProvider.JAVAMAIL_CREDENTIALS_ATTRIBUTE, null,
                RequestAttributes.SCOPE_REQUEST);
    }/*w w w .j a  v a2  s.c  om*/
}

From source file:net.groupbuy.controller.admin.BaseController.java

/**
 * /*from  w  ww .j  a  v  a 2s.co m*/
 * 
 * @param content
 *            
 */
protected void addLog(String content) {
    if (content != null) {
        RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
        requestAttributes.setAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME, content,
                RequestAttributes.SCOPE_REQUEST);
    }
}

From source file:net.groupbuy.controller.admin.BaseController.java

/**
 * ??//from  ww w  .j a  va  2 s . co m
 * 
 * @param target
 *            ?
 * @param groups
 *            ?
 * @return ?
 */
protected boolean isValid(Object target, Class<?>... groups) {
    Set<ConstraintViolation<Object>> constraintViolations = validator.validate(target, groups);
    if (constraintViolations.isEmpty()) {
        return true;
    } else {
        RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
        requestAttributes.setAttribute(CONSTRAINT_VIOLATIONS_ATTRIBUTE_NAME, constraintViolations,
                RequestAttributes.SCOPE_REQUEST);
        return false;
    }
}

From source file:net.groupbuy.controller.admin.BaseController.java

/**
 * ??// w w w.  j  av a  2  s  .co  m
 * 
 * @param type
 *            
 * @param property
 *            
 * @param value
 *            
 * @param groups
 *            ?
 * @return ?
 */
protected boolean isValid(Class<?> type, String property, Object value, Class<?>... groups) {
    Set<?> constraintViolations = validator.validateValue(type, property, value, groups);
    if (constraintViolations.isEmpty()) {
        return true;
    } else {
        RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
        requestAttributes.setAttribute(CONSTRAINT_VIOLATIONS_ATTRIBUTE_NAME, constraintViolations,
                RequestAttributes.SCOPE_REQUEST);
        return false;
    }
}

From source file:cz.cvut.zuul.support.spring.client.ScopedOAuth2ClientContext.java

@SuppressWarnings("unchecked")
private <T> T scopedAttribute(String name, ObjectFactory<T> factory, int scope) {
    RequestAttributes attributes = currentRequestAttributes();
    String key = prefixKey(name);

    Object value = attributes.getAttribute(key, scope);
    if (value == null) {
        value = factory.getObject();/*from   ww w  .ja va2s  .  c  o  m*/
        attributes.setAttribute(key, value, scope);
    }
    return (T) value;
}

From source file:org.jasig.portlet.emailpreview.dao.exchange.MailCredentialsProvider.java

@Override
public void initialize(PortletRequest request, MailStoreConfiguration config,
        IAuthenticationService authService) {

    // Exchange/* ww  w  . ja va 2  s  .  c  o m*/
    Credentials credentials = authService.getCredentials(request, config);

    // cache the credentials object to this thread
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes == null) {
        requestAttributes = new PortletRequestAttributes(request);
        RequestContextHolder.setRequestAttributes(requestAttributes);
    }
    requestAttributes.setAttribute(MailCredentialsProvider.EXCHANGE_CREDENTIALS_ATTRIBUTE, credentials,
            RequestAttributes.SCOPE_REQUEST);

    // Javamail
    Authenticator authenticator = authService.getAuthenticator(request, config);
    requestAttributes.setAttribute(MailCredentialsProvider.JAVAMAIL_CREDENTIALS_ATTRIBUTE, authenticator,
            RequestAttributes.SCOPE_REQUEST);
}