Skip to content
This repository was archived by the owner on Apr 5, 2022. It is now read-only.

Support HAL #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ ext {
slf4jVersion = "1.7.2"
logbackVersion = "1.0.9"

springVersion = "3.2.2.RELEASE"
springVersion = "4.1.6.RELEASE"
springShellVersion = "1.1.0.RELEASE"
hateoasVersion = "0.4.0.RELEASE"
hateoasVersion = "0.16.0.RELEASE"
jacksonVersion = "1.9.12"

junitVersion = "4.11"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.data.rest.shell.context.BaseUriChangedEvent;
Expand All @@ -29,7 +30,7 @@ public class ConfigurationCommands implements CommandMarker, ApplicationEventPub

@Autowired
private ContextCommands contextCmds;
private URI baseUri = URI.create("http://localhost:8080");
private URI baseUri = URI.create((System.getenv("REST_SHELL_BASEURI") == null ? "http://localhost:8080": System.getenv("REST_SHELL_BASEURI")));
private ApplicationEventPublisher ctx = null;
private HttpHeaders headers = new HttpHeaders();
private ObjectMapper mapper = new ObjectMapper();
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 @@ -22,6 +23,7 @@
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpRequest;
Expand Down Expand Up @@ -63,6 +65,9 @@ public class DiscoveryCommands implements CommandMarker, ApplicationEventPublish
private Map<String, String> resources = new HashMap<String, String>();
private ApplicationEventPublisher ctx;

public DiscoveryCommands() {
}

private static String pad(String s, int len) {
char[] pad = new char[len - s.length()];
Arrays.fill(pad, ' ');
Expand Down Expand Up @@ -228,7 +233,7 @@ private class ExtractLinksHelper implements RequestCallback, ResponseExtractor<L
if(LOG.isDebugEnabled()) {
LOG.debug("No 'Accept' header specified, using " + COMPACT_JSON);
}
request.getHeaders().setAccept(Arrays.asList(COMPACT_JSON, MediaType.APPLICATION_JSON));
request.getHeaders().setAccept(Arrays.asList(COMPACT_JSON, MediaTypes.HAL_JSON, MediaType.APPLICATION_JSON));
}
}

Expand All @@ -249,6 +254,15 @@ private class ExtractLinksHelper implements RequestCallback, ResponseExtractor<L
links.add(new Link(href, rel));
}
}
} else {
o = m.get("_links");
if(o instanceof Map) {
Map map = (Map) o;
for (Object key : map.keySet()) {
Map valueMap = (Map) map.get(key);
links.add(new Link((String) valueMap.get("href"), (String)key));
}
}
}
} else if(null != ct && ct.getSubtype().endsWith("uri-list")) {
BufferedReader rdr = new BufferedReader(new InputStreamReader(response.getBody()));
Expand Down