Skip to content

Commit

Permalink
#369 - Traverson no defensively expands URIs handed to getAndFindLink…
Browse files Browse the repository at this point in the history
…WithRel(…).
  • Loading branch information
odrotbohm committed Jul 21, 2015
1 parent da01a20 commit 591749f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/springframework/hateoas/client/Hop.java
Expand Up @@ -79,6 +79,15 @@ public Hop withParameter(String name, Object value) {
return new Hop(rel, parameters);
}

/**
* Returns whether the {@link Hop} has parameters declared.
*
* @return
*/
boolean hasParameters() {
return !this.parameters.isEmpty();
}

/**
* Create a new {@link Map} starting with the supplied template parameters. Then add the ones for this hop. This
* allows a local hop to override global parameters.
Expand Down
Expand Up @@ -391,8 +391,9 @@ private String getAndFindLinkWithRel(String uri, Iterator<Hop> rels) {
}

HttpEntity<?> request = prepareRequest(headers);
UriTemplate template = new UriTemplate(uri);

ResponseEntity<String> responseEntity = operations.exchange(uri, GET, request, String.class);
ResponseEntity<String> responseEntity = operations.exchange(template.expand(), GET, request, String.class);
MediaType contentType = responseEntity.getHeaders().getContentType();
String responseBody = responseEntity.getBody();

Expand All @@ -409,7 +410,7 @@ private String getAndFindLinkWithRel(String uri, Iterator<Hop> rels) {
/**
* Don't expand if the parameters are empty
*/
if (thisHop.getParameters().isEmpty()) {
if (!thisHop.hasParameters()) {
return getAndFindLinkWithRel(link.getHref(), rels);
} else {
return getAndFindLinkWithRel(link.expand(thisHop.getMergedParameters(templateParameters)).getHref(), rels);
Expand Down

0 comments on commit 591749f

Please sign in to comment.