Skip to content

Commit

Permalink
Polishing KeyValueConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Mar 12, 2024
1 parent 7f1048a commit df81812
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
@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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
*/
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit df81812

Please sign in to comment.