diff options
Diffstat (limited to 'src/main')
3 files changed, 18 insertions, 4 deletions
diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java index f4efab0d7..fc097bd60 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 @@ package org.onap.clamp.policy; 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 1e35ad6c4..b2f6109f7 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.JsonObject; 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 @@ public class OperationalPolicy implements Serializable, Policy { 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 @@ public class OperationalPolicy implements Serializable, Policy { 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 9ba030786..9874d05cd 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]} |