Skip to content

Commit 09aee0b

Browse files
authored
Merge pull request #79 from sumitnigamcs/PLUGIN-949
[PLUGIN-949] missing key value error msg
2 parents dcf808c + 3b7e23c commit 09aee0b

3 files changed

Lines changed: 149 additions & 0 deletions

File tree

src/main/java/io/cdap/plugin/http/source/batch/HttpBatchSourceConfig.java

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,113 @@ public class HttpBatchSourceConfig extends BaseHttpSourceConfig {
2424
protected HttpBatchSourceConfig(String referenceName) {
2525
super(referenceName);
2626
}
27+
28+
private HttpBatchSourceConfig(HttpBatchSourceConfigBuilder builder) {
29+
super(builder.referenceName);
30+
this.url = builder.url;
31+
this.httpMethod = builder.httpMethod;
32+
this.headers = builder.headers;
33+
this.format = builder.format;
34+
this.oauth2Enabled = builder.oauth2Enabled;
35+
this.errorHandling = builder.errorHandling;
36+
this.retryPolicy = builder.retryPolicy;
37+
this.maxRetryDuration = builder.maxRetryDuration;
38+
this.connectTimeout = builder.connectTimeout;
39+
this.readTimeout = builder.readTimeout;
40+
this.paginationType = builder.paginationType;
41+
this.verifyHttps = builder.verifyHttps;
42+
}
43+
44+
public static HttpBatchSourceConfigBuilder builder() {
45+
return new HttpBatchSourceConfigBuilder();
46+
}
47+
48+
/**
49+
* Builder for HttpBatchSourceConfig
50+
*/
51+
public static class HttpBatchSourceConfigBuilder {
52+
53+
private String referenceName;
54+
private String url;
55+
private String httpMethod;
56+
private String headers;
57+
private String format;
58+
private String oauth2Enabled;
59+
private String errorHandling;
60+
private String retryPolicy;
61+
private Long maxRetryDuration;
62+
private Integer connectTimeout;
63+
private Integer readTimeout;
64+
private String paginationType;
65+
private String verifyHttps;
66+
67+
public HttpBatchSourceConfigBuilder setReferenceName (String referenceName) {
68+
this.referenceName = referenceName;
69+
return this;
70+
}
71+
72+
public HttpBatchSourceConfigBuilder setUrl(String url) {
73+
this.url = url;
74+
return this;
75+
}
76+
77+
public HttpBatchSourceConfigBuilder setHttpMethod(String httpMethod) {
78+
this.httpMethod = httpMethod;
79+
return this;
80+
}
81+
82+
public HttpBatchSourceConfigBuilder setHeaders(String headers) {
83+
this.headers = headers;
84+
return this;
85+
}
86+
87+
public HttpBatchSourceConfigBuilder setFormat(String format) {
88+
this.format = format;
89+
return this;
90+
}
91+
92+
public HttpBatchSourceConfigBuilder setOauth2Enabled(String oauth2Enabled) {
93+
this.oauth2Enabled = oauth2Enabled;
94+
return this;
95+
}
96+
97+
public HttpBatchSourceConfigBuilder setErrorHandling(String errorHandling) {
98+
this.errorHandling = errorHandling;
99+
return this;
100+
}
101+
102+
public HttpBatchSourceConfigBuilder setRetryPolicy(String retryPolicy) {
103+
this.retryPolicy = retryPolicy;
104+
return this;
105+
}
106+
107+
public HttpBatchSourceConfigBuilder setMaxRetryDuration(Long maxRetryDuration) {
108+
this.maxRetryDuration = maxRetryDuration;
109+
return this;
110+
}
111+
112+
public HttpBatchSourceConfigBuilder setConnectTimeout(Integer connectTimeout) {
113+
this.connectTimeout = connectTimeout;
114+
return this;
115+
}
116+
117+
public HttpBatchSourceConfigBuilder setReadTimeout(Integer readTimeout) {
118+
this.readTimeout = readTimeout;
119+
return this;
120+
}
121+
122+
public HttpBatchSourceConfigBuilder setPaginationType(String paginationType) {
123+
this.paginationType = paginationType;
124+
return this;
125+
}
126+
127+
public HttpBatchSourceConfigBuilder setVerifyHttps(String verifyHttps) {
128+
this.verifyHttps = verifyHttps;
129+
return this;
130+
}
131+
132+
public HttpBatchSourceConfig build() {
133+
return new HttpBatchSourceConfig(this);
134+
}
135+
}
27136
}

src/main/java/io/cdap/plugin/http/source/common/BaseHttpSourceConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,9 @@ public static Map<String, String> getMapFromKeyValueString(String keyValueString
870870
String[] mappings = keyValueString.split(",");
871871
for (String map : mappings) {
872872
String[] columns = map.split(":");
873+
if (columns.length < 2) { //For scenario where either of key or value not provided
874+
throw new IllegalArgumentException(String.format("Missing value for key %s", columns[0]));
875+
}
873876
result.put(columns[0], columns[1]);
874877
}
875878
return result;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright © 2022 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package io.cdap.plugin.http.source.common;
18+
19+
import io.cdap.plugin.http.source.batch.HttpBatchSourceConfig;
20+
import org.apache.commons.lang3.StringUtils;
21+
import org.junit.Test;
22+
23+
/**
24+
* Unit tests for HttpBatchSourceConfig
25+
*/
26+
public class HttpBatchSourceConfigTest {
27+
28+
@Test (expected = IllegalArgumentException.class)
29+
public void testMissingKeyValue() {
30+
HttpBatchSourceConfig config = HttpBatchSourceConfig.builder()
31+
.setReferenceName("test").setUrl("http://localhost").setHttpMethod("GET").setHeaders("Auth:")
32+
.setFormat("JSON").setOauth2Enabled("false").setErrorHandling(StringUtils.EMPTY)
33+
.setRetryPolicy(StringUtils.EMPTY).setMaxRetryDuration(600L).setConnectTimeout(120)
34+
.setReadTimeout(120).setPaginationType("NONE").setVerifyHttps("true").build();
35+
config.validate();
36+
}
37+
}

0 commit comments

Comments
 (0)