summaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-simulator/src/main
diff options
context:
space:
mode:
authorSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-08-31 11:25:34 +0100
committerSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-09-01 16:48:18 +0100
commit83b5318e545fbc72e3612c4300c4d738b0b577de (patch)
treec4429d0f64b16f510ca00160cd1eb49d91657b45 /participant/participant-impl/participant-impl-simulator/src/main
parentbd376e1dd5e8ccb1893ef244dcd9e4b1a0686150 (diff)
Send ToscaServiceTemplateFragment with policies, policy-types
ToscaServiceTemplateFragment contains policies, policy-types and respective datatypes to be sent to Policy participant, and there on to Policy Framework to create new policies or policy-types that doesnot exist in the database. https://wiki.onap.org/display/DW/The+CLAMP+Policy+Framework+Participant Issue-ID: POLICY-3607 Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech> Change-Id: I2b98d7dc6946b0c27763f1a150d1bf4adca90a2f
Diffstat (limited to 'participant/participant-impl/participant-impl-simulator/src/main')
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java9
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java27
2 files changed, 28 insertions, 8 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
index e84a7fc0a..16da5cf7f 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlConfiguration.java
@@ -22,7 +22,9 @@ package org.onap.policy.clamp.controlloop.participant.simulator.config;
import java.util.List;
import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@@ -30,6 +32,11 @@ public class YamlConfiguration implements WebMvcConfigurer {
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
- converters.add(new YamlHttpMessageConverter<>());
+ converters.add(new YamlHttpMessageConverter<>("yaml"));
+ converters.add(new YamlHttpMessageConverter<>("json"));
+
+ StringHttpMessageConverter converter = new StringHttpMessageConverter();
+ converter.setSupportedMediaTypes(List.of(MediaType.TEXT_PLAIN));
+ converters.add(converter);
}
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java
index 3e1059835..d9a72ce10 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/YamlHttpMessageConverter.java
@@ -23,20 +23,29 @@
package org.onap.policy.clamp.controlloop.participant.simulator.config;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
+import javax.ws.rs.core.Response;
+import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
-import org.yaml.snakeyaml.Yaml;
public class YamlHttpMessageConverter<T> extends AbstractHttpMessageConverter<T> {
- public YamlHttpMessageConverter() {
- super(new MediaType("application", "yaml"));
+ private Coder coder;
+
+ public YamlHttpMessageConverter(String type) {
+ super(new MediaType("application", type, StandardCharsets.UTF_8));
+ this.coder = "json".equals(type) ? new StandardCoder() : new StandardYamlCoder();
}
@Override
@@ -47,16 +56,20 @@ public class YamlHttpMessageConverter<T> extends AbstractHttpMessageConverter<T>
@Override
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
- var yaml = new Yaml();
- return yaml.loadAs(inputMessage.getBody(), clazz);
+ try (var is = new InputStreamReader(inputMessage.getBody(), StandardCharsets.UTF_8)) {
+ return coder.decode(is, clazz);
+ } catch (CoderException e) {
+ throw new ControlLoopRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
+ }
}
@Override
protected void writeInternal(T t, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
- var yaml = new Yaml();
try (var writer = new OutputStreamWriter(outputMessage.getBody(), StandardCharsets.UTF_8)) {
- yaml.dump(t, writer);
+ coder.encode(writer, t);
+ } catch (CoderException e) {
+ throw new ControlLoopRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
}
}
}