Search in sources :

Example 6 with SynthesizingMethodParameter

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

the class RequestAttributeMethodArgumentResolverTests method initMethodParameter.

private MethodParameter initMethodParameter(int parameterIndex) {
    MethodParameter param = new SynthesizingMethodParameter(this.handleMethod, parameterIndex);
    param.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
    GenericTypeResolver.resolveParameterType(param, this.resolver.getClass());
    return param;
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) DefaultParameterNameDiscoverer(org.springframework.core.DefaultParameterNameDiscoverer) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter)

Example 7 with SynthesizingMethodParameter

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

the class RequestHeaderMapMethodArgumentResolverTests method setup.

@Before
public void setup() throws Exception {
    resolver = new RequestHeaderMapMethodArgumentResolver(new ReactiveAdapterRegistry());
    Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
    paramMap = new SynthesizingMethodParameter(method, 0);
    paramMultiValueMap = new SynthesizingMethodParameter(method, 1);
    paramHttpHeaders = new SynthesizingMethodParameter(method, 2);
    paramUnsupported = new SynthesizingMethodParameter(method, 3);
    paramUnsupported = new SynthesizingMethodParameter(method, 3);
    paramAlsoUnsupported = new SynthesizingMethodParameter(method, 4);
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) Method(java.lang.reflect.Method) Before(org.junit.Before)

Example 8 with SynthesizingMethodParameter

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

the class RequestHeaderMethodArgumentResolverTests method setup.

@Before
public void setup() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.refresh();
    ReactiveAdapterRegistry adapterRegistry = new ReactiveAdapterRegistry();
    this.resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
    ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
    initializer.setConversionService(new DefaultFormattingConversionService());
    this.bindingContext = new BindingContext(initializer);
    Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
    this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 0);
    this.paramNamedValueStringArray = new SynthesizingMethodParameter(method, 1);
    this.paramSystemProperty = new SynthesizingMethodParameter(method, 2);
    this.paramResolvedNameWithExpression = new SynthesizingMethodParameter(method, 3);
    this.paramResolvedNameWithPlaceholder = new SynthesizingMethodParameter(method, 4);
    this.paramNamedValueMap = new SynthesizingMethodParameter(method, 5);
    this.paramDate = new SynthesizingMethodParameter(method, 6);
    this.paramInstant = new SynthesizingMethodParameter(method, 7);
    this.paramMono = new SynthesizingMethodParameter(method, 8);
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) Method(java.lang.reflect.Method) BindingContext(org.springframework.web.reactive.BindingContext) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) Before(org.junit.Before)

Example 9 with SynthesizingMethodParameter

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

the class MvcUriComponentsBuilder method applyContributors.

private static UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
    CompositeUriComponentsContributor contributor = getConfiguredUriComponentsContributor();
    if (contributor == null) {
        logger.debug("Using default CompositeUriComponentsContributor");
        contributor = defaultUriComponentsContributor;
    }
    int paramCount = method.getParameterCount();
    int argCount = args.length;
    if (paramCount != argCount) {
        throw new IllegalArgumentException("Number of method parameters " + paramCount + " does not match number of argument values " + argCount);
    }
    final Map<String, Object> uriVars = new HashMap<>();
    for (int i = 0; i < paramCount; i++) {
        MethodParameter param = new SynthesizingMethodParameter(method, i);
        param.initParameterNameDiscovery(parameterNameDiscoverer);
        contributor.contributeMethodArgument(param, args[i], builder, uriVars);
    }
    // We may not have all URI var values, expand only what we have
    return builder.build().expand(new UriComponents.UriTemplateVariables() {

        @Override
        public Object getValue(String name) {
            return uriVars.containsKey(name) ? uriVars.get(name) : UriComponents.UriTemplateVariables.SKIP_VALUE;
        }
    });
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) UriComponents(org.springframework.web.util.UriComponents) CompositeUriComponentsContributor(org.springframework.web.method.support.CompositeUriComponentsContributor) HashMap(java.util.HashMap) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter)

Example 10 with SynthesizingMethodParameter

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

the class ServletCookieValueMethodArgumentResolverTests method setup.

@Before
public void setup() throws Exception {
    resolver = new ServletCookieValueMethodArgumentResolver(null);
    request = new MockHttpServletRequest();
    webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
    Method method = getClass().getMethod("params", Cookie.class, String.class);
    cookieParameter = new SynthesizingMethodParameter(method, 0);
    cookieStringParameter = new SynthesizingMethodParameter(method, 1);
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) Method(java.lang.reflect.Method) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Aggregations

SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)22 Method (java.lang.reflect.Method)17 Before (org.junit.Before)15 MethodParameter (org.springframework.core.MethodParameter)8 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)8 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)7 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)7 DefaultParameterNameDiscoverer (org.springframework.core.DefaultParameterNameDiscoverer)4 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)4 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)3 Test (org.junit.Test)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 LocalVariableTableParameterNameDiscoverer (org.springframework.core.LocalVariableTableParameterNameDiscoverer)2 Message (org.springframework.messaging.Message)2 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)2 BindingContext (org.springframework.web.reactive.BindingContext)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 DependencyDescriptor (org.springframework.beans.factory.config.DependencyDescriptor)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1