E5EB Supports query params without values by jebeaudet · Pull Request #193 · OpenFeign/feign · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Adds Request.Options support to RibbonClient
* Updates to Ribbon 2.0-RC13
* Updates to Jackson 2.5.1
* Supports query parameters without values

### Version 7.2
* Adds `Feign.Builder.build()`
Expand Down
8 changes: 2 additions & 6 deletions core/src/main/java/feign/RequestTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ private static Map<String, Collection<String>> parseAndDecodeQueries(String quer
return map;
}
if (queryLine.indexOf('&') == -1) {
if (queryLine.indexOf('=') != -1) {
putKV(queryLine, map);
} else {
map.put(queryLine, null);
}
putKV(queryLine, map);
} else {
char[] chars = queryLine.toCharArray();
int start = 0;
Expand Down Expand Up @@ -504,7 +500,7 @@ private StringBuilder pullAnyQueriesOutOfUrl(StringBuilder url) {
}

private boolean allValuesAreNull(Collection<String> values) {
if (values.isEmpty()) {
if (values == null || values.isEmpty()) {
return true;
}
for (String val : values) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/feign/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type) {
* Returns an unmodifiable collection which may be empty, but is never null.
*/
public static <T> Collection<T> valuesOrEmpty(Map<String, Collection<T>> map, String key) {
return map.containsKey(key) ? map.get(key) : Collections.<T>emptyList();
return map.containsKey(key) && map.get(key) != null ? map.get(key) : Collections.<T>emptyList();
}

public static void ensureClosed(Closeable closeable) {
Expand Down
28 changes: 26 additions & 2 deletions core/src/test/java/feign/DefaultContractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.junit.rules.ExpectedException;

import java.net.URI;
import java.util.Collections;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -124,14 +125,31 @@ public void queryParamsInPathExtract() throws Exception {
);

assertThat(
contract.parseAndValidatateMetadata(WithQueryParamsInPath.class.getDeclaredMethod("empty"))
contract.parseAndValidatateMetadata(WithQueryParamsInPath.class.getDeclaredMethod("twoAndOneEmpty"))
.template())
.hasUrl("/")
.hasQueries(
entry("flag", asList(new String[]{null})),
entry("Action", asList("GetUser")),
entry("Version", asList("2010-05-08"))
);

assertThat(
contract.parseAndValidatateMetadata(WithQueryParamsInPath.class.getDeclaredMethod("oneEmpty"))
.template())
.hasUrl("/")
.hasQueries(
entry("flag", asList(new String[]{null}))
);

assertThat(
contract.parseAndValidatateMetadata(WithQueryParamsInPath.class.getDeclaredMethod("twoEmpty"))
.template())
.hasUrl("/")
.hasQueries(
entry("flag", asList(new String[]{null})),
entry("NoErrors", asList(new String[]{null}))
);
}

@Test
Expand Down Expand Up @@ -307,7 +325,13 @@ interface WithQueryParamsInPath {
Response three();

@RequestLine("GET /?flag&Action=GetUser&Version=2010-05-08")
Response empty();
Response twoAndOneEmpty();

@RequestLine("GET /?flag")
Response oneEmpty();

@RequestLine("GET /?flag&NoErrors")
Response twoEmpty();
}

interface BodyWithoutParameters {
Expand Down
0