org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder Java Examples

The following examples show how to use org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageWriterResultHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
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) {};
}
 
Example #2
Source File: ResponseEntityResultHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private ResponseEntityResultHandler createHandler(HttpMessageWriter<?>... writers) {
	List<HttpMessageWriter<?>> writerList;
	if (ObjectUtils.isEmpty(writers)) {
		writerList = new ArrayList<>();
		writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
		writerList.add(new ResourceHttpMessageWriter());
		writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
	}
	else {
		writerList = Arrays.asList(writers);
	}
	RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
	return new ResponseEntityResultHandler(writerList, resolver);
}
 
Example #3
Source File: ProducesRequestConditionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test // gh-22853
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);

	assertEquals(1, noneMatch.compareTo(htmlMatch, exchange));
}
 
Example #4
Source File: ResponseEntityResultHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private ResponseEntityResultHandler createHandler(HttpMessageWriter<?>... writers) {
	List<HttpMessageWriter<?>> writerList;
	if (ObjectUtils.isEmpty(writers)) {
		writerList = new ArrayList<>();
		writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
		writerList.add(new ResourceHttpMessageWriter());
		writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
		writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
	}
	else {
		writerList = Arrays.asList(writers);
	}
	RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
	return new ResponseEntityResultHandler(writerList, resolver);
}
 
Example #5
Source File: MessageWriterResultHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
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) {};
}
 
Example #6
Source File: DefaultControllerSpecTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void configurerConsumers() {
	TestConsumer<ArgumentResolverConfigurer> argumentResolverConsumer = new TestConsumer<>();
	TestConsumer<RequestedContentTypeResolverBuilder> contenTypeResolverConsumer = new TestConsumer<>();
	TestConsumer<CorsRegistry> corsRegistryConsumer = new TestConsumer<>();
	TestConsumer<FormatterRegistry> formatterConsumer = new TestConsumer<>();
	TestConsumer<ServerCodecConfigurer> codecsConsumer = new TestConsumer<>();
	TestConsumer<PathMatchConfigurer> pathMatchingConsumer = new TestConsumer<>();
	TestConsumer<ViewResolverRegistry> viewResolverConsumer = new TestConsumer<>();

	new DefaultControllerSpec(new MyController())
			.argumentResolvers(argumentResolverConsumer)
			.contentTypeResolver(contenTypeResolverConsumer)
			.corsMappings(corsRegistryConsumer)
			.formatters(formatterConsumer)
			.httpMessageCodecs(codecsConsumer)
			.pathMatching(pathMatchingConsumer)
			.viewResolvers(viewResolverConsumer)
			.build();

	assertNotNull(argumentResolverConsumer.getValue());
	assertNotNull(contenTypeResolverConsumer.getValue());
	assertNotNull(corsRegistryConsumer.getValue());
	assertNotNull(formatterConsumer.getValue());
	assertNotNull(codecsConsumer.getValue());
	assertNotNull(pathMatchingConsumer.getValue());
	assertNotNull(viewResolverConsumer.getValue());

}
 
Example #7
Source File: ProducesRequestCondition.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Private constructor with already parsed media type expressions.
 */
private ProducesRequestCondition(Collection<ProduceMediaTypeExpression> expressions,
		RequestedContentTypeResolver resolver) {

	this.expressions = new ArrayList<>(expressions);
	Collections.sort(this.expressions);
	this.contentTypeResolver = (resolver != null ? resolver : new RequestedContentTypeResolverBuilder().build());
}
 
Example #8
Source File: DelegatingWebFluxConfigurationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void requestMappingHandlerMapping() throws Exception {
	delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
	delegatingConfig.requestMappingHandlerMapping();

	verify(webFluxConfigurer).configureContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
	verify(webFluxConfigurer).addCorsMappings(any(CorsRegistry.class));
	verify(webFluxConfigurer).configurePathMatching(any(PathMatchConfigurer.class));
}
 
Example #9
Source File: DefaultControllerSpecTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void configurerConsumers() {
	TestConsumer<ArgumentResolverConfigurer> argumentResolverConsumer = new TestConsumer<>();
	TestConsumer<RequestedContentTypeResolverBuilder> contenTypeResolverConsumer = new TestConsumer<>();
	TestConsumer<CorsRegistry> corsRegistryConsumer = new TestConsumer<>();
	TestConsumer<FormatterRegistry> formatterConsumer = new TestConsumer<>();
	TestConsumer<ServerCodecConfigurer> codecsConsumer = new TestConsumer<>();
	TestConsumer<PathMatchConfigurer> pathMatchingConsumer = new TestConsumer<>();
	TestConsumer<ViewResolverRegistry> viewResolverConsumer = new TestConsumer<>();

	new DefaultControllerSpec(new MyController())
			.argumentResolvers(argumentResolverConsumer)
			.contentTypeResolver(contenTypeResolverConsumer)
			.corsMappings(corsRegistryConsumer)
			.formatters(formatterConsumer)
			.httpMessageCodecs(codecsConsumer)
			.pathMatching(pathMatchingConsumer)
			.viewResolvers(viewResolverConsumer)
			.build();

	assertNotNull(argumentResolverConsumer.getValue());
	assertNotNull(contenTypeResolverConsumer.getValue());
	assertNotNull(corsRegistryConsumer.getValue());
	assertNotNull(formatterConsumer.getValue());
	assertNotNull(codecsConsumer.getValue());
	assertNotNull(pathMatchingConsumer.getValue());
	assertNotNull(viewResolverConsumer.getValue());

}
 
Example #10
Source File: DelegatingWebFluxConfigurationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void responseBodyResultHandler() throws Exception {
	delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
	delegatingConfig.responseBodyResultHandler();

	verify(webFluxConfigurer).configureHttpMessageCodecs(codecsConfigurer.capture());
	verify(webFluxConfigurer).configureContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
}
 
Example #11
Source File: ResponseBodyResultHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
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);
}
 
Example #12
Source File: ResponseBodyResultHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
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);
}
 
Example #13
Source File: DelegatingWebFluxConfigurationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void responseBodyResultHandler() throws Exception {
	delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
	delegatingConfig.responseBodyResultHandler(
			delegatingConfig.webFluxAdapterRegistry(),
			delegatingConfig.serverCodecConfigurer(),
			delegatingConfig.webFluxContentTypeResolver());

	verify(webFluxConfigurer).configureHttpMessageCodecs(codecsConfigurer.capture());
	verify(webFluxConfigurer).configureContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
}
 
Example #14
Source File: DelegatingWebFluxConfigurationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void requestMappingHandlerMapping() throws Exception {
	delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer));
	delegatingConfig.requestMappingHandlerMapping(delegatingConfig.webFluxContentTypeResolver());

	verify(webFluxConfigurer).configureContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
	verify(webFluxConfigurer).addCorsMappings(any(CorsRegistry.class));
	verify(webFluxConfigurer).configurePathMatching(any(PathMatchConfigurer.class));
}
 
Example #15
Source File: DefaultControllerSpec.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public DefaultControllerSpec contentTypeResolver(Consumer<RequestedContentTypeResolverBuilder> consumer) {
	this.configurer.contentTypeResolverConsumer = consumer;
	return this;
}
 
Example #16
Source File: DefaultControllerSpec.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
	if (this.contentTypeResolverConsumer != null) {
		this.contentTypeResolverConsumer.accept(builder);
	}
}
 
Example #17
Source File: WebFluxConfigurerComposite.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
	this.delegates.forEach(delegate -> delegate.configureContentTypeResolver(builder));
}
 
Example #18
Source File: DelegatingWebFluxConfiguration.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
	this.configurers.configureContentTypeResolver(builder);
}
 
Example #19
Source File: WebFluxConfigurationSupport.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Bean
public RequestedContentTypeResolver webFluxContentTypeResolver() {
	RequestedContentTypeResolverBuilder builder = new RequestedContentTypeResolverBuilder();
	configureContentTypeResolver(builder);
	return builder.build();
}
 
Example #20
Source File: WebFluxConfigurerComposite.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
	this.delegates.forEach(delegate -> delegate.configureContentTypeResolver(builder));
}
 
Example #21
Source File: DefaultControllerSpec.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
	if (this.contentTypeResolverConsumer != null) {
		this.contentTypeResolverConsumer.accept(builder);
	}
}
 
Example #22
Source File: DefaultControllerSpec.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public DefaultControllerSpec contentTypeResolver(Consumer<RequestedContentTypeResolverBuilder> consumer) {
	this.configurer.contentTypeResolverConsumer = consumer;
	return this;
}
 
Example #23
Source File: DelegatingWebFluxConfiguration.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
	this.configurers.configureContentTypeResolver(builder);
}
 
Example #24
Source File: WebFluxConfigurationSupport.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Bean
public RequestedContentTypeResolver webFluxContentTypeResolver() {
	RequestedContentTypeResolverBuilder builder = new RequestedContentTypeResolverBuilder();
	configureContentTypeResolver(builder);
	return builder.build();
}
 
Example #25
Source File: WebFluxConfigurationSupport.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Override to configure how the requested content type is resolved.
 */
protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
}
 
Example #26
Source File: WebFluxConfigurer.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Configure how the content type requested for the response is resolved
 * when handling requests with annotated controllers.
 * @param builder for configuring the resolvers to use
 */
default void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
}
 
Example #27
Source File: WebTestClient.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Customize content type resolution.
 * @see WebFluxConfigurer#configureContentTypeResolver
 */
ControllerSpec contentTypeResolver(Consumer<RequestedContentTypeResolverBuilder> consumer);
 
Example #28
Source File: WebTestClient.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Customize content type resolution.
 * @see WebFluxConfigurer#configureContentTypeResolver
 */
ControllerSpec contentTypeResolver(Consumer<RequestedContentTypeResolverBuilder> consumer);
 
Example #29
Source File: WebFluxConfigurationSupport.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Override to configure how the requested content type is resolved.
 */
protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
}
 
Example #30
Source File: WebFluxConfigurer.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Configure how the content type requested for the response is resolved
 * when handling requests with annotated controllers.
 * @param builder for configuring the resolvers to use
 */
default void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
}