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:nl.ctrlaltdev.harbinger.evidence.EvidenceCollector.java

private Evidence enhance(Evidence evidence) {
    if (evidence.getIp() == null) {
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (sra != null) {
            evidence = new Evidence(evidence, sra.getRequest());
        }//from w  w w .jav  a 2  s. co  m
    }
    if (evidence.getUser() == null) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null) {
            evidence = new Evidence(evidence, auth);
        }
    }
    return evidence;
}

From source file:grails.util.GrailsWebUtil.java

/**
 * @return The currently bound GrailsApplication instance
 * @since 2.0//w  ww. ja v  a2s.co  m
 */
public static GrailsApplication currentApplication() {
    final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (!(requestAttributes instanceof GrailsWebRequest)) {
        return null;
    }

    return ((GrailsWebRequest) requestAttributes).getAttributes().getGrailsApplication();
}

From source file:io.pivotal.cla.mvc.ClaRequest.java

private String signUrl() throws Exception {
    ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes();//  w  w  w. j  a  v  a  2s.  co m
    HttpServletRequest request = requestAttributes.getRequest();

    return UrlBuilder.signUrl().request(request).claName(claName).repositoryId(repositoryId)
            .pullRequestId(pullRequestId).build();
}

From source file:org.cloudfoundry.identity.uaa.web.ForwardAwareInternalResourceViewResolver.java

private MediaType getRequestedMediaType() {
    RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
    Assert.isInstanceOf(ServletRequestAttributes.class, attrs);
    HttpServletRequest request = ((ServletRequestAttributes) attrs).getRequest();
    MediaType requestedMediaType = getMediaTypes(request);
    return requestedMediaType;
}

From source file:com.collin.joyous.web.util.SpringUtil.java

/**
 * ?HttpServletRequest//  w  ww. j av  a  2  s  . c  o m
 * 
 * @return
 */
public static HttpServletRequest getRequest() {
    RequestAttributes ra = RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = ((ServletRequestAttributes) ra).getRequest();
    return request;
}

From source file:com.revolsys.ui.web.config.HttpServletRequestJexlContext.java

private HttpServletRequest getRequest() {
    final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes();//from  w  ww.j a v a 2  s  .  co m
    final HttpServletRequest request = requestAttributes.getRequest();
    return request;
}

From source file:org.hdiv.web.validator.AbstractEditableParameterValidator.java

@SuppressWarnings("unchecked")
protected void validateEditableParameter(String param, Errors errors) {

    RequestAttributes attr = RequestContextHolder.getRequestAttributes();
    if (attr == null) {
        // This is not a web request
        return;// w  ww  . java 2s .com
    }

    Hashtable<String, String[]> parameters = (Hashtable<String, String[]>) attr
            .getAttribute(Constants.EDITABLE_PARAMETER_ERROR, 0);
    if (parameters != null && parameters.size() > 0) {

        String[] unauthorizedValues = parameters.get(param);
        if (unauthorizedValues != null && unauthorizedValues.length > 0) {

            this.rejectParamValues(param, unauthorizedValues, errors);
        }
    }
}

From source file:com.roncoo.controller.BaseController.java

/**
 * ?session
 * 
 * @return
 */
protected HttpSession getSession() {
    return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
}

From source file:de.hybris.platform.chineseprofile.controllers.pages.ChineseEmailPageController.java

@Override
@RequestMapping(value = "", method = RequestMethod.POST, params = "emailLanguage")
@RequireHardLogIn//from   w w  w. j  a  v a 2 s .  c o m
public String updateEmail(final UpdateEmailForm updateEmailForm, final BindingResult bindingResult,
        final Model model, final RedirectAttributes redirectAttributes) throws CMSItemNotFoundException {
    final HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();
    final String emailLanguage = request.getParameter("emailLanguage");
    if (StringUtils.isNotEmpty(emailLanguage)) {
        chineseCustomerFacade.saveEmailLanguageForCurrentUser(emailLanguage);
    }
    return super.updateEmail(updateEmailForm, bindingResult, model, redirectAttributes);
}

From source file:org.dbflute.utflute.spring.web.bean.BarActionTest.java

@Override
public void tearDown() throws Exception {
    assertNotNull(barLogic);//from w w  w . j a  v  a2 s.  c om
    assertNotNull(cachedInjectingBarAction.barLogic);
    assertNotNull(cachedNestedBarLogic.request);
    super.tearDown();
    assertNull(RequestContextHolder.getRequestAttributes());
    assertNull(cachedInjectingBarAction.barLogic);
    assertNull(cachedNestedBarLogic.request);
    assertNull(cachedInjectingBarAction.barLogic);
    assertNull(barLogic);
    cachedInjectingBarAction = null;
    cachedNestedBarLogic = null;
}