use of org.springframework.web.bind.support.ConfigurableWebBindingInitializer in project spring-framework by spring-projects.
the class RequestAttributeMethodArgumentResolverTests method resolveOptional.
@Test
public void resolveOptional() throws Exception {
MethodParameter param = initMethodParameter(3);
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
assertNotNull(mono.block());
assertEquals(Optional.class, mono.block().getClass());
assertFalse(((Optional<?>) mono.block()).isPresent());
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultFormattingConversionService());
BindingContext bindingContext = new BindingContext(initializer);
Foo foo = new Foo();
this.exchange.getAttributes().put("foo", foo);
mono = this.resolver.resolveArgument(param, bindingContext, this.exchange);
assertNotNull(mono.block());
assertEquals(Optional.class, mono.block().getClass());
Optional<?> optional = (Optional<?>) mono.block();
assertTrue(optional.isPresent());
assertSame(foo, optional.get());
}
use of org.springframework.web.bind.support.ConfigurableWebBindingInitializer 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);
}
use of org.springframework.web.bind.support.ConfigurableWebBindingInitializer in project spring-data-document-examples by spring-projects.
the class HandlerAdapterConfiguration method annotationMethodHandlerAdapter.
@Bean
public AnnotationMethodHandlerAdapter annotationMethodHandlerAdapter() {
AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter();
ActionInterceptor[] interceptors = new ActionInterceptor[] { datastoreInterceptor };
//adapter.setActionInterceptors(interceptors);
ConfigurableWebBindingInitializer wbi = new ConfigurableWebBindingInitializer();
wbi.setValidator(getValidator());
wbi.setConversionService(conversionService());
adapter.setWebBindingInitializer(wbi);
adapter.setMessageConverters(getMessageConverters());
adapter.setOrder(-1);
return adapter;
}
use of org.springframework.web.bind.support.ConfigurableWebBindingInitializer in project spring-framework by spring-projects.
the class RequestHeaderMethodArgumentResolverTests method instantConversion.
@Test
public void instantConversion() throws Exception {
String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
servletRequest.addHeader("name", rfc1123val);
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
bindingInitializer.setConversionService(new DefaultFormattingConversionService());
Object result = resolver.resolveArgument(paramInstant, null, webRequest, new DefaultDataBinderFactory(bindingInitializer));
assertTrue(result instanceof Instant);
assertEquals(Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(rfc1123val)), result);
}
use of org.springframework.web.bind.support.ConfigurableWebBindingInitializer in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method optionalMultipartFileWithoutMultipartRequest.
@Test
public void optionalMultipartFileWithoutMultipartRequest() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
Object actual = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertEquals(Optional.empty(), actual);
}
Aggregations