Skip to content

Commit

Permalink
Adds support for templated Urls of HAL specification
Browse files Browse the repository at this point in the history
- Upgrades spring-hateoas version to 0.9.0.RELEASE

- Upgrades spring-shell version to 1.0.0.RELEASE

- Adds support for templates urls

- Adds LinkUtil class which contains utility method to normalize templated links
  • Loading branch information
Faisal Feroz committed Feb 22, 2014
1 parent ccc9db9 commit bed975e
Show file tree
Hide file tree
Showing 6 changed files with 663 additions and 632 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ext {
logbackVersion = "1.0.9"

springVersion = "3.2.2.RELEASE"
springShellVersion = "1.0.1.BUILD-SNAPSHOT"
hateoasVersion = "0.4.0.RELEASE"
springShellVersion = "1.0.0.RELEASE"
hateoasVersion = "0.9.0.RELEASE"
jacksonVersion = "1.9.12"

junitVersion = "4.11"
Expand All @@ -38,7 +38,7 @@ project.targetCompatibility = 1.6

// Repositories
repositories {
//maven { url "http://repo.springsource.org/libs-snapshot" }
maven { url "http://repo.springsource.org/libs-snapshot" }
//maven { url "http://repo.springsource.org/libs-milestone" }
maven { url "http://repo.springsource.org/libs-release" }
maven { url "http://spring-roo-repository.springsource.org/release" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
Expand All @@ -21,6 +22,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.data.rest.shell.util.LinkUtil;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -60,7 +62,7 @@ public class DiscoveryCommands implements CommandMarker, ApplicationEventPublish
private RestTemplate client = new RestTemplate(requestFactory);
@Autowired(required = false)
private ObjectMapper mapper = new ObjectMapper();
private Map<String, String> resources = new HashMap<String, String>();
private Map<String, Link> resources = new HashMap<String, Link>();
private ApplicationEventPublisher ctx;

private static String pad(String s, int len) {
Expand All @@ -78,7 +80,7 @@ private static String pad(String s, int len) {
*
* @return
*/
public Map<String, String> getResources() {
public Map<String, Link> getResources() {
return resources;
}

Expand Down Expand Up @@ -134,7 +136,7 @@ public String list(
} else if(path.getPath().startsWith("http")) {
requestUri = URI.create(path.getPath());
} else if(resources.containsKey(path)) {
requestUri = UriComponentsBuilder.fromUriString(resources.get(path))
requestUri = UriComponentsBuilder.fromUriString(LinkUtil.normalize(resources.get(path)))
.build()
.toUri();
} else if("/".equals(configCmds.getBaseUri().getPath())) {
Expand Down Expand Up @@ -191,7 +193,7 @@ public String list(

// Now build a table
for(Link l : links) {
resources.put(l.getRel(), l.getHref());
resources.put(l.getRel(), l);
sb.append(pad(l.getRel(), maxRelLen))
.append(pad(l.getHref(), maxHrefLen))
.append(OsUtils.LINE_SEPARATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.net.URISyntaxException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.shell.util.LinkUtil;
import org.springframework.shell.core.CommandMarker;
import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
import org.springframework.shell.core.annotation.CliCommand;
Expand Down Expand Up @@ -35,7 +36,7 @@ public boolean isHierarchyAvailable() {
@CliCommand(value = "up", help = "Traverse one level up in the URL hierarchy.")
public void up() throws URISyntaxException {
if(discoveryCmds.getResources().containsKey("parent")) {
configCmds.setBaseUri(discoveryCmds.getResources().get("parent"));
configCmds.setBaseUri(LinkUtil.normalize(discoveryCmds.getResources().get("parent")));
return;
}

Expand Down
Loading

0 comments on commit bed975e

Please sign in to comment.