Polishing KeyValueConverter
This commit is contained in:
@@ -27,19 +27,19 @@ import org.springframework.util.StringUtils;
|
||||
@Deprecated
|
||||
public class KeyValueConverter implements Converter<String, KeyValue> {
|
||||
|
||||
private static final String INVALID_CONFIGURATION_MESSAGE = "Invalid configuration, expected format is: 'key:value'";
|
||||
private static final String INVALID_CONFIGURATION_MESSAGE = "Invalid configuration, expected format is: 'key:value', received: ";
|
||||
|
||||
@Override
|
||||
public KeyValue convert(String source) throws IllegalArgumentException {
|
||||
try {
|
||||
String[] split = source.split(":");
|
||||
if (source.contains(":") && StringUtils.hasText(split[0])) {
|
||||
if (split.length == 2) {
|
||||
return new KeyValue(split[0], split.length == 1 ? "" : split[1]);
|
||||
}
|
||||
throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE);
|
||||
throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE + source);
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE);
|
||||
throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE + source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,19 +24,19 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class KeyValueConverter implements Converter<String, KeyValue> {
|
||||
|
||||
private static final String INVALID_CONFIGURATION_MESSAGE = "Invalid configuration, expected format is: 'key:value'";
|
||||
private static final String INVALID_CONFIGURATION_MESSAGE = "Invalid configuration, expected format is: 'key:value', received: ";
|
||||
|
||||
@Override
|
||||
public KeyValue convert(String source) throws IllegalArgumentException {
|
||||
try {
|
||||
String[] split = source.split(":");
|
||||
if (source.contains(":") && StringUtils.hasText(split[0])) {
|
||||
if (split.length == 2) {
|
||||
return new KeyValue(split[0], split.length == 1 ? "" : split[1]);
|
||||
}
|
||||
throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE);
|
||||
throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE + source);
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE);
|
||||
throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE + source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,4 @@ spring:
|
||||
- Path=/multivalueheaders
|
||||
filters:
|
||||
- AddRequestHeadersIfNotPresent=X-Request-Example:ValueA,X-Request-Second-Example:ValueC
|
||||
- AddRequestHeadersIfNotPresent=X-Request-Example:ValueB,X-Request-Second-Example:ValueD
|
||||
- AddRequestHeadersIfNotPresent=X-Request-Example:ValueB, X-Request-Second-Example:ValueD
|
||||
|
||||
Reference in New Issue
Block a user