This closes #283
diff --git a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/EntityApi.java b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/EntityApi.java
index e5683ed..b3cae2f 100644
--- a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/EntityApi.java
+++ b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/EntityApi.java
@@ -221,9 +221,11 @@
@ApiParam(value = "Entity ID or name", required = true)
@PathParam("entity") String entity);
+ // see http://stackoverflow.com/questions/332129/yaml-mime-type for "@Produces"
@GET
@Path("/{entity}/spec")
@ApiOperation(value = "Get the YAML spec used to create the entity, if available")
+ @Produces({"text/x-yaml", "application/x-yaml", "text/yaml", "text/plain", "application/yaml", MediaType.TEXT_PLAIN})
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Application or entity missing")
})
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/EntityResource.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/EntityResource.java
index 4d263da..c67eaaa 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/EntityResource.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/EntityResource.java
@@ -218,6 +218,6 @@
NamedStringTag spec = BrooklynTags.findFirst(BrooklynTags.YAML_SPEC_KIND, entity.tags().getTags());
if (spec == null)
return null;
- return (String) WebResourceUtils.getValueForDisplay(spec.getContents(), true, true);
+ return (String) WebResourceUtils.getValueForDisplay(spec.getContents(), false, true);
}
}
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EntityResourceTest.java b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EntityResourceTest.java
index decbcef..62ee189 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EntityResourceTest.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EntityResourceTest.java
@@ -18,6 +18,8 @@
*/
package org.apache.brooklyn.rest.resources;
+import static org.testng.Assert.assertEquals;
+
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -30,6 +32,7 @@
import org.apache.brooklyn.core.entity.EntityInternal;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.stock.BasicApplication;
+import org.apache.brooklyn.entity.stock.BasicEntity;
import org.apache.brooklyn.rest.domain.ApplicationSpec;
import org.apache.brooklyn.rest.domain.EntitySpec;
import org.apache.brooklyn.rest.domain.TaskSummary;
@@ -46,6 +49,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@@ -85,6 +89,44 @@
}
@Test
+ public void testGetSpecAcceptingXYaml() throws Exception {
+ testGetSpec("text/x-yaml");
+ }
+
+ @Test
+ public void testGetSpecWithNoExplicitAccepts() throws Exception {
+ testGetSpec(null);
+ }
+
+ protected void testGetSpec(String acceptMimeType) throws Exception {
+ String appName = "ent-with-spec";
+
+ // Create an app with a yaml spec
+ String yaml = Joiner.on("\n").join(
+ "name: " + appName,
+ "services:",
+ "- type: "+BasicEntity.class.getName());
+ Response appResponse = client().path("/applications")
+ .header("Content-Type", "text/x-yaml")
+ .post(yaml);
+ waitForApplicationToBeRunning(appResponse.getLocation());
+
+ // Retrieve the yaml spec, and confirm it is as expected (not wrapped in quotes, and treating \n sensibly)
+ Response response;
+ if (acceptMimeType != null) {
+ response = client().path("/applications/" + appName + "/entities/" + appName + "/spec")
+ .accept(acceptMimeType)
+ .get();
+ } else {
+ response = client().path("/applications/" + appName + "/entities/" + appName + "/spec")
+ .get();
+ }
+ String data = response.readEntity(String.class);
+
+ assertEquals(data.trim(), yaml.trim());
+ }
+
+ @Test
public void testTagsSanity() throws Exception {
entity.tags().addTag("foo");