diff --git a/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/HttpClient.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/HttpClient.java index e521cb3c9..00af14d7f 100644 --- a/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/HttpClient.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/HttpClient.java @@ -2,12 +2,14 @@ import com.symphony.bdk.http.api.util.TypeReference; +import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.With; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -368,34 +370,55 @@ public HttpClient build() { @Getter @NoArgsConstructor @AllArgsConstructor + @With(AccessLevel.PROTECTED) private static class RequestConfig { - @With private Map headers; - @With private Map cookies; - @With private Map formParams; - @With private List queryParams; + private Map headers; + private Map cookies; + private Map formParams; + private List queryParams; - @With private String path; - @With private Object body; - @With private String accept; - @With private String contentType; + private String path; + private Object body; + private String accept; + private String contentType; public Map appendHeader(String key, String value) { + + if (this.headers == null) { + this.headers = new HashMap<>(); + } + this.headers.put(key, value); return this.headers; } public Map appendCookie(String key, String value) { + + if (this.cookies == null) { + this.cookies = new HashMap<>(); + } + this.cookies.put(key, value); return this.cookies; } public List appendQueryParam(String key, String value) { + + if (this.queryParams == null) { + this.queryParams = new ArrayList<>(); + } + this.queryParams.add(new Pair(key, value)); return this.queryParams; } public Map appendFormParam(String key, Object value) { + + if (this.formParams == null) { + this.formParams = new HashMap<>(); + } + this.formParams.put(key, value); return this.formParams; } diff --git a/symphony-bdk-http/symphony-bdk-http-api/src/test/java/com/symphony/bdk/http/api/HttpClientTest.java b/symphony-bdk-http/symphony-bdk-http-api/src/test/java/com/symphony/bdk/http/api/HttpClientTest.java index 40899e195..c534aaa9f 100644 --- a/symphony-bdk-http/symphony-bdk-http-api/src/test/java/com/symphony/bdk/http/api/HttpClientTest.java +++ b/symphony-bdk-http/symphony-bdk-http-api/src/test/java/com/symphony/bdk/http/api/HttpClientTest.java @@ -21,6 +21,8 @@ public void usage() throws ApiException { final String response = httpClient.path("/api/v1/users") .header("Authorization", "Bearer AbCdEf123456") + .queryParam("test", "test") + .formParam("test", "test") .get(new TypeReference() {}); }