Browse Source

Revise order of method declarations in WebFluxConfigurer

See gh-30678
pull/28374/merge
rstoyanchev 1 year ago
parent
commit
3c9cfa8a0f
  1. 51
      spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java
  2. 116
      spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurer.java
  3. 50
      spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurerComposite.java

51
spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java

@ -53,56 +53,55 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport @@ -53,56 +53,55 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport
@Override
protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
this.configurers.configureContentTypeResolver(builder);
protected void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
this.configurers.configureHttpMessageCodecs(configurer);
}
@Override
protected void addCorsMappings(CorsRegistry registry) {
this.configurers.addCorsMappings(registry);
protected void addFormatters(FormatterRegistry registry) {
this.configurers.addFormatters(registry);
}
@Override
public void configurePathMatching(PathMatchConfigurer configurer) {
this.configurers.configurePathMatching(configurer);
protected Validator getValidator() {
Validator validator = this.configurers.getValidator();
return (validator != null ? validator : super.getValidator());
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
this.configurers.addResourceHandlers(registry);
protected MessageCodesResolver getMessageCodesResolver() {
MessageCodesResolver messageCodesResolver = this.configurers.getMessageCodesResolver();
return (messageCodesResolver != null ? messageCodesResolver : super.getMessageCodesResolver());
}
@Override
protected void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
this.configurers.configureArgumentResolvers(configurer);
protected void addCorsMappings(CorsRegistry registry) {
this.configurers.addCorsMappings(registry);
}
@Override
protected void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
this.configurers.configureHttpMessageCodecs(configurer);
protected void configureBlockingExecution(BlockingExecutionConfigurer configurer) {
this.configurers.configureBlockingExecution(configurer);
}
@Override
protected void addFormatters(FormatterRegistry registry) {
this.configurers.addFormatters(registry);
protected void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
this.configurers.configureContentTypeResolver(builder);
}
@Override
protected Validator getValidator() {
Validator validator = this.configurers.getValidator();
return (validator != null ? validator : super.getValidator());
public void configurePathMatching(PathMatchConfigurer configurer) {
this.configurers.configurePathMatching(configurer);
}
@Override
protected MessageCodesResolver getMessageCodesResolver() {
MessageCodesResolver messageCodesResolver = this.configurers.getMessageCodesResolver();
return (messageCodesResolver != null ? messageCodesResolver : super.getMessageCodesResolver());
protected void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
this.configurers.configureArgumentResolvers(configurer);
}
@Override
protected WebSocketService getWebSocketService() {
WebSocketService service = this.configurers.getWebSocketService();
return (service != null ? service : super.getWebSocketService());
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
this.configurers.addResourceHandlers(registry);
}
@Override
@ -111,7 +110,9 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport @@ -111,7 +110,9 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport
}
@Override
protected void configureBlockingExecution(BlockingExecutionConfigurer configurer) {
this.configurers.configureBlockingExecution(configurer);
protected WebSocketService getWebSocketService() {
WebSocketService service = this.configurers.getWebSocketService();
return (service != null ? service : super.getWebSocketService());
}
}

116
spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurer.java

@ -45,53 +45,6 @@ import org.springframework.web.reactive.socket.server.WebSocketService; @@ -45,53 +45,6 @@ import org.springframework.web.reactive.socket.server.WebSocketService;
*/
public interface WebFluxConfigurer {
/**
* 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) {
}
/**
* Configure "global" cross-origin request processing. The configured CORS
* mappings apply to annotated controllers, functional endpoints, and static
* resources.
* <p>Annotated controllers can further declare more fine-grained config via
* {@link org.springframework.web.bind.annotation.CrossOrigin @CrossOrigin}.
* In such cases "global" CORS configuration declared here is
* {@link org.springframework.web.cors.CorsConfiguration#combine(CorsConfiguration) combined}
* with local CORS configuration defined on a controller method.
* @see CorsRegistry
* @see CorsConfiguration#combine(CorsConfiguration)
*/
default void addCorsMappings(CorsRegistry registry) {
}
/**
* Configure path matching options.
* <p>The configured path matching options will be used for mapping to
* annotated controllers and also
* {@link #addResourceHandlers(ResourceHandlerRegistry) static resources}.
* @param configurer the {@link PathMatchConfigurer} instance
*/
default void configurePathMatching(PathMatchConfigurer configurer) {
}
/**
* Add resource handlers for serving static resources.
* @see ResourceHandlerRegistry
*/
default void addResourceHandlers(ResourceHandlerRegistry registry) {
}
/**
* Configure resolvers for custom {@code @RequestMapping} method arguments.
* @param configurer to configurer to use
*/
default void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
}
/**
* Configure the HTTP message readers and writers for reading from the
* request body and for writing to the response body in annotated controllers
@ -134,15 +87,50 @@ public interface WebFluxConfigurer { @@ -134,15 +87,50 @@ public interface WebFluxConfigurer {
}
/**
* Provide the {@link WebSocketService} to create
* {@link org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter}
* with. This can be used to configure server-specific properties through the
* {@link org.springframework.web.reactive.socket.server.RequestUpgradeStrategy}.
* @since 5.3
* Configure "global" cross-origin request processing. The configured CORS
* mappings apply to annotated controllers, functional endpoints, and static
* resources.
* <p>Annotated controllers can further declare more fine-grained config via
* {@link org.springframework.web.bind.annotation.CrossOrigin @CrossOrigin}.
* In such cases "global" CORS configuration declared here is
* {@link org.springframework.web.cors.CorsConfiguration#combine(CorsConfiguration) combined}
* with local CORS configuration defined on a controller method.
* @see CorsRegistry
* @see CorsConfiguration#combine(CorsConfiguration)
*/
@Nullable
default WebSocketService getWebSocketService() {
return null;
default void addCorsMappings(CorsRegistry registry) {
}
/**
* Configure settings related to blocking execution in WebFlux.
* @since 6.1
*/
default void configureBlockingExecution(BlockingExecutionConfigurer configurer) {
}
/**
* 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) {
}
/**
* Configure path matching options.
* <p>The configured path matching options will be used for mapping to
* annotated controllers and also
* {@link #addResourceHandlers(ResourceHandlerRegistry) static resources}.
* @param configurer the {@link PathMatchConfigurer} instance
*/
default void configurePathMatching(PathMatchConfigurer configurer) {
}
/**
* Configure resolvers for custom {@code @RequestMapping} method arguments.
* @param configurer to configurer to use
*/
default void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
}
/**
@ -156,10 +144,22 @@ public interface WebFluxConfigurer { @@ -156,10 +144,22 @@ public interface WebFluxConfigurer {
}
/**
* Configure settings related to blocking execution in WebFlux.
* @since 6.1
* Add resource handlers for serving static resources.
* @see ResourceHandlerRegistry
*/
default void configureBlockingExecution(BlockingExecutionConfigurer configurer) {
default void addResourceHandlers(ResourceHandlerRegistry registry) {
}
/**
* Provide the {@link WebSocketService} to create
* {@link org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter}
* with. This can be used to configure server-specific properties through the
* {@link org.springframework.web.reactive.socket.server.RequestUpgradeStrategy}.
* @since 5.3
*/
@Nullable
default WebSocketService getWebSocketService() {
return null;
}
}

50
spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurerComposite.java

@ -51,64 +51,64 @@ public class WebFluxConfigurerComposite implements WebFluxConfigurer { @@ -51,64 +51,64 @@ public class WebFluxConfigurerComposite implements WebFluxConfigurer {
@Override
public void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
this.delegates.forEach(delegate -> delegate.configureContentTypeResolver(builder));
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
this.delegates.forEach(delegate -> delegate.configureHttpMessageCodecs(configurer));
}
@Override
public void addCorsMappings(CorsRegistry registry) {
this.delegates.forEach(delegate -> delegate.addCorsMappings(registry));
public void addFormatters(FormatterRegistry registry) {
this.delegates.forEach(delegate -> delegate.addFormatters(registry));
}
@Override
public void configurePathMatching(PathMatchConfigurer configurer) {
this.delegates.forEach(delegate -> delegate.configurePathMatching(configurer));
public Validator getValidator() {
return createSingleBean(WebFluxConfigurer::getValidator, Validator.class);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
this.delegates.forEach(delegate -> delegate.addResourceHandlers(registry));
public MessageCodesResolver getMessageCodesResolver() {
return createSingleBean(WebFluxConfigurer::getMessageCodesResolver, MessageCodesResolver.class);
}
@Nullable
@Override
public WebSocketService getWebSocketService() {
return createSingleBean(WebFluxConfigurer::getWebSocketService, WebSocketService.class);
public void addCorsMappings(CorsRegistry registry) {
this.delegates.forEach(delegate -> delegate.addCorsMappings(registry));
}
@Override
public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
this.delegates.forEach(delegate -> delegate.configureArgumentResolvers(configurer));
public void configureBlockingExecution(BlockingExecutionConfigurer configurer) {
this.delegates.forEach(delegate -> delegate.configureBlockingExecution(configurer));
}
@Override
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
this.delegates.forEach(delegate -> delegate.configureHttpMessageCodecs(configurer));
public void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
this.delegates.forEach(delegate -> delegate.configureContentTypeResolver(builder));
}
@Override
public void addFormatters(FormatterRegistry registry) {
this.delegates.forEach(delegate -> delegate.addFormatters(registry));
public void configurePathMatching(PathMatchConfigurer configurer) {
this.delegates.forEach(delegate -> delegate.configurePathMatching(configurer));
}
@Override
public Validator getValidator() {
return createSingleBean(WebFluxConfigurer::getValidator, Validator.class);
public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
this.delegates.forEach(delegate -> delegate.configureArgumentResolvers(configurer));
}
@Override
public MessageCodesResolver getMessageCodesResolver() {
return createSingleBean(WebFluxConfigurer::getMessageCodesResolver, MessageCodesResolver.class);
public void configureViewResolvers(ViewResolverRegistry registry) {
this.delegates.forEach(delegate -> delegate.configureViewResolvers(registry));
}
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
this.delegates.forEach(delegate -> delegate.configureViewResolvers(registry));
public void addResourceHandlers(ResourceHandlerRegistry registry) {
this.delegates.forEach(delegate -> delegate.addResourceHandlers(registry));
}
@Nullable
@Override
public void configureBlockingExecution(BlockingExecutionConfigurer configurer) {
this.delegates.forEach(delegate -> delegate.configureBlockingExecution(configurer));
public WebSocketService getWebSocketService() {
return createSingleBean(WebFluxConfigurer::getWebSocketService, WebSocketService.class);
}
@Nullable

Loading…
Cancel
Save