@@ -262,6 +262,10 @@ public class DefaultHttpHeaderMapper implements HeaderMapper<HttpHeaders>, BeanF
262
262
// Copy of 'org.springframework.http.HttpHeaders#GMT'
263
263
private static final ZoneId GMT = ZoneId .of ("GMT" );
264
264
265
+ // Copy of 'org.springframework.http.HttpHeaders#DATE_FORMATTER'
266
+ protected static final DateTimeFormatter DATE_FORMATTER =
267
+ DateTimeFormatter .ofPattern ("EEE, dd MMM yyyy HH:mm:ss zzz" , Locale .US ).withZone (GMT );
268
+
265
269
// Copy of 'org.springframework.http.HttpHeaders#DATE_FORMATS'
266
270
protected static final DateTimeFormatter [] DATE_FORMATS = new DateTimeFormatter [] {
267
271
DateTimeFormatter .RFC_1123_DATE_TIME ,
@@ -413,27 +417,28 @@ public void setUserDefinedHeaderPrefix(String userDefinedHeaderPrefix) {
413
417
@ Override
414
418
public void fromHeaders (MessageHeaders headers , HttpHeaders target ) {
415
419
if (this .logger .isDebugEnabled ()) {
416
- this .logger .debug (MessageFormat .format ("outboundHeaderNames={0}" ,
417
- CollectionUtils .arrayToList (this .outboundHeaderNames )));
420
+ this .logger .debug ("outboundHeaderNames=" + Arrays .toString (this .outboundHeaderNames ));
418
421
}
419
422
for (Entry <String , Object > entry : headers .entrySet ()) {
420
423
String name = entry .getKey ();
421
424
String lowerName = name .toLowerCase ();
422
- if (this . shouldMapOutboundHeader (lowerName )) {
425
+ if (shouldMapOutboundHeader (lowerName )) {
423
426
Object value = entry .getValue ();
424
427
if (value != null ) {
425
428
if (!HTTP_REQUEST_HEADER_NAMES_LOWER .contains (lowerName ) &&
426
429
!HTTP_RESPONSE_HEADER_NAMES_LOWER .contains (lowerName ) &&
427
430
!MessageHeaders .CONTENT_TYPE .equalsIgnoreCase (name )) {
428
431
// prefix the user-defined header names if not already prefixed
429
432
430
- name = StringUtils .startsWithIgnoreCase (name , this .userDefinedHeaderPrefix ) ? name :
431
- this .userDefinedHeaderPrefix + name ;
433
+ name =
434
+ StringUtils .startsWithIgnoreCase (name , this .userDefinedHeaderPrefix )
435
+ ? name
436
+ : this .userDefinedHeaderPrefix + name ;
432
437
}
433
438
if (this .logger .isDebugEnabled ()) {
434
439
this .logger .debug (MessageFormat .format ("setting headerName=[{0}], value={1}" , name , value ));
435
440
}
436
- this . setHttpHeader (target , name , value );
441
+ setHttpHeader (target , name , value );
437
442
}
438
443
}
439
444
}
@@ -450,36 +455,36 @@ public Map<String, Object> toHeaders(HttpHeaders source) {
450
455
this .logger .debug (MessageFormat .format ("inboundHeaderNames={0}" ,
451
456
CollectionUtils .arrayToList (this .inboundHeaderNames )));
452
457
}
453
- Map <String , Object > target = new HashMap <String , Object >();
458
+ Map <String , Object > target = new HashMap <>();
454
459
Set <String > headerNames = source .keySet ();
455
460
for (String name : headerNames ) {
456
461
String lowerName = name .toLowerCase ();
457
- if (this . shouldMapInboundHeader (lowerName )) {
462
+ if (shouldMapInboundHeader (lowerName )) {
458
463
if (!HTTP_REQUEST_HEADER_NAMES_LOWER .contains (lowerName )
459
464
&& !HTTP_RESPONSE_HEADER_NAMES_LOWER .contains (lowerName )) {
460
465
String prefixedName = StringUtils .startsWithIgnoreCase (name , this .userDefinedHeaderPrefix )
461
466
? name
462
467
: this .userDefinedHeaderPrefix + name ;
463
468
Object value = source .containsKey (prefixedName )
464
- ? this . getHttpHeader (source , prefixedName )
465
- : this . getHttpHeader (source , name );
469
+ ? getHttpHeader (source , prefixedName )
470
+ : getHttpHeader (source , name );
466
471
if (value != null ) {
467
472
if (this .logger .isDebugEnabled ()) {
468
473
this .logger .debug (MessageFormat .format ("setting headerName=[{0}], value={1}" , name , value ));
469
474
}
470
- this . setMessageHeader (target , name , value );
475
+ setMessageHeader (target , name , value );
471
476
}
472
477
}
473
478
else {
474
- Object value = this . getHttpHeader (source , name );
479
+ Object value = getHttpHeader (source , name );
475
480
if (value != null ) {
476
481
if (this .logger .isDebugEnabled ()) {
477
482
this .logger .debug (MessageFormat .format ("setting headerName=[{0}], value={1}" , name , value ));
478
483
}
479
484
if (CONTENT_TYPE .equalsIgnoreCase (name )) {
480
485
name = MessageHeaders .CONTENT_TYPE ;
481
486
}
482
- this . setMessageHeader (target , name , value );
487
+ setMessageHeader (target , name , value );
483
488
}
484
489
}
485
490
}
@@ -511,9 +516,10 @@ private boolean shouldMapOutboundHeader(String headerName) {
511
516
* When using the default response header name list, suppress the
512
517
* mapping of exclusions for specific headers.
513
518
*/
514
- if (this . containsElementIgnoreCase (this .excludedInboundStandardResponseHeaderNames , headerName )) {
519
+ if (containsElementIgnoreCase (this .excludedInboundStandardResponseHeaderNames , headerName )) {
515
520
if (this .logger .isDebugEnabled ()) {
516
- this .logger .debug (MessageFormat .format ("headerName=[{0}] WILL NOT be mapped (excluded)" , headerName ));
521
+ this .logger
522
+ .debug (MessageFormat .format ("headerName=[{0}] WILL NOT be mapped (excluded)" , headerName ));
517
523
}
518
524
return false ;
519
525
}
@@ -524,18 +530,19 @@ else if (this.isDefaultOutboundMapper) {
524
530
* When using the default request header name list, suppress the
525
531
* mapping of exclusions for specific headers.
526
532
*/
527
- if (this . containsElementIgnoreCase (this .excludedOutboundStandardRequestHeaderNames , headerName )) {
533
+ if (containsElementIgnoreCase (this .excludedOutboundStandardRequestHeaderNames , headerName )) {
528
534
if (this .logger .isDebugEnabled ()) {
529
- this .logger .debug (MessageFormat .format ("headerName=[{0}] WILL NOT be mapped (excluded)" , headerName ));
535
+ this .logger
536
+ .debug (MessageFormat .format ("headerName=[{0}] WILL NOT be mapped (excluded)" , headerName ));
530
537
}
531
538
return false ;
532
539
}
533
540
}
534
- return this . shouldMapHeader (headerName , outboundHeaderNamesLower );
541
+ return shouldMapHeader (headerName , outboundHeaderNamesLower );
535
542
}
536
543
537
544
protected final boolean shouldMapInboundHeader (String headerName ) {
538
- return this . shouldMapHeader (headerName , this .inboundHeaderNamesLower );
545
+ return shouldMapHeader (headerName , this .inboundHeaderNamesLower );
539
546
}
540
547
541
548
/**
@@ -582,7 +589,7 @@ private void setHttpHeader(HttpHeaders target, String name, Object value) {
582
589
if (value instanceof Collection <?>) {
583
590
Collection <?> values = (Collection <?>) value ;
584
591
if (!CollectionUtils .isEmpty (values )) {
585
- List <MediaType > acceptableMediaTypes = new ArrayList <MediaType >();
592
+ List <MediaType > acceptableMediaTypes = new ArrayList <>();
586
593
for (Object type : values ) {
587
594
if (type instanceof MediaType ) {
588
595
acceptableMediaTypes .add ((MediaType ) type );
@@ -604,7 +611,7 @@ else if (value instanceof MediaType) {
604
611
target .setAccept (Collections .singletonList ((MediaType ) value ));
605
612
}
606
613
else if (value instanceof String []) {
607
- List <MediaType > acceptableMediaTypes = new ArrayList <MediaType >();
614
+ List <MediaType > acceptableMediaTypes = new ArrayList <>();
608
615
for (String next : (String []) value ) {
609
616
acceptableMediaTypes .add (MediaType .parseMediaType (next ));
610
617
}
@@ -623,7 +630,7 @@ else if (ACCEPT_CHARSET.equalsIgnoreCase(name)) {
623
630
if (value instanceof Collection <?>) {
624
631
Collection <?> values = (Collection <?>) value ;
625
632
if (!CollectionUtils .isEmpty (values )) {
626
- List <Charset > acceptableCharsets = new ArrayList <Charset >();
633
+ List <Charset > acceptableCharsets = new ArrayList <>();
627
634
for (Object charset : values ) {
628
635
if (charset instanceof Charset ) {
629
636
acceptableCharsets .add ((Charset ) charset );
@@ -642,7 +649,7 @@ else if (charset instanceof String) {
642
649
}
643
650
}
644
651
else if (value instanceof Charset [] || value instanceof String []) {
645
- List <Charset > acceptableCharsets = new ArrayList <Charset >();
652
+ List <Charset > acceptableCharsets = new ArrayList <>();
646
653
Object [] values = ObjectUtils .toObjectArray (value );
647
654
for (Object charset : values ) {
648
655
if (charset instanceof Charset ) {
@@ -659,7 +666,7 @@ else if (value instanceof Charset) {
659
666
}
660
667
else if (value instanceof String ) {
661
668
String [] charsets = StringUtils .commaDelimitedListToStringArray ((String ) value );
662
- List <Charset > acceptableCharsets = new ArrayList <Charset >();
669
+ List <Charset > acceptableCharsets = new ArrayList <>();
663
670
for (String charset : charsets ) {
664
671
acceptableCharsets .add (Charset .forName (charset .trim ()));
665
672
}
@@ -675,7 +682,7 @@ else if (ALLOW.equalsIgnoreCase(name)) {
675
682
if (value instanceof Collection <?>) {
676
683
Collection <?> values = (Collection <?>) value ;
677
684
if (!CollectionUtils .isEmpty (values )) {
678
- Set <HttpMethod > allowedMethods = new HashSet <HttpMethod >();
685
+ Set <HttpMethod > allowedMethods = new HashSet <>();
679
686
for (Object method : values ) {
680
687
if (method instanceof HttpMethod ) {
681
688
allowedMethods .add ((HttpMethod ) method );
@@ -698,14 +705,14 @@ else if (method instanceof String) {
698
705
target .setAllow (Collections .singleton ((HttpMethod ) value ));
699
706
}
700
707
else if (value instanceof HttpMethod []) {
701
- Set <HttpMethod > allowedMethods = new HashSet <HttpMethod >();
708
+ Set <HttpMethod > allowedMethods = new HashSet <>();
702
709
Collections .addAll (allowedMethods , (HttpMethod []) value );
703
710
target .setAllow (allowedMethods );
704
711
}
705
712
else if (value instanceof String || value instanceof String []) {
706
713
String [] values = (value instanceof String []) ? (String []) value
707
714
: StringUtils .commaDelimitedListToStringArray ((String ) value );
708
- Set <HttpMethod > allowedMethods = new HashSet <HttpMethod >();
715
+ Set <HttpMethod > allowedMethods = new HashSet <>();
709
716
for (String next : values ) {
710
717
allowedMethods .add (HttpMethod .valueOf (next .trim ()));
711
718
}
@@ -766,7 +773,7 @@ else if (value instanceof String) {
766
773
target .setDate (Long .parseLong ((String ) value ));
767
774
}
768
775
catch (@ SuppressWarnings (UNUSED ) NumberFormatException e ) {
769
- target .setDate (this . getFirstDate ((String ) value , DATE ));
776
+ target .setDate (getFirstDate ((String ) value , DATE ));
770
777
}
771
778
}
772
779
else {
@@ -797,7 +804,7 @@ else if (value instanceof String) {
797
804
target .setExpires (Long .parseLong ((String ) value ));
798
805
}
799
806
catch (@ SuppressWarnings (UNUSED ) NumberFormatException e ) {
800
- target .setExpires (this . getFirstDate ((String ) value , EXPIRES ));
807
+ target .setExpires (getFirstDate ((String ) value , EXPIRES ));
801
808
}
802
809
}
803
810
else {
@@ -818,7 +825,7 @@ else if (value instanceof String) {
818
825
target .setIfModifiedSince (Long .parseLong ((String ) value ));
819
826
}
820
827
catch (@ SuppressWarnings (UNUSED ) NumberFormatException e ) {
821
- target .setIfModifiedSince (this . getFirstDate ((String ) value , IF_MODIFIED_SINCE ));
828
+ target .setIfModifiedSince (getFirstDate ((String ) value , IF_MODIFIED_SINCE ));
822
829
}
823
830
}
824
831
else {
@@ -829,20 +836,20 @@ else if (value instanceof String) {
829
836
}
830
837
}
831
838
else if (IF_UNMODIFIED_SINCE .equalsIgnoreCase (name )) {
832
- String ifUnmodifiedSinceValue = null ;
839
+ String ifUnmodifiedSinceValue ;
833
840
if (value instanceof Date ) {
834
- ifUnmodifiedSinceValue = this . formatDate (((Date ) value ).getTime ());
841
+ ifUnmodifiedSinceValue = formatDate (((Date ) value ).getTime ());
835
842
}
836
843
else if (value instanceof Number ) {
837
- ifUnmodifiedSinceValue = this . formatDate (((Number ) value ).longValue ());
844
+ ifUnmodifiedSinceValue = formatDate (((Number ) value ).longValue ());
838
845
}
839
846
else if (value instanceof String ) {
840
847
try {
841
- ifUnmodifiedSinceValue = this . formatDate (Long .parseLong ((String ) value ));
848
+ ifUnmodifiedSinceValue = formatDate (Long .parseLong ((String ) value ));
842
849
}
843
850
catch (@ SuppressWarnings (UNUSED ) NumberFormatException e ) {
844
- long longValue = this . getFirstDate ((String ) value , IF_UNMODIFIED_SINCE );
845
- ifUnmodifiedSinceValue = this . formatDate (longValue );
851
+ long longValue = getFirstDate ((String ) value , IF_UNMODIFIED_SINCE );
852
+ ifUnmodifiedSinceValue = formatDate (longValue );
846
853
}
847
854
}
848
855
else {
@@ -864,7 +871,7 @@ else if (value instanceof String[]) {
864
871
else if (value instanceof Collection ) {
865
872
Collection <?> values = (Collection <?>) value ;
866
873
if (!CollectionUtils .isEmpty (values )) {
867
- List <String > ifNoneMatchList = new ArrayList <String >();
874
+ List <String > ifNoneMatchList = new ArrayList <>();
868
875
for (Object next : values ) {
869
876
if (next instanceof String ) {
870
877
ifNoneMatchList .add ((String ) next );
@@ -891,7 +898,7 @@ else if (value instanceof String) {
891
898
target .setLastModified (Long .parseLong ((String ) value ));
892
899
}
893
900
catch (@ SuppressWarnings (UNUSED ) NumberFormatException e ) {
894
- target .setLastModified (this . getFirstDate ((String ) value , LAST_MODIFIED ));
901
+ target .setLastModified (getFirstDate ((String ) value , LAST_MODIFIED ));
895
902
}
896
903
}
897
904
else {
@@ -939,12 +946,12 @@ else if (value instanceof String[]) {
939
946
}
940
947
else if (value instanceof Iterable <?>) {
941
948
for (Object next : (Iterable <?>) value ) {
942
- String convertedValue = null ;
949
+ String convertedValue ;
943
950
if (next instanceof String ) {
944
951
convertedValue = (String ) next ;
945
952
}
946
953
else {
947
- convertedValue = this . convertToString (value );
954
+ convertedValue = convertToString (value );
948
955
}
949
956
if (StringUtils .hasText (convertedValue )) {
950
957
target .add (name , convertedValue );
@@ -957,7 +964,7 @@ else if (value instanceof Iterable<?>) {
957
964
}
958
965
}
959
966
else {
960
- String convertedValue = this . convertToString (value );
967
+ String convertedValue = convertToString (value );
961
968
if (StringUtils .hasText (convertedValue )) {
962
969
target .set (name , convertedValue );
963
970
}
@@ -1018,7 +1025,7 @@ else if (IF_MODIFIED_SINCE.equalsIgnoreCase(name)) {
1018
1025
}
1019
1026
else if (IF_UNMODIFIED_SINCE .equalsIgnoreCase (name )) {
1020
1027
String unmodifiedSince = source .getFirst (IF_UNMODIFIED_SINCE );
1021
- return unmodifiedSince != null ? this . getFirstDate (unmodifiedSince , IF_UNMODIFIED_SINCE ) : null ;
1028
+ return unmodifiedSince != null ? getFirstDate (unmodifiedSince , IF_UNMODIFIED_SINCE ) : null ;
1022
1029
}
1023
1030
else if (LAST_MODIFIED .equalsIgnoreCase (name )) {
1024
1031
long lastModified = source .getLastModified ();
@@ -1066,6 +1073,7 @@ protected String convertToString(Object value) {
1066
1073
if (this .conversionService != null &&
1067
1074
this .conversionService .canConvert (TypeDescriptor .forObject (value ),
1068
1075
TypeDescriptor .valueOf (String .class ))) {
1076
+
1069
1077
return this .conversionService .convert (value , String .class );
1070
1078
}
1071
1079
return null ;
@@ -1089,10 +1097,10 @@ protected long getFirstDate(String headerValue, String headerName) {
1089
1097
+ "' header" );
1090
1098
}
1091
1099
1092
- protected String formatDate (long date ) {
1100
+ protected static String formatDate (long date ) {
1093
1101
Instant instant = Instant .ofEpochMilli (date );
1094
1102
ZonedDateTime zonedDateTime = ZonedDateTime .ofInstant (instant , GMT );
1095
- return DATE_FORMATS [ 0 ] .format (zonedDateTime );
1103
+ return DATE_FORMATTER .format (zonedDateTime );
1096
1104
}
1097
1105
1098
1106
/**
0 commit comments