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

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

Introduction

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

Prototype

public static RequestAttributes currentRequestAttributes() throws IllegalStateException 

Source Link

Document

Return the RequestAttributes currently bound to the thread.

Usage

From source file:org.craftercms.core.util.HttpServletUtils.java

public static <T> T getAttribute(String name, int scope) throws IllegalStateException {
    return (T) RequestContextHolder.currentRequestAttributes().getAttribute(name, scope);
}

From source file:at.ac.univie.isc.asio.spring.ContextPropagatorTest.java

@Test
public void should_publish_stored_attributes_to_current_thread() throws Exception {
    subject.publish();//from   w  w  w . java  2  s.co  m
    assertThat(RequestContextHolder.currentRequestAttributes(), sameInstance(attributes));
}

From source file:org.jasig.portlet.contacts.context.impl.PortalUserInfoContextProvider.java

private PortletRequest getRequest() {
    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    PortletRequest request = null;//from  w w  w .  j  a v  a  2  s . c o  m
    if (requestAttributes instanceof PortletRequestAttributes) {
        request = ((PortletRequestAttributes) requestAttributes).getRequest();
    }

    return request;
}

From source file:de.appsolve.padelcampus.reporting.ErrorReporter.java

public void notify(Throwable ex) {
    boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString()
            .contains("jdwp");
    if (!isDebug) {
        if (ex != null && !IGNORED_EXCEPTION_CLASS_NAMES.contains(ex.getClass().getSimpleName())) {
            if (ex.getCause() == null
                    || !IGNORED_EXCEPTION_CLASS_NAMES.contains(ex.getCause().getClass().getSimpleName())) {
                try {
                    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder
                            .currentRequestAttributes();
                    //log all errors when we don't have a request context, e.g. for scheduled tasks etc
                    if (attr == null || attr.getRequest() == null) {
                        LOG.error(ex.getMessage(), ex);
                    } else {
                        //if we have a request context, ignore bot requests
                        String userAgent = attr.getRequest().getHeader(HttpHeaders.USER_AGENT);
                        if (!StringUtils.isEmpty(userAgent)
                                && !IGNORED_USER_AGENT_PATTERN.matcher(userAgent).matches()) {
                            bugsnag.notify(ex);
                        }//ww  w  . ja  va  2 s.c om
                    }
                } catch (IllegalStateException e) {
                    LOG.error(ex.getMessage(), ex);
                }

            }
        }
    }
}

From source file:org.vaadin.spring.internal.UIScope.java

private UIStore getUIStore() {
    final String attributeName = UIStore.class.getCanonicalName();
    UIStore uiStore = (UIStore) RequestContextHolder.currentRequestAttributes().getAttribute(attributeName,
            RequestAttributes.SCOPE_SESSION);
    if (uiStore == null) {
        uiStore = new UIStore();
        RequestContextHolder.currentRequestAttributes().setAttribute(attributeName, uiStore,
                RequestAttributes.SCOPE_SESSION);
    }/*from w w w  .j  ava  2 s  . co  m*/
    return uiStore;
}

From source file:com.playtech.portal.platform.portlet.spring.InternalResourceViewResolver.java

private PortletRequest getPortletRequest() {
    return ((org.springframework.web.portlet.context.PortletRequestAttributes) RequestContextHolder
            .currentRequestAttributes()).getRequest();
}

From source file:org.joinfaces.annotations.ViewScope.java

@Override
public Object resolveContextualObject(String key) {
    RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
    return attributes.resolveReference(key);
}

From source file:org.craftercms.core.util.HttpServletUtils.java

public static void setAttribute(String name, Object value, int scope) throws IllegalStateException {
    RequestContextHolder.currentRequestAttributes().setAttribute(name, value, scope);
}

From source file:com.ocs.dynamo.service.impl.DefaultUserDetailsServiceImpl.java

@Override
public boolean isUserInRole(String... roles) {
    try {//from  www  . j  a  va2 s.  com
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
                .currentRequestAttributes()).getRequest();
        for (String r : roles) {
            if (request.isUserInRole(r)) {
                return true;
            }
        }
        return false;
    } catch (Exception ex) {
        return false;
    }
}

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

/**
 * Gets the http request based on the/* w  w w  . j av  a  2s  .co  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;
}