Skip to content

Commit

Permalink
#462 Fixed HttpClient NPE when adding query param
Browse files Browse the repository at this point in the history
  • Loading branch information
thibauult committed Mar 2, 2021
1 parent a6a49a2 commit 723a4a7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -368,34 +370,55 @@ public HttpClient build() {
@Getter
@NoArgsConstructor
@AllArgsConstructor
@With(AccessLevel.PROTECTED)
private static class RequestConfig {

@With private Map<String, String> headers;
@With private Map<String, String> cookies;
@With private Map<String, Object> formParams;
@With private List<Pair> queryParams;
private Map<String, String> headers;
private Map<String, String> cookies;
private Map<String, Object> formParams;
private List<Pair> 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<String, String> appendHeader(String key, String value) {

if (this.headers == null) {
this.headers = new HashMap<>();
}

this.headers.put(key, value);
return this.headers;
}

public Map<String, String> appendCookie(String key, String value) {

if (this.cookies == null) {
this.cookies = new HashMap<>();
}

this.cookies.put(key, value);
return this.cookies;
}

public List<Pair> 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<String, Object> appendFormParam(String key, Object value) {

if (this.formParams == null) {
this.formParams = new HashMap<>();
}

this.formParams.put(key, value);
return this.formParams;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>() {});
}

Expand Down

0 comments on commit 723a4a7

Please sign in to comment.