use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class ViewResolutionResultHandler method addBindingResult.
private void addBindingResult(BindingContext context, ServerWebExchange exchange) {
Map<String, Object> model = context.getModel().asMap();
model.keySet().stream().filter(name -> isBindingCandidate(name, model.get(name))).filter(name -> !model.containsKey(BindingResult.MODEL_KEY_PREFIX + name)).forEach(name -> {
WebExchangeDataBinder binder = context.createDataBinder(exchange, model.get(name), name);
model.put(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());
});
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class PathExtensionContentTypeResolverTests method resolveMediaTypesFromMapping.
@Test
public void resolveMediaTypesFromMapping() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/test.html").toExchange();
PathExtensionContentTypeResolver resolver = new PathExtensionContentTypeResolver();
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.singletonList(new MediaType("text", "html")), mediaTypes);
Map<String, MediaType> mapping = Collections.singletonMap("HTML", MediaType.APPLICATION_XHTML_XML);
resolver = new PathExtensionContentTypeResolver(mapping);
mediaTypes = resolver.resolveMediaTypes(exchange);
assertEquals(Collections.singletonList(new MediaType("application", "xhtml+xml")), mediaTypes);
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class CompositeContentTypeResolverBuilderTests method setDefaultContentType.
// SPR-10513
@Test
public void setDefaultContentType() throws Exception {
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().defaultContentType(MediaType.APPLICATION_JSON).build();
ServerWebExchange exchange = MockServerHttpRequest.get("/").accept(MediaType.ALL).toExchange();
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class CompositeContentTypeResolverBuilderTests method setDefaultContentTypeWithStrategy.
// SPR-12286
@Test
public void setDefaultContentTypeWithStrategy() throws Exception {
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().defaultContentTypeResolver(new FixedContentTypeResolver(MediaType.APPLICATION_JSON)).build();
List<MediaType> expected = Collections.singletonList(MediaType.APPLICATION_JSON);
ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
assertEquals(expected, resolver.resolveMediaTypes(exchange));
exchange = MockServerHttpRequest.get("/").accept(MediaType.ALL).toExchange();
assertEquals(expected, resolver.resolveMediaTypes(exchange));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class CompositeContentTypeResolverBuilderTests method favorParameter.
@Test
public void favorParameter() throws Exception {
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().favorParameter(true).mediaType("json", MediaType.APPLICATION_JSON).build();
ServerWebExchange exchange = MockServerHttpRequest.get("/flower?format=json").toExchange();
assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange));
}
Aggregations