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
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,18 @@ private Object executeRequest(final ResourceMethod rm,
pathSegments.add(pathTemplate.getSegment());
}
}
uriBuilder.appendPathSegments(pathSegments);
if (!pathSegments.isEmpty()) {
Comment thread
ok2c marked this conversation as resolved.
Resolved
// A base URI ending in '/' (as many are written) has an empty last path
// segment. Appending after it would produce '//'; drop it first, exactly
// as ResourceIfaceScanner#join already does when joining a resource class's
// path with its method's path.
final List<String> baseSegments = uriBuilder.getPathSegments();
if (!baseSegments.isEmpty() && baseSegments.get(baseSegments.size() - 1).isEmpty()) {
baseSegments.remove(baseSegments.size() - 1);
}
baseSegments.addAll(pathSegments);
uriBuilder.setPathSegments(baseSegments);
}
uriBuilder.addParameters(queryParams);
requestUri = uriBuilder.build();
} catch (final URISyntaxException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ void readsFormUrlEncodedResponseAsNameValuePairs() throws Exception {
assertThat(pairs.get(1).getValue()).isEqualTo("en");
}

@Test
void getBook_withTrailingSlashBaseUri_doesNotProduceDoubleSlash() throws Exception {
// A base URI ending in '/', as many are written, must not combine with the resource
// path to produce '//books/...': the server only has a context registered at
// "/books", so a leading double slash would not match it and the call would fail.
final URI trailingSlashBaseUri = new URI(baseUri.toString() + "/");
final BookResource client = RestClientBuilder.newBuilder()
.baseUri(trailingSlashBaseUri)
.httpClient(httpClient)
.build(BookResource.class);

final Book fetched = client.getBook("abc-123", "en", "token-1");

assertThat(fetched).isNotNull();
assertThat(fetched.id).isEqualTo("abc-123");
assertThat(fetched.lang).isEqualTo("en");
}

@Test
void rejectsNonFormResponseForNameValuePairReturnType() {
final BookResource client = RestClientBuilder.newBuilder()
Expand Down
Loading