Search in sources :

Example 1 with LocalVariableTableParameterNameDiscoverer

use of org.springframework.core.LocalVariableTableParameterNameDiscoverer in project spring-framework by spring-projects.

the class InitBinderDataBinderFactoryTests method createFactory.

private WebDataBinderFactory createFactory(String methodName, Class<?>... parameterTypes) throws Exception {
    Object handler = new InitBinderHandler();
    Method method = handler.getClass().getMethod(methodName, parameterTypes);
    InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(handler, method);
    handlerMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
    handlerMethod.setDataBinderFactory(new DefaultDataBinderFactory(null));
    handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
    return new InitBinderDataBinderFactory(Collections.singletonList(handlerMethod), this.bindingInitializer);
}
Also used : LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) Method(java.lang.reflect.Method) DefaultDataBinderFactory(org.springframework.web.bind.support.DefaultDataBinderFactory)

Example 2 with LocalVariableTableParameterNameDiscoverer

use of org.springframework.core.LocalVariableTableParameterNameDiscoverer in project spring-framework by spring-projects.

the class InitBinderBindingContextTests method createBindingContext.

private BindingContext createBindingContext(String methodName, Class<?>... parameterTypes) throws Exception {
    Object handler = new InitBinderHandler();
    Method method = handler.getClass().getMethod(methodName, parameterTypes);
    SyncInvocableHandlerMethod handlerMethod = new SyncInvocableHandlerMethod(handler, method);
    handlerMethod.setArgumentResolvers(new ArrayList<>(this.argumentResolvers));
    handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
    return new InitBinderBindingContext(this.bindingInitializer, Collections.singletonList(handlerMethod));
}
Also used : LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) SyncInvocableHandlerMethod(org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod) SyncInvocableHandlerMethod(org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod) Method(java.lang.reflect.Method)

Example 3 with LocalVariableTableParameterNameDiscoverer

use of org.springframework.core.LocalVariableTableParameterNameDiscoverer in project spring-framework by spring-projects.

the class MatrixVariablesMethodArgumentResolverTests method setup.

@Before
public void setup() throws Exception {
    this.resolver = new MatrixVariableMethodArgumentResolver();
    this.mavContainer = new ModelAndViewContainer();
    this.request = new MockHttpServletRequest();
    this.webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
    Map<String, MultiValueMap<String, String>> params = new LinkedHashMap<>();
    this.request.setAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, params);
    Method method = getClass().getMethod("handle", String.class, List.class, int.class);
    this.paramString = new MethodParameter(method, 0);
    this.paramColors = new MethodParameter(method, 1);
    this.paramColors.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    this.paramYear = new MethodParameter(method, 2);
}
Also used : LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) LinkedHashMap(java.util.LinkedHashMap) Before(org.junit.Before)

Example 4 with LocalVariableTableParameterNameDiscoverer

use of org.springframework.core.LocalVariableTableParameterNameDiscoverer in project spring-framework by spring-projects.

the class ModelFactoryTests method createModelFactory.

private ModelFactory createModelFactory(String methodName, Class<?>... parameterTypes) throws Exception {
    HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
    resolvers.addResolver(new ModelMethodProcessor());
    InvocableHandlerMethod modelMethod = createHandlerMethod(methodName, parameterTypes);
    modelMethod.setHandlerMethodArgumentResolvers(resolvers);
    modelMethod.setDataBinderFactory(null);
    modelMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
    return new ModelFactory(Collections.singletonList(modelMethod), null, this.attributeHandler);
}
Also used : LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethodArgumentResolverComposite(org.springframework.web.method.support.HandlerMethodArgumentResolverComposite)

Example 5 with LocalVariableTableParameterNameDiscoverer

use of org.springframework.core.LocalVariableTableParameterNameDiscoverer in project spring-framework by spring-projects.

the class RequestPartMethodArgumentResolverTests method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    messageConverter = mock(HttpMessageConverter.class);
    given(messageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
    resolver = new RequestPartMethodArgumentResolver(Collections.<HttpMessageConverter<?>>singletonList(messageConverter));
    reset(messageConverter);
    byte[] content = "doesn't matter as long as not empty".getBytes(StandardCharsets.UTF_8);
    multipartFile1 = new MockMultipartFile("requestPart", "", "text/plain", content);
    multipartFile2 = new MockMultipartFile("requestPart", "", "text/plain", content);
    multipartRequest = new MockMultipartHttpServletRequest();
    multipartRequest.addFile(multipartFile1);
    multipartRequest.addFile(multipartFile2);
    multipartRequest.addFile(new MockMultipartFile("otherPart", "", "text/plain", content));
    webRequest = new ServletWebRequest(multipartRequest, new MockHttpServletResponse());
    Method method = ReflectionUtils.findMethod(getClass(), "handle", (Class<?>[]) null);
    paramRequestPart = new SynthesizingMethodParameter(method, 0);
    paramRequestPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    paramNamedRequestPart = new SynthesizingMethodParameter(method, 1);
    paramValidRequestPart = new SynthesizingMethodParameter(method, 2);
    paramMultipartFile = new SynthesizingMethodParameter(method, 3);
    paramMultipartFileList = new SynthesizingMethodParameter(method, 4);
    paramMultipartFileArray = new SynthesizingMethodParameter(method, 5);
    paramInt = new SynthesizingMethodParameter(method, 6);
    paramMultipartFileNotAnnot = new SynthesizingMethodParameter(method, 7);
    paramMultipartFileNotAnnot.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    paramPart = new SynthesizingMethodParameter(method, 8);
    paramPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    paramPartList = new SynthesizingMethodParameter(method, 9);
    paramPartArray = new SynthesizingMethodParameter(method, 10);
    paramRequestParamAnnot = new SynthesizingMethodParameter(method, 11);
    optionalMultipartFile = new SynthesizingMethodParameter(method, 12);
    optionalMultipartFile.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    optionalMultipartFileList = new SynthesizingMethodParameter(method, 13);
    optionalMultipartFileList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    optionalPart = new SynthesizingMethodParameter(method, 14);
    optionalPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    optionalPartList = new SynthesizingMethodParameter(method, 15);
    optionalPartList.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
    optionalRequestPart = new SynthesizingMethodParameter(method, 16);
}
Also used : MockMultipartFile(org.springframework.mock.web.test.MockMultipartFile) LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) MockMultipartHttpServletRequest(org.springframework.mock.web.test.MockMultipartHttpServletRequest) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Method(java.lang.reflect.Method) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Aggregations

LocalVariableTableParameterNameDiscoverer (org.springframework.core.LocalVariableTableParameterNameDiscoverer)9 Method (java.lang.reflect.Method)5 Before (org.junit.Before)3 Test (org.junit.Test)3 MethodParameter (org.springframework.core.MethodParameter)3 Ignore (org.junit.Ignore)2 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)2 DependencyDescriptor (org.springframework.beans.factory.config.DependencyDescriptor)2 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)2 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)2 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)2 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Set (java.util.Set)1 DefaultParameterNameDiscoverer (org.springframework.core.DefaultParameterNameDiscoverer)1 ParameterNameDiscoverer (org.springframework.core.ParameterNameDiscoverer)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1