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

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

Introduction

In this page you can find the example usage for org.springframework.web.context.request NativeWebRequest 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:org.zht.framework.validate.ValidateHandler.java

public static boolean hasErrors(NativeWebRequest request) {
    Boolean hasError = (Boolean) request.getAttribute(ValidateConstant.BINDING_RESULT_HAS_ERROR, 0);
    if (hasError != null && hasError) {
        return true;
    }/*from   w w w. j a  v  a2s  .c om*/
    return false;
}

From source file:org.zht.framework.validate.ValidateHandler.java

@SuppressWarnings("unchecked")
public static String getDefaultErrorFromResolver(NativeWebRequest request) {
    List<BindingResult> list = (List<BindingResult>) request
            .getAttribute(ValidateConstant.BINDING_RESULT_LIST_NAME, 0);
    if (list != null && list.size() > 0) {
        String error = getDefaultError(list.get(0));
        return error == null ? "" : error;
    }/*from   w w  w  .j a  v a 2s.co  m*/
    return null;
}

From source file:org.impalaframework.extension.mvc.annotation.resolver.FlashAttributeArgumentResolver.java

private boolean isArgumentPending(NativeWebRequest webRequest) {
    return webRequest.getAttribute(WebAnnotationUtils.ARGUMENT_PENDING, WebRequest.SCOPE_REQUEST) == null;
}

From source file:org.impalaframework.extension.mvc.annotation.resolver.SessionAttributeArgumentResolver.java

protected Object getValue(NativeWebRequest webRequest, String attributeName) {
    Object attribute = webRequest.getAttribute(attributeName, WebRequest.SCOPE_SESSION);
    return attribute;
}

From source file:org.test.skeleton.core.security.CsrfTokenArgumentResolver.java

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    return webRequest.getAttribute(CsrfToken.class.getName(), WebRequest.SCOPE_REQUEST);
}

From source file:org.impalaframework.extension.mvc.annotation.resolver.FlashAttributeArgumentResolver.java

protected Object getValue(NativeWebRequest webRequest, String attributeName) {
    Object attribute = webRequest.getAttribute(attributeName, WebRequest.SCOPE_SESSION);

    if (attribute != null && isArgumentPending(webRequest)) {
        webRequest.removeAttribute(attributeName, WebRequest.SCOPE_SESSION);
    }//from  w w w. j  ava 2  s  .c om

    return attribute;
}

From source file:com.netease.channel.filter.RequestAttributeArgumentResolver.java

protected Object getValue(NativeWebRequest webRequest, String attributeName) {
    Object attribute = webRequest.getAttribute(attributeName, WebRequest.SCOPE_REQUEST);
    return attribute;
}

From source file:org.kmnet.com.fw.web.token.transaction.TransactionTokenContextHandlerMethodArgumentResolver.java

/**
 * resolve {@link TransactionTokenContext} object
 * @see org.springframework.web.method.support.HandlerMethodArgumentResolver#resolveArgument(org.springframework.core.MethodParameter,
 *      org.springframework.web.method.support.ModelAndViewContainer,
 *      org.springframework.web.context.request.NativeWebRequest, org.springframework.web.bind.support.WebDataBinderFactory)
 *///from  w  ww .j a v a  2s. c  om
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {

    return webRequest.getAttribute(TransactionTokenInterceptor.TOKEN_CONTEXT_REQUEST_ATTRIBUTE_NAME,
            RequestAttributes.SCOPE_REQUEST);
}

From source file:org.ngrinder.infra.spring.RemainedPathResolverTest.java

@Test
public void testResolveArgument() throws Exception {

    MethodParameter mock2 = mock(MethodParameter.class);
    RequestMapping requestMapping = mock(RequestMapping.class);
    when(mock2.getMethodAnnotation(RequestMapping.class)).thenReturn(requestMapping);
    when(requestMapping.value()).thenReturn(new String[] { "/list/**" });
    final RequestMapping requestMappingOnType = mock(RequestMapping.class);
    when(requestMappingOnType.value()).thenReturn(new String[] { "/script" });
    RemainedPathMethodArgumentResolver resolver = new RemainedPathMethodArgumentResolver() {
        @Override/*from ww w.  j a v a 2s.  c  o  m*/
        protected RequestMapping getDeclaringClassRequestMapping(MethodParameter parameter) {
            return requestMappingOnType;
        }
    };
    NativeWebRequest nativeWebRequestMock = mock(NativeWebRequest.class);
    when(nativeWebRequestMock.getAttribute(anyString(), anyInt())).thenReturn("/list/script/hello/world");
    assertThat((String) resolver.resolveArgument(mock2, null, nativeWebRequestMock, null), is("hello/world"));

}

From source file:com.linecorp.bot.spring.boot.support.LineBotServerArgumentProcessor.java

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    return webRequest.getAttribute(PROPERTY_NAME, RequestAttributes.SCOPE_REQUEST);
}