10
10
import lombok .Data ;
11
11
import lombok .RequiredArgsConstructor ;
12
12
import org .apache .flink .util .Preconditions ;
13
- import org .apache .flink .util .StringUtils ;
13
+ import static org .apache .flink .util .StringUtils . isNullOrWhitespaceOnly ;
14
14
15
15
import com .getindata .connectors .http .internal .config .HttpConnectorConfigConstants ;
16
16
@@ -35,8 +35,7 @@ public class ComposeHttpStatusCodeChecker implements HttpStatusCodeChecker {
35
35
36
36
public ComposeHttpStatusCodeChecker (ComposeHttpStatusCodeCheckerConfig config ) {
37
37
// Handle deprecated configuration for backward compatibility.
38
- if (!StringUtils .isNullOrWhitespaceOnly (config .getDeprecatedCodePrefix ()) ||
39
- !StringUtils .isNullOrWhitespaceOnly (config .getDeprecatedErrorWhiteListPrefix ())) {
38
+ if (areDeprecatedPropertiesUsed (config )) {
40
39
notRetryableErrorStatusCodes = buildPredicate (config , config .getDeprecatedCodePrefix (),
41
40
config .getDeprecatedErrorWhiteListPrefix (), DEFAULT_DEPRECATED_ERROR_CODES );
42
41
retryableErrorStatusCodes = integer -> false ;
@@ -48,15 +47,28 @@ public ComposeHttpStatusCodeChecker(ComposeHttpStatusCodeCheckerConfig config) {
48
47
}
49
48
}
50
49
50
+ private boolean areDeprecatedPropertiesUsed (ComposeHttpStatusCodeCheckerConfig config ) {
51
+ boolean whiteListDefined =
52
+ !isNullOrWhitespaceOnly (config .getDeprecatedErrorWhiteListPrefix ());
53
+ boolean codeListDefined = !isNullOrWhitespaceOnly (config .getDeprecatedCodePrefix ());
54
+
55
+ return (whiteListDefined && !isNullOrWhitespaceOnly (
56
+ config .getProperties ().getProperty (config .getDeprecatedErrorWhiteListPrefix ())))
57
+ || (codeListDefined && !isNullOrWhitespaceOnly (
58
+ config .getProperties ().getProperty (config .getDeprecatedCodePrefix ())));
59
+ }
60
+
51
61
private Predicate <Integer > buildPredicate (
52
62
ComposeHttpStatusCodeCheckerConfig config ,
53
63
String errorCodePrefix ,
54
64
String whiteListPrefix ,
55
65
Predicate <Integer > defaultErrorCodes ) {
56
66
Properties properties = config .getProperties ();
57
67
58
- String errorCodes = properties .getProperty (errorCodePrefix , "" );
59
- String whitelistCodes = properties .getProperty (whiteListPrefix , "" );
68
+ String errorCodes =
69
+ errorCodePrefix == null ? "" : properties .getProperty (errorCodePrefix , "" );
70
+ String whitelistCodes =
71
+ whiteListPrefix == null ? "" : properties .getProperty (whiteListPrefix , "" );
60
72
61
73
Predicate <Integer > errorPredicate =
62
74
prepareErrorCodes (errorCodes ).orElse (defaultErrorCodes );
@@ -74,7 +86,7 @@ private Predicate<Integer> buildPredicate(
74
86
*/
75
87
private Optional <Predicate <Integer >> prepareErrorCodes (String statusCodesStr ) {
76
88
return Arrays .stream (statusCodesStr .split (HttpConnectorConfigConstants .PROP_DELIM ))
77
- .filter (code -> !StringUtils . isNullOrWhitespaceOnly (code ))
89
+ .filter (code -> !isNullOrWhitespaceOnly (code ))
78
90
.map (code -> code .toUpperCase ().trim ())
79
91
.map (codeStr -> {
80
92
Preconditions .checkArgument (
0 commit comments