Repository: brooklyn-server
Updated Branches:
  refs/heads/master 1ea4c5172 -> 23cb3a080


HttpCommandEffector allows string payload

Also fixed integration tests that failing due to https://httpbin


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/1c064b28
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/1c064b28
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/1c064b28

Branch: refs/heads/master
Commit: 1c064b284757ed0c794cbf8f3a6d65e34564af3a
Parents: 8930ab6
Author: Duncan Grant <[email protected]>
Authored: Fri Mar 24 09:15:47 2017 +0000
Committer: Duncan Grant <[email protected]>
Committed: Fri Mar 24 09:15:47 2017 +0000

----------------------------------------------------------------------
 .../core/effector/http/HttpCommandEffector.java |  2 +-
 .../HttpCommandEffectorIntegrationTest.java     | 14 +++++++-------
 .../effector/http/HttpCommandEffectorTest.java  | 20 ++++++++++++++++++++
 3 files changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1c064b28/core/src/main/java/org/apache/brooklyn/core/effector/http/HttpCommandEffector.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/effector/http/HttpCommandEffector.java
 
b/core/src/main/java/org/apache/brooklyn/core/effector/http/HttpCommandEffector.java
index 1388a926..a32e0fe 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/effector/http/HttpCommandEffector.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/effector/http/HttpCommandEffector.java
@@ -181,7 +181,7 @@ public final class HttpCommandEffector extends AddEffector {
                 if (contentType == null || 
contentType.equalsIgnoreCase(APPLICATION_JSON)) {
                     LOG.warn("Content-Type not specified. Using {}, as default 
(continuing)", APPLICATION_JSON);
                     body = toJsonString(payload);
-                } else if (!(payload instanceof String) && 
!contentType.equalsIgnoreCase(APPLICATION_JSON)) {
+                } else if (!contentType.equalsIgnoreCase(APPLICATION_JSON)) {
                     LOG.warn("the http request may fail with payload {} and 
'Content-Type= {}, (continuing)", payload, contentType);
                     body = payload.toString();
                 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1c064b28/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorIntegrationTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorIntegrationTest.java
 
b/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorIntegrationTest.java
index 7d1a91a..c99c9c3 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorIntegrationTest.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorIntegrationTest.java
@@ -61,7 +61,7 @@ public class HttpCommandEffectorIntegrationTest {
     public void testHttpEffector() throws Exception {
         new HttpCommandEffector(ConfigBag.newInstance()
                 .configure(HttpCommandEffector.EFFECTOR_NAME, "Httpbin")
-                .configure(HttpCommandEffector.EFFECTOR_URI, 
"https://httpbin.org/get?login=myLogin";)
+                .configure(HttpCommandEffector.EFFECTOR_URI, 
"http://httpbin.org/get?login=myLogin";)
                 .configure(HttpCommandEffector.EFFECTOR_HTTP_VERB, "GET")
         ).apply(entity);
 
@@ -73,7 +73,7 @@ public class HttpCommandEffectorIntegrationTest {
     public void testHttpEffectorWithPayload() throws Exception {
         new HttpCommandEffector(ConfigBag.newInstance()
                 .configure(HttpCommandEffector.EFFECTOR_NAME, "HttpbinPost")
-                .configure(HttpCommandEffector.EFFECTOR_URI, 
"https://httpbin.org/post";)
+                .configure(HttpCommandEffector.EFFECTOR_URI, 
"http://httpbin.org/post";)
                 .configure(HttpCommandEffector.EFFECTOR_HTTP_VERB, "POST")
                 .configure(HttpCommandEffector.EFFECTOR_HTTP_PAYLOAD, 
ImmutableMap.<String, Object>of(
                         "description", "Created via API", 
@@ -92,7 +92,7 @@ public class HttpCommandEffectorIntegrationTest {
     public void testHttpEffectorWithJsonPath() throws Exception {
         new HttpCommandEffector(ConfigBag.newInstance()
                 .configure(HttpCommandEffector.EFFECTOR_NAME, "Httpbin")
-                .configure(HttpCommandEffector.EFFECTOR_URI, 
"https://httpbin.org/get?id=myId";)
+                .configure(HttpCommandEffector.EFFECTOR_URI, 
"http://httpbin.org/get?id=myId";)
                 .configure(HttpCommandEffector.EFFECTOR_HTTP_VERB, "GET")
                 .configure(HttpCommandEffector.JSON_PATH, "$.args.id")
                 .configure(HttpCommandEffector.PUBLISH_SENSOR, "result")
@@ -107,19 +107,19 @@ public class HttpCommandEffectorIntegrationTest {
     public void testHttpEffectorWithParameters() throws Exception {
         new HttpCommandEffector(ConfigBag.newInstance()
                 .configure(HttpCommandEffector.EFFECTOR_NAME, "Httpbin")
-                .configure(HttpCommandEffector.EFFECTOR_URI, 
"https://httpbin.org/get";)                
+                .configure(HttpCommandEffector.EFFECTOR_URI, 
"http://httpbin.org/get";)
                 .configure(HttpCommandEffector.EFFECTOR_HTTP_VERB, "GET")
                 .configure(HttpCommandEffector.EFFECTOR_PARAMETER_DEFS,
-                        MutableMap.<String,Object>of("uri", 
MutableMap.of("defaultValue", "https://httpbin.org/get";))))
+                        MutableMap.<String,Object>of("uri", 
MutableMap.of("defaultValue", "http://httpbin.org/get";))))
                 .apply(entity);
 
         String val;
         // explicit value
-        val = entity.invoke(EFFECTOR_HTTPBIN, MutableMap.of("uri", 
"https://httpbin.org/ip";)).get();
+        val = entity.invoke(EFFECTOR_HTTPBIN, MutableMap.of("uri", 
"http://httpbin.org/ip";)).get();
         Assert.assertNotNull(JsonPath.parse(val).read("$.origin", 
String.class));
 
         // default value
         val = entity.invoke(EFFECTOR_HTTPBIN, 
MutableMap.<String,String>of()).get();
-        Assert.assertEquals(JsonPath.parse(val).read("$.url", String.class), 
"https://httpbin.org/get";);
+        Assert.assertEquals(JsonPath.parse(val).read("$.url", String.class), 
"http://httpbin.org/get";);
     }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1c064b28/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorTest.java
 
b/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorTest.java
index 8d620a4..d3d5b7f 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorTest.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorTest.java
@@ -167,6 +167,26 @@ public class HttpCommandEffectorTest extends 
BrooklynAppUnitTestSupport {
    }
 
    @Test
+   public void testPayloadWithContentTypeHeaderYaml() throws 
InterruptedException {
+      server.enqueue((jsonResponse("map-response.json")));
+
+      httpCommandEffector = new HttpCommandEffector(ConfigBag.newInstance()
+              .configure(HttpCommandEffector.EFFECTOR_NAME, 
EFFECTOR_HTTP_COMMAND.getName())
+              .configure(HttpCommandEffector.EFFECTOR_URI, url("/post"))
+              .configure(HttpCommandEffector.EFFECTOR_HTTP_VERB, "POST")
+              .configure(HttpCommandEffector.EFFECTOR_HTTP_PAYLOAD, "my yaml")
+              .configure(HttpCommandEffector.EFFECTOR_HTTP_HEADERS, 
ImmutableMap.of(HttpHeaders.CONTENT_TYPE, "application/yaml"))
+              .configure(HttpCommandEffector.JSON_PATH, "$.data")
+      );
+      assertNotNull(httpCommandEffector);
+      TestEntity testEntity = 
app.createAndManageChild(buildEntitySpec(httpCommandEffector));
+      testEntity.invoke(EFFECTOR_HTTP_COMMAND, ImmutableMap.<String, 
Object>of()).getUnchecked(Duration.minutes(1));
+
+      assertEquals(server.getRequestCount(), 1);
+      assertEquals(new String(server.takeRequest().getBody()), "my yaml");
+   }
+
+   @Test
    public void testPayloadWithoutContentTypeHeader() throws 
InterruptedException {
       server.enqueue(jsonResponse("map-response.json"));
 

Reply via email to