Change Yaml to Json payload

Change the operational policy payload from Yaml to a JSon, yaml being
embedded as URLEncoded

Issue-ID: CLAMP-359
Change-Id: I8c97bb155e6136ce37c29a65a7d9d85e21fedd61
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java
index f4efab0..fc097bd 100644
--- a/src/main/java/org/onap/clamp/policy/Policy.java
+++ b/src/main/java/org/onap/clamp/policy/Policy.java
@@ -25,13 +25,15 @@
 
 import com.google.gson.JsonObject;
 
+import java.io.UnsupportedEncodingException;
+
 public interface Policy {
 
     String getName();
 
     JsonObject getJsonRepresentation();
 
-    String createPolicyPayload();
+    String createPolicyPayload() throws UnsupportedEncodingException;
 
     /**
      * Generate the policy name.
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
index 1e35ad6..b2f6109 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -31,6 +31,9 @@
 import com.google.gson.annotations.Expose;
 
 import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -150,8 +153,7 @@
         return true;
     }
 
-    @Override
-    public String createPolicyPayload() {
+    public String createPolicyPayloadYaml() {
         JsonObject policyPayloadResult = new JsonObject();
 
         policyPayloadResult.addProperty("tosca_definitions_version", "tosca_simple_yaml_1_0_0");
@@ -181,6 +183,16 @@
         return (new Yaml()).dump(jsonMap);
     }
 
+    @Override
+    public String createPolicyPayload() throws UnsupportedEncodingException {
+
+        // Now the Yaml payload must be injected in a json ...
+        JsonObject payload = new JsonObject();
+        payload.addProperty("policy-id", this.getName());
+        payload.addProperty("content", URLEncoder.encode(createPolicyPayloadYaml(), StandardCharsets.UTF_8.toString()));
+        return new GsonBuilder().setPrettyPrinting().create().toJson(payload);
+    }
+
     /**
      * Return a map containing all Guard policies indexed by Guard policy Name.
      *
diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml
index 9ba0307..9874d05 100644
--- a/src/main/resources/clds/camel/routes/flexible-flow.xml
+++ b/src/main/resources/clds/camel/routes/flexible-flow.xml
@@ -210,7 +210,7 @@
 				<constant>POST</constant>
 			</setHeader>
 			<setHeader headerName="Content-Type">
-				<constant>application/yaml; vnd.onap.operational</constant>
+				<constant>application/json</constant>
 			</setHeader>
 			<setHeader headerName="X-ONAP-RequestID">
 				<simple>${exchangeProperty[X-ONAP-RequestID]}