Search in sources :

Example 1 with SyncInvocableHandlerMethod

use of org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod in project spring-framework by spring-projects.

the class RequestMappingHandlerAdapter method createBinderMethod.

private SyncInvocableHandlerMethod createBinderMethod(Object bean, Method method) {
    SyncInvocableHandlerMethod invocable = new SyncInvocableHandlerMethod(bean, method);
    invocable.setArgumentResolvers(getInitBinderArgumentResolvers());
    return invocable;
}
Also used : SyncInvocableHandlerMethod(org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod)

Example 2 with SyncInvocableHandlerMethod

use of org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod in project spring-framework by spring-projects.

the class ModelInitializerTests method basic.

@SuppressWarnings("unchecked")
@Test
public void basic() throws Exception {
    TestController controller = new TestController();
    Validator validator = mock(Validator.class);
    controller.setValidator(validator);
    List<SyncInvocableHandlerMethod> binderMethods = getBinderMethods(controller);
    List<InvocableHandlerMethod> attributeMethods = getAttributeMethods(controller);
    WebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
    BindingContext bindingContext = new InitBinderBindingContext(bindingInitializer, binderMethods);
    this.modelInitializer.initModel(bindingContext, attributeMethods, this.exchange).block(Duration.ofMillis(5000));
    WebExchangeDataBinder binder = bindingContext.createDataBinder(this.exchange, "name");
    assertEquals(Collections.singletonList(validator), binder.getValidators());
    Map<String, Object> model = bindingContext.getModel().asMap();
    assertEquals(5, model.size());
    Object value = model.get("bean");
    assertEquals("Bean", ((TestBean) value).getName());
    value = model.get("monoBean");
    assertEquals("Mono Bean", ((Mono<TestBean>) value).block(Duration.ofMillis(5000)).getName());
    value = model.get("singleBean");
    assertEquals("Single Bean", ((Single<TestBean>) value).toBlocking().value().getName());
    value = model.get("voidMethodBean");
    assertEquals("Void Method Bean", ((TestBean) value).getName());
    value = model.get("voidMonoMethodBean");
    assertEquals("Void Mono Method Bean", ((TestBean) value).getName());
}
Also used : InvocableHandlerMethod(org.springframework.web.reactive.result.method.InvocableHandlerMethod) SyncInvocableHandlerMethod(org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod) Mono(reactor.core.publisher.Mono) SyncInvocableHandlerMethod(org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod) BindingContext(org.springframework.web.reactive.BindingContext) WebExchangeDataBinder(org.springframework.web.bind.support.WebExchangeDataBinder) ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) Validator(org.springframework.validation.Validator) WebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer) ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) Test(org.junit.Test)

Example 3 with SyncInvocableHandlerMethod

use of org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod 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)

Aggregations

SyncInvocableHandlerMethod (org.springframework.web.reactive.result.method.SyncInvocableHandlerMethod)3 Method (java.lang.reflect.Method)1 Test (org.junit.Test)1 LocalVariableTableParameterNameDiscoverer (org.springframework.core.LocalVariableTableParameterNameDiscoverer)1 Validator (org.springframework.validation.Validator)1 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)1 WebBindingInitializer (org.springframework.web.bind.support.WebBindingInitializer)1 WebExchangeDataBinder (org.springframework.web.bind.support.WebExchangeDataBinder)1 BindingContext (org.springframework.web.reactive.BindingContext)1 InvocableHandlerMethod (org.springframework.web.reactive.result.method.InvocableHandlerMethod)1 Mono (reactor.core.publisher.Mono)1