1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -422,6 +422,7 @@ public int getContentLength() {
422
422
return (this .content != null ? this .content .length : -1 );
423
423
}
424
424
425
+ @ Override
425
426
public long getContentLengthLong () {
426
427
return getContentLength ();
427
428
}
@@ -475,28 +476,25 @@ public void setParameter(String name, String value) {
475
476
* <p>If there are already one or more values registered for the given
476
477
* parameter name, they will be replaced.
477
478
*/
478
- public void setParameter (String name , String [] values ) {
479
+ public void setParameter (String name , String ... values ) {
479
480
Assert .notNull (name , "Parameter name must not be null" );
480
481
this .parameters .put (name , values );
481
482
}
482
483
483
484
/**
484
- * Sets all provided parameters <strong>replacing</strong> any existing
485
+ * Set all provided parameters <strong>replacing</strong> any existing
485
486
* values for the provided parameter names. To add without replacing
486
487
* existing values, use {@link #addParameters(java.util.Map)}.
487
488
*/
488
- @ SuppressWarnings ("rawtypes" )
489
- public void setParameters (Map params ) {
489
+ public void setParameters (Map <String , ?> params ) {
490
490
Assert .notNull (params , "Parameter map must not be null" );
491
- for (Object key : params .keySet ()) {
492
- Assert .isInstanceOf (String .class , key ,
493
- "Parameter map key must be of type [" + String .class .getName () + "]" );
491
+ for (String key : params .keySet ()) {
494
492
Object value = params .get (key );
495
493
if (value instanceof String ) {
496
- this . setParameter (( String ) key , (String ) value );
494
+ setParameter (key , (String ) value );
497
495
}
498
496
else if (value instanceof String []) {
499
- this . setParameter (( String ) key , (String []) value );
497
+ setParameter (key , (String []) value );
500
498
}
501
499
else {
502
500
throw new IllegalArgumentException (
@@ -519,7 +517,7 @@ public void addParameter(String name, String value) {
519
517
* <p>If there are already one or more values registered for the given
520
518
* parameter name, the given values will be added to the end of the list.
521
519
*/
522
- public void addParameter (String name , String [] values ) {
520
+ public void addParameter (String name , String ... values ) {
523
521
Assert .notNull (name , "Parameter name must not be null" );
524
522
String [] oldArr = this .parameters .get (name );
525
523
if (oldArr != null ) {
@@ -538,18 +536,15 @@ public void addParameter(String name, String[] values) {
538
536
* existing values. To replace existing values, use
539
537
* {@link #setParameters(java.util.Map)}.
540
538
*/
541
- @ SuppressWarnings ("rawtypes" )
542
- public void addParameters (Map params ) {
539
+ public void addParameters (Map <String , ?> params ) {
543
540
Assert .notNull (params , "Parameter map must not be null" );
544
- for (Object key : params .keySet ()) {
545
- Assert .isInstanceOf (String .class , key ,
546
- "Parameter map key must be of type [" + String .class .getName () + "]" );
541
+ for (String key : params .keySet ()) {
547
542
Object value = params .get (key );
548
543
if (value instanceof String ) {
549
- this .addParameter (( String ) key , (String ) value );
544
+ this .addParameter (key , (String ) value );
550
545
}
551
546
else if (value instanceof String []) {
552
- this .addParameter (( String ) key , (String []) value );
547
+ this .addParameter (key , (String []) value );
553
548
}
554
549
else {
555
550
throw new IllegalArgumentException ("Parameter map value must be single value " +
@@ -929,14 +924,14 @@ public Cookie[] getCookies() {
929
924
* @see #getDateHeader
930
925
*/
931
926
public void addHeader (String name , Object value ) {
932
- if (CONTENT_TYPE_HEADER .equalsIgnoreCase (name )) {
933
- setContentType ((String ) value );
934
- return ;
927
+ if (CONTENT_TYPE_HEADER .equalsIgnoreCase (name ) && !this .headers .containsKey (CONTENT_TYPE_HEADER )) {
928
+ setContentType (value .toString ());
929
+ }
930
+ else {
931
+ doAddHeaderValue (name , value , false );
935
932
}
936
- doAddHeaderValue (name , value , false );
937
933
}
938
934
939
- @ SuppressWarnings ("rawtypes" )
940
935
private void doAddHeaderValue (String name , Object value , boolean replace ) {
941
936
HeaderValueHolder header = HeaderValueHolder .getByName (this .headers , name );
942
937
Assert .notNull (value , "Header value must not be null" );
0 commit comments