Skip to content

Commit 2b2bf27

Browse files
committed
Polishing
1 parent 3881a4a commit 2b2bf27

File tree

3 files changed

+77
-90
lines changed

3 files changed

+77
-90
lines changed

spring-web/src/test/java/org/springframework/http/codec/support/CodecConfigurerTests.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -256,19 +256,6 @@ public void jackson2DecoderOverride() {
256256
.filter(e -> e == decoder).orElse(null));
257257
}
258258

259-
@Test
260-
public void protobufDecoderOverride() {
261-
ProtobufDecoder decoder = new ProtobufDecoder(ExtensionRegistry.newInstance());
262-
this.configurer.defaultCodecs().protobufDecoder(decoder);
263-
264-
assertSame(decoder, this.configurer.getReaders().stream()
265-
.filter(writer -> writer instanceof DecoderHttpMessageReader)
266-
.map(writer -> ((DecoderHttpMessageReader<?>) writer).getDecoder())
267-
.filter(e -> ProtobufDecoder.class.equals(e.getClass()))
268-
.findFirst()
269-
.filter(e -> e == decoder).orElse(null));
270-
}
271-
272259
@Test
273260
public void jackson2EncoderOverride() {
274261
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
@@ -283,7 +270,20 @@ public void jackson2EncoderOverride() {
283270
}
284271

285272
@Test
286-
public void protobufWriterOverride() {
273+
public void protobufDecoderOverride() {
274+
ProtobufDecoder decoder = new ProtobufDecoder(ExtensionRegistry.newInstance());
275+
this.configurer.defaultCodecs().protobufDecoder(decoder);
276+
277+
assertSame(decoder, this.configurer.getReaders().stream()
278+
.filter(writer -> writer instanceof DecoderHttpMessageReader)
279+
.map(writer -> ((DecoderHttpMessageReader<?>) writer).getDecoder())
280+
.filter(e -> ProtobufDecoder.class.equals(e.getClass()))
281+
.findFirst()
282+
.filter(e -> e == decoder).orElse(null));
283+
}
284+
285+
@Test
286+
public void protobufEncoderOverride() {
287287
ProtobufEncoder encoder = new ProtobufEncoder();
288288
this.configurer.defaultCodecs().protobufEncoder(encoder);
289289

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,14 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping() {
126126
mapping.setCorsConfigurations(getCorsConfigurations());
127127

128128
PathMatchConfigurer configurer = getPathMatchConfigurer();
129-
130129
Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
131130
if (useTrailingSlashMatch != null) {
132131
mapping.setUseTrailingSlashMatch(useTrailingSlashMatch);
133132
}
134-
135133
Boolean useCaseSensitiveMatch = configurer.isUseCaseSensitiveMatch();
136134
if (useCaseSensitiveMatch != null) {
137135
mapping.setUseCaseSensitiveMatch(useCaseSensitiveMatch);
138136
}
139-
140137
Map<String, Predicate<Class<?>>> pathPrefixes = configurer.getPathPrefixes();
141138
if (pathPrefixes != null) {
142139
mapping.setPathPrefixes(pathPrefixes);
@@ -331,6 +328,10 @@ protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer
331328
return initializer;
332329
}
333330

331+
/**
332+
* Return a {@link FormattingConversionService} for use with annotated controllers.
333+
* <p>See {@link #addFormatters} as an alternative to overriding this method.
334+
*/
334335
@Bean
335336
public FormattingConversionService webFluxConversionService() {
336337
FormattingConversionService service = new DefaultFormattingConversionService();
@@ -339,7 +340,9 @@ public FormattingConversionService webFluxConversionService() {
339340
}
340341

341342
/**
342-
* Override to add custom {@link Converter}s and {@link Formatter Formatter}s.
343+
* Override this method to add custom {@link Converter} and/or {@link Formatter}
344+
* delegates to the common {@link FormattingConversionService}.
345+
* @see #webFluxConversionService()
343346
*/
344347
protected void addFormatters(FormatterRegistry registry) {
345348
}

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java

Lines changed: 56 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,10 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping() {
284284
if (useSuffixPatternMatch != null) {
285285
mapping.setUseSuffixPatternMatch(useSuffixPatternMatch);
286286
}
287-
288287
Boolean useRegisteredSuffixPatternMatch = configurer.isUseRegisteredSuffixPatternMatch();
289288
if (useRegisteredSuffixPatternMatch != null) {
290289
mapping.setUseRegisteredSuffixPatternMatch(useRegisteredSuffixPatternMatch);
291290
}
292-
293291
Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
294292
if (useTrailingSlashMatch != null) {
295293
mapping.setUseTrailingSlashMatch(useTrailingSlashMatch);
@@ -299,12 +297,10 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping() {
299297
if (pathHelper != null) {
300298
mapping.setUrlPathHelper(pathHelper);
301299
}
302-
303300
PathMatcher pathMatcher = configurer.getPathMatcher();
304301
if (pathMatcher != null) {
305302
mapping.setPathMatcher(pathMatcher);
306303
}
307-
308304
Map<String, Predicate<Class<?>>> pathPrefixes = configurer.getPathPrefixes();
309305
if (pathPrefixes != null) {
310306
mapping.setPathPrefixes(pathPrefixes);
@@ -324,8 +320,8 @@ protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
324320

325321
/**
326322
* Provide access to the shared handler interceptors used to configure
327-
* {@link HandlerMapping} instances with. This method cannot be overridden,
328-
* use {@link #addInterceptors(InterceptorRegistry)} instead.
323+
* {@link HandlerMapping} instances with.
324+
* <p>This method cannot be overridden; use {@link #addInterceptors} instead.
329325
*/
330326
protected final Object[] getInterceptors() {
331327
if (this.interceptors == null) {
@@ -628,9 +624,8 @@ protected void configureAsyncSupport(AsyncSupportConfigurer configurer) {
628624
}
629625

630626
/**
631-
* Return a {@link FormattingConversionService} for use with annotated
632-
* controller methods and the {@code spring:eval} JSP tag.
633-
* Also see {@link #addFormatters} as an alternative to overriding this method.
627+
* Return a {@link FormattingConversionService} for use with annotated controllers.
628+
* <p>See {@link #addFormatters} as an alternative to overriding this method.
634629
*/
635630
@Bean
636631
public FormattingConversionService mvcConversionService() {
@@ -640,8 +635,9 @@ public FormattingConversionService mvcConversionService() {
640635
}
641636

642637
/**
643-
* Override this method to add custom {@link Converter}s and
644-
* {@link Formatter Converter}s and {@link Formatters}.
638+
* Override this method to add custom {@link Converter} and/or {@link Formatter}
639+
* delegates to the common {@link FormattingConversionService}.
640+
* @see #mvcConversionService()
645641
*/
646642
protected void addFormatters(FormatterRegistry registry) {
647643
}
@@ -686,9 +682,8 @@ protected Validator getValidator() {
686682

687683
/**
688684
* Provide access to the shared custom argument resolvers used by the
689-
* {@link RequestMappingHandlerAdapter} and the
690-
* {@link ExceptionHandlerExceptionResolver}. This method cannot be
691-
* overridden, use {@link #addArgumentResolvers(List)} instead.
685+
* {@link RequestMappingHandlerAdapter} and the {@link ExceptionHandlerExceptionResolver}.
686+
* <p>This method cannot be overridden; use {@link #addArgumentResolvers} instead.
692687
* @since 4.3
693688
*/
694689
protected final List<HandlerMethodArgumentResolver> getArgumentResolvers() {
@@ -700,24 +695,21 @@ protected final List<HandlerMethodArgumentResolver> getArgumentResolvers() {
700695
}
701696

702697
/**
703-
* Add custom {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers} to use in addition to
704-
* the ones registered by default.
705-
* <p>Custom argument resolvers are invoked before built-in resolvers
706-
* except for those that rely on the presence of annotations (e.g.
707-
* {@code @RequestParameter}, {@code @PathVariable}, etc.).
708-
* The latter can be customized by configuring the
698+
* Add custom {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers}
699+
* to use in addition to the ones registered by default.
700+
* <p>Custom argument resolvers are invoked before built-in resolvers except for
701+
* those that rely on the presence of annotations (e.g. {@code @RequestParameter},
702+
* {@code @PathVariable}, etc). The latter can be customized by configuring the
709703
* {@link RequestMappingHandlerAdapter} directly.
710-
* @param argumentResolvers the list of custom converters;
711-
* initially an empty list.
704+
* @param argumentResolvers the list of custom converters (initially an empty list)
712705
*/
713706
protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
714707
}
715708

716709
/**
717710
* Provide access to the shared return value handlers used by the
718-
* {@link RequestMappingHandlerAdapter} and the
719-
* {@link ExceptionHandlerExceptionResolver}. This method cannot be
720-
* overridden, use {@link #addReturnValueHandlers(List)} instead.
711+
* {@link RequestMappingHandlerAdapter} and the {@link ExceptionHandlerExceptionResolver}.
712+
* <p>This method cannot be overridden; use {@link #addReturnValueHandlers} instead.
721713
* @since 4.3
722714
*/
723715
protected final List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
@@ -729,27 +721,23 @@ protected final List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
729721
}
730722

731723
/**
732-
* Add custom {@link HandlerMethodReturnValueHandler HandlerMethodReturnValueHandlers} in addition to the
733-
* ones registered by default.
734-
* <p>Custom return value handlers are invoked before built-in ones except
735-
* for those that rely on the presence of annotations (e.g.
736-
* {@code @ResponseBody}, {@code @ModelAttribute}, etc.).
737-
* The latter can be customized by configuring the
724+
* Add custom {@link HandlerMethodReturnValueHandler HandlerMethodReturnValueHandlers}
725+
* in addition to the ones registered by default.
726+
* <p>Custom return value handlers are invoked before built-in ones except for
727+
* those that rely on the presence of annotations (e.g. {@code @ResponseBody},
728+
* {@code @ModelAttribute}, etc). The latter can be customized by configuring the
738729
* {@link RequestMappingHandlerAdapter} directly.
739-
* @param returnValueHandlers the list of custom handlers;
740-
* initially an empty list.
730+
* @param returnValueHandlers the list of custom handlers (initially an empty list)
741731
*/
742732
protected void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
743733
}
744734

745735
/**
746-
* Provides access to the shared {@link HttpMessageConverter HttpMessageConverters} used by the
747-
* {@link RequestMappingHandlerAdapter} and the
736+
* Provides access to the shared {@link HttpMessageConverter HttpMessageConverters}
737+
* used by the {@link RequestMappingHandlerAdapter} and the
748738
* {@link ExceptionHandlerExceptionResolver}.
749-
* This method cannot be overridden.
750-
* Use {@link #configureMessageConverters(List)} instead.
751-
* Also see {@link #addDefaultHttpMessageConverters(List)} that can be
752-
* used to add default message converters.
739+
* <p>This method cannot be overridden; use {@link #configureMessageConverters} instead.
740+
* Also see {@link #addDefaultHttpMessageConverters} for adding default message converters.
753741
*/
754742
protected final List<HttpMessageConverter<?>> getMessageConverters() {
755743
if (this.messageConverters == null) {
@@ -764,32 +752,30 @@ protected final List<HttpMessageConverter<?>> getMessageConverters() {
764752
}
765753

766754
/**
767-
* Override this method to add custom {@link HttpMessageConverter HttpMessageConverters} to use
768-
* with the {@link RequestMappingHandlerAdapter} and the
769-
* {@link ExceptionHandlerExceptionResolver}. Adding converters to the
770-
* list turns off the default converters that would otherwise be registered
771-
* by default. Also see {@link #addDefaultHttpMessageConverters(List)} that
772-
* can be used to add default message converters.
773-
* @param converters a list to add message converters to;
774-
* initially an empty list.
755+
* Override this method to add custom {@link HttpMessageConverter HttpMessageConverters}
756+
* to use with the {@link RequestMappingHandlerAdapter} and the
757+
* {@link ExceptionHandlerExceptionResolver}.
758+
* <p>Adding converters to the list turns off the default converters that would
759+
* otherwise be registered by default. Also see {@link #addDefaultHttpMessageConverters}
760+
* for adding default message converters.
761+
* @param converters a list to add message converters to (initially an empty list)
775762
*/
776763
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
777764
}
778765

779766
/**
780-
* Override this method to extend or modify the list of converters after it
781-
* has been configured. This may be useful for example to allow default
782-
* converters to be registered and then insert a custom converter through
783-
* this method.
784-
* @param converters the list of configured converters to extend.
767+
* Override this method to extend or modify the list of converters after it has
768+
* been configured. This may be useful for example to allow default converters
769+
* to be registered and then insert a custom converter through this method.
770+
* @param converters the list of configured converters to extend
785771
* @since 4.1.3
786772
*/
787773
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
788774
}
789775

790776
/**
791777
* Adds a set of default HttpMessageConverter instances to the given list.
792-
* Subclasses can call this method from {@link #configureMessageConverters(List)}.
778+
* Subclasses can call this method from {@link #configureMessageConverters}.
793779
* @param messageConverters the list to add the default message converters to
794780
*/
795781
protected final void addDefaultHttpMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
@@ -803,8 +789,8 @@ protected final void addDefaultHttpMessageConverters(List<HttpMessageConverter<?
803789
try {
804790
messageConverters.add(new SourceHttpMessageConverter<>());
805791
}
806-
catch (Error err) {
807-
// Ignore when no TransformerFactory implementation is available
792+
catch (Throwable ex) {
793+
// Ignore when no TransformerFactory implementation is available...
808794
}
809795
messageConverters.add(new AllEncompassingFormHttpMessageConverter());
810796

@@ -884,14 +870,12 @@ public SimpleControllerHandlerAdapter simpleControllerHandlerAdapter() {
884870
}
885871

886872
/**
887-
* Returns a {@link HandlerExceptionResolverComposite} containing a list
888-
* of exception resolvers obtained either through
889-
* {@link #configureHandlerExceptionResolvers(List)} or through
890-
* {@link #addDefaultHandlerExceptionResolvers(List)}.
891-
* <p><strong>Note:</strong> This method cannot be made final due to CGLib
892-
* constraints. Rather than overriding it, consider overriding
893-
* {@link #configureHandlerExceptionResolvers(List)}, which allows
894-
* providing a list of resolvers.
873+
* Returns a {@link HandlerExceptionResolverComposite} containing a list of exception
874+
* resolvers obtained either through {@link #configureHandlerExceptionResolvers} or
875+
* through {@link #addDefaultHandlerExceptionResolvers}.
876+
* <p><strong>Note:</strong> This method cannot be made final due to CGLIB constraints.
877+
* Rather than overriding it, consider overriding {@link #configureHandlerExceptionResolvers}
878+
* which allows for providing a list of resolvers.
895879
*/
896880
@Bean
897881
public HandlerExceptionResolver handlerExceptionResolver() {
@@ -909,29 +893,29 @@ public HandlerExceptionResolver handlerExceptionResolver() {
909893

910894
/**
911895
* Override this method to configure the list of
912-
* {@link HandlerExceptionResolver HandlerExceptionResolvers} to use. Adding resolvers to the list
913-
* turns off the default resolvers that would otherwise be registered by
914-
* default. Also see {@link #addDefaultHandlerExceptionResolvers(List)}
896+
* {@link HandlerExceptionResolver HandlerExceptionResolvers} to use.
897+
* <p>Adding resolvers to the list turns off the default resolvers that would otherwise
898+
* be registered by default. Also see {@link #addDefaultHandlerExceptionResolvers}
915899
* that can be used to add the default exception resolvers.
916-
* @param exceptionResolvers a list to add exception resolvers to;
917-
* initially an empty list.
900+
* @param exceptionResolvers a list to add exception resolvers to (initially an empty list)
918901
*/
919902
protected void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
920903
}
921904

922905
/**
923906
* Override this method to extend or modify the list of
924-
* {@link HandlerExceptionResolver HandlerExceptionResolvers} after it has been configured. This may
925-
* be useful for example to allow default resolvers to be registered and then
926-
* insert a custom one through this method.
907+
* {@link HandlerExceptionResolver HandlerExceptionResolvers} after it has been configured.
908+
* <p>This may be useful for example to allow default resolvers to be registered
909+
* and then insert a custom one through this method.
927910
* @param exceptionResolvers the list of configured resolvers to extend.
928911
* @since 4.3
929912
*/
930913
protected void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
931914
}
932915

933916
/**
934-
* A method available to subclasses for adding default {@link HandlerExceptionResolver HandlerExceptionResolvers}.
917+
* A method available to subclasses for adding default
918+
* {@link HandlerExceptionResolver HandlerExceptionResolvers}.
935919
* <p>Adds the following exception resolvers:
936920
* <ul>
937921
* <li>{@link ExceptionHandlerExceptionResolver} for handling exceptions through

0 commit comments

Comments
 (0)