use of org.springframework.web.reactive.accept.RequestedContentTypeResolver in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method resultHandler.
private ViewResolutionResultHandler resultHandler(List<View> defaultViews, ViewResolver... resolvers) {
List<ViewResolver> resolverList = Arrays.asList(resolvers);
RequestedContentTypeResolver contentTypeResolver = new HeaderContentTypeResolver();
ViewResolutionResultHandler handler = new ViewResolutionResultHandler(resolverList, contentTypeResolver);
handler.setDefaultViews(defaultViews);
return handler;
}
use of org.springframework.web.reactive.accept.RequestedContentTypeResolver in project spring-framework by spring-projects.
the class ProducesRequestConditionTests method matchAndCompare.
// gh-22853
@Test
public void matchAndCompare() {
RequestedContentTypeResolverBuilder builder = new RequestedContentTypeResolverBuilder();
builder.headerResolver();
builder.fixedResolver(MediaType.TEXT_HTML);
RequestedContentTypeResolver resolver = builder.build();
ProducesRequestCondition none = new ProducesRequestCondition(new String[0], null, resolver);
ProducesRequestCondition html = new ProducesRequestCondition(new String[] { "text/html" }, null, resolver);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "*/*"));
ProducesRequestCondition noneMatch = none.getMatchingCondition(exchange);
ProducesRequestCondition htmlMatch = html.getMatchingCondition(exchange);
assertThat(noneMatch.compareTo(htmlMatch, exchange)).isEqualTo(1);
}
use of org.springframework.web.reactive.accept.RequestedContentTypeResolver in project spring-framework by spring-projects.
the class MessageWriterResultHandlerTests method initResultHandler.
private AbstractMessageWriterResultHandler initResultHandler(HttpMessageWriter<?>... writers) {
List<HttpMessageWriter<?>> writerList;
if (ObjectUtils.isEmpty(writers)) {
writerList = new ArrayList<>();
writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
writerList.add(new ResourceHttpMessageWriter());
writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
} else {
writerList = Arrays.asList(writers);
}
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
return new AbstractMessageWriterResultHandler(writerList, resolver) {
};
}
use of org.springframework.web.reactive.accept.RequestedContentTypeResolver in project spring-framework by spring-projects.
the class ResponseBodyResultHandlerTests method setup.
@BeforeEach
public void setup() throws Exception {
List<HttpMessageWriter<?>> writerList = new ArrayList<>(5);
writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
writerList.add(new ResourceHttpMessageWriter());
writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
this.resultHandler = new ResponseBodyResultHandler(writerList, resolver);
}
use of org.springframework.web.reactive.accept.RequestedContentTypeResolver in project spring-framework by spring-projects.
the class WebFluxConfigurationSupportTests method requestMappingHandlerMapping.
@Test
public void requestMappingHandlerMapping() {
ApplicationContext context = loadConfig(WebFluxConfig.class);
final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
ReflectionUtils.makeAccessible(field);
String name = "requestMappingHandlerMapping";
RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
assertThat(mapping).isNotNull();
assertThat(mapping.getOrder()).isEqualTo(0);
PathPatternParser patternParser = mapping.getPathPatternParser();
assertThat(patternParser).isNotNull();
boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
assertThat(matchOptionalTrailingSlash).isTrue();
name = "webFluxContentTypeResolver";
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
assertThat(mapping.getContentTypeResolver()).isSameAs(resolver);
ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON));
assertThat(resolver.resolveMediaTypes(exchange)).isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
}
Aggregations