Search in sources :

Example 1 with ParameterResolvingRegistry

use of cn.taketoday.web.bind.resolver.ParameterResolvingRegistry in project today-infrastructure by TAKETODAY.

the class AnnotationHandlerFactory method initDefaults.

public void initDefaults() {
    ParameterResolvingRegistry registry = beanFactory.getBean(ParameterResolvingRegistry.class);
    Assert.state(registry != null, "No ParameterResolvingRegistry");
    setReturnValueHandlerManager(beanFactory.getBean(ReturnValueHandlerManager.class));
    setParameterFactory(new ParameterResolvingRegistryResolvableParameterFactory(registry));
}
Also used : ReturnValueHandlerManager(cn.taketoday.web.handler.ReturnValueHandlerManager) ParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry)

Example 2 with ParameterResolvingRegistry

use of cn.taketoday.web.bind.resolver.ParameterResolvingRegistry in project today-infrastructure by TAKETODAY.

the class RequestMappingHandlerAdapter method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    // Do this first, it may add ResponseBody advice beans
    initControllerAdviceCache();
    if (resolvingRegistry == null) {
        this.resolvingRegistry = new ParameterResolvingRegistry();
        resolvingRegistry.setApplicationContext(getApplicationContext());
        resolvingRegistry.registerDefaultStrategies();
    }
    // prepare returnValueHandlerManager
    setReturnValueHandlerManager(returnValueHandlerManager);
}
Also used : ParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry)

Example 3 with ParameterResolvingRegistry

use of cn.taketoday.web.bind.resolver.ParameterResolvingRegistry in project today-framework by TAKETODAY.

the class HandlerMethodTests method testSimple.

@Test
public void testSimple() throws Throwable {
    final Method method = HandlerMethodTests.class.getDeclaredMethod("method", String.class);
    final HandlerMethod handlerMethod = HandlerMethod.from(method);
    DefaultParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
    handlerMethod.initParameterNameDiscovery(parameterNameDiscoverer);
    assertThat(handlerMethod.getMethod()).isEqualTo(method);
    assertThat(handlerMethod.getParameters()).hasSize(1);
    assertThat(handlerMethod.getReturnType()).isEqualTo(method.getReturnType()).isEqualTo(void.class);
    assertThat(handlerMethod.getContentType()).isNull();
    // produce
    final Method produce = HandlerMethodTests.class.getDeclaredMethod("produce", String.class);
    final HandlerMethod produceMethod = HandlerMethod.from(produce);
    assertThat(produceMethod.getContentType()).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
    produceMethod.initParameterNameDiscovery(parameterNameDiscoverer);
    ApplicationContext applicationContext = getApplicationContext();
    final ParameterResolvingRegistryResolvableParameterFactory methodParameterBuilder = new ParameterResolvingRegistryResolvableParameterFactory();
    final ParameterResolvingRegistry resolversRegistry = methodParameterBuilder.getResolvingRegistry();
    resolversRegistry.setApplicationContext(applicationContext);
    resolversRegistry.registerDefaultStrategies();
    setResultHandlers(produceMethod, applicationContext);
    assertThat(produceMethod).isNotEqualTo(handlerMethod);
    assertThat(produceMethod).hasToString("HandlerMethodTests#produce(String name)");
}
Also used : AnnotationConfigServletWebApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) DefaultParameterNameDiscoverer(cn.taketoday.core.DefaultParameterNameDiscoverer) Method(java.lang.reflect.Method) ParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry) Test(org.junit.jupiter.api.Test)

Example 4 with ParameterResolvingRegistry

use of cn.taketoday.web.bind.resolver.ParameterResolvingRegistry in project today-framework by TAKETODAY.

the class ParameterResolvingRegistryTests method parameterResolvingRegistry.

@Test
void parameterResolvingRegistry() {
    assertThat(registry.getMessageConverters()).hasSize(3);
    ParameterResolvingRegistry registry1 = new ParameterResolvingRegistry(registry.getMessageConverters());
    assertThat(registry1.getMessageConverters()).isNotEmpty().hasSize(3);
    assertThat(registry1).isNotEqualTo(registry);
    registry.setMessageConverters(List.of(new StringHttpMessageConverter(StandardCharsets.US_ASCII)));
    assertThat(registry.getMessageConverters()).isNotEmpty().hasSize(1);
    assertThat(registry.toString()).isNotEmpty();
    registry.hashCode();
}
Also used : ParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) Test(org.junit.jupiter.api.Test)

Example 5 with ParameterResolvingRegistry

use of cn.taketoday.web.bind.resolver.ParameterResolvingRegistry in project today-framework by TAKETODAY.

the class ValidationParameterResolver method obtainResolvers.

private ParameterResolvingRegistry obtainResolvers() {
    final ParameterResolvingRegistry ret = getResolvingRegistry();
    Assert.state(ret != null, "No ParameterResolvingRegistry.");
    return ret;
}
Also used : ParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry)

Aggregations

ParameterResolvingRegistry (cn.taketoday.web.bind.resolver.ParameterResolvingRegistry)10 ModelMethodProcessor (cn.taketoday.web.bind.resolver.ModelMethodProcessor)2 ReturnValueHandlerManager (cn.taketoday.web.handler.ReturnValueHandlerManager)2 Method (java.lang.reflect.Method)2 Test (org.junit.jupiter.api.Test)2 ApplicationContext (cn.taketoday.context.ApplicationContext)1 DefaultParameterNameDiscoverer (cn.taketoday.core.DefaultParameterNameDiscoverer)1 AnnotationConfigServletWebApplicationContext (cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext)1 StringHttpMessageConverter (cn.taketoday.http.converter.StringHttpMessageConverter)1 BindingContext (cn.taketoday.web.BindingContext)1 WebApplicationContext (cn.taketoday.web.WebApplicationContext)1 MultipartConfiguration (cn.taketoday.web.multipart.MultipartConfiguration)1 ArrayList (java.util.ArrayList)1