summaryrefslogtreecommitdiffstats
path: root/sliPluginUtils/provider/src/main/java
diff options
context:
space:
mode:
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>2019-05-22 15:31:08 +0000
committerKevin Smokowski <kevin.smokowski@att.com>2019-05-22 18:17:40 +0000
commita3d782bc5e0bc07fcc5efd9a118e109011ee2889 (patch)
treec21d826eda26ed09d5d603abed65ab76117bee72 /sliPluginUtils/provider/src/main/java
parent3afef48beebb503e466c611e2b731f3d761e81fb (diff)
add escape and unescape json to SliStringUtils
Add escape and unescape json to SliStringUtils. Can be useful when creating payloads from escaped json or sending payloads that involved escaped json. Change-Id: I736024ef91b5e6fff75374802b0fee2370f12b2f Issue-ID: CCSDK-1353 Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Diffstat (limited to 'sliPluginUtils/provider/src/main/java')
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
index 574178e39..888ef8834 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
@@ -437,4 +437,42 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
source = StringEscapeUtils.escapeXml(source);
ctx.setAttribute(target, source);
}
+
+ /**
+ * unescapeJsonString takes an escaped json string stored as a single property in context memory and unescapes it storing it as a single property
+ * @param parameters - requires source and outputPath to not be null.
+ * @param ctx Reference to context memory
+ * @throws SvcLogicException if a required parameter is missing an exception is thrown
+ */
+ public static void unescapeJsonString(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ SliPluginUtils.checkParameters(parameters, new String[] { INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET }, LOG);
+ try {
+ String source = parameters.get(INPUT_PARAM_SOURCE);
+ String target = parameters.get(INPUT_PARAM_TARGET);
+ String unescapedJson = StringEscapeUtils.unescapeJson(source);
+ ctx.setAttribute(target, unescapedJson);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new SvcLogicException("problem with unescapeJsonString", ex);
+ }
+ }
+
+ /**
+ * escapeJsonString takes json stored as a single string in context memory and escapes it storing it as a single property
+ * @param parameters - requires source and outputPath to not be null.
+ * @param ctx Reference to context memory
+ * @throws SvcLogicException if a required parameter is missing an exception is thrown
+ */
+ public static void escapeJsonString(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ SliPluginUtils.checkParameters(parameters, new String[] { INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET }, LOG);
+ try {
+ String source = parameters.get(INPUT_PARAM_SOURCE);
+ String target = parameters.get(INPUT_PARAM_TARGET);
+ String unescapedJson = StringEscapeUtils.escapeJson(source);
+ ctx.setAttribute(target, unescapedJson);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new SvcLogicException("problem with escapeJsonString", ex);
+ }
+ }
}