aboutsummaryrefslogtreecommitdiffstats
path: root/aai-core/src/main
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-12-11 09:21:34 +0100
committerFiete Ostkamp <fiete.ostkamp@telekom.de>2024-12-11 08:27:21 +0000
commit5c2e24008d5b093f86aa5dce8db1336d9211d1d2 (patch)
tree9e60f3f5ec3b76a442206b9b9752e6ec5a616a3e /aai-core/src/main
parent498b357833a128211aac0bf6c4325f0b100b72b6 (diff)
Reduce org.json usage in aai-common
- org.json [is slow](https://github.com/fabienrenaud/java-json-benchmark?tab=readme-ov-file#users-model) - Jackson should be consistently used everywhere - only XmlFormatTransformer is left, but that warrants a dedicated change with (likely) further tests since it appears to be quite a critical execution path - remove unused imports - update org.json to a non-vulnerable version Issue-ID: AAI-4085 Change-Id: I84610523447d70a1729348392ffd302d17e9379d Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'aai-core/src/main')
-rw-r--r--aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java44
-rw-r--r--aai-core/src/main/java/org/onap/aai/kafka/MessageProducer.java36
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java2
3 files changed, 30 insertions, 52 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java b/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java
index 496c1e82..5ecc3a91 100644
--- a/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java
+++ b/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java
@@ -22,30 +22,41 @@ package org.onap.aai.introspection;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
import org.onap.aai.schema.enums.ObjectMetadata;
import org.onap.aai.schema.enums.PropertyMetadata;
import org.onap.aai.setup.SchemaVersion;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
public class JSONStrategy extends Introspector {
- private JSONObject json = null;
+ private JsonNode json = null;
private String namedType = "";
+ private static final ObjectMapper mapper = new ObjectMapper();
protected JSONStrategy(Object o) {
super(o);
- json = (JSONObject) o;
+ json = mapper.valueToTree(o);
// Assumes you provide a wrapper
- Set<String> keySet = json.keySet();
- if (keySet.size() == 1) {
- namedType = keySet.iterator().next();
- json = (JSONObject) json.get(namedType);
+ Iterator<Map.Entry<String, JsonNode>> fields = json.fields();
+ if (fields.hasNext()) {
+ Map.Entry<String, JsonNode> entry = fields.next();
+ if (!fields.hasNext()) {
+ namedType = entry.getKey();
+ json = entry.getValue();
+ } else {
+ throw new IllegalArgumentException("This object has no named type.");
+ }
} else {
throw new IllegalArgumentException("This object has no named type.");
}
@@ -53,7 +64,7 @@ public class JSONStrategy extends Introspector {
protected JSONStrategy(Object o, String namedType) {
super(o);
- json = (JSONObject) o;
+ json = (JsonNode) o;
this.namedType = namedType;
}
@@ -74,8 +85,7 @@ public class JSONStrategy extends Introspector {
@Override
public void setValue(String name, Object obj) {
- json.put(name, obj);
-
+ ((ObjectNode) json).set(name, (JsonNode) obj);
}
@Override
@@ -85,8 +95,14 @@ public class JSONStrategy extends Introspector {
@Override
public Set<String> getProperties() {
- Set<String> result = json.keySet();
- return result;
+ Iterator<String> fieldNames = json.fieldNames();
+ Set<String> properties = new HashSet<>();
+
+ // Iterate through the iterator and add each element to the set
+ while (fieldNames.hasNext()) {
+ properties.add(fieldNames.next());
+ }
+ return properties;
}
@Override
@@ -150,7 +166,7 @@ public class JSONStrategy extends Introspector {
public Class<?> getGenericTypeClass(String name) {
Class<?> resultClass = null;
Object resultObject = this.getValue(name);
- if (resultObject instanceof JSONArray) {
+ if (resultObject instanceof ArrayNode) {
resultClass = ((List<?>) resultObject).get(0).getClass();
}
diff --git a/aai-core/src/main/java/org/onap/aai/kafka/MessageProducer.java b/aai-core/src/main/java/org/onap/aai/kafka/MessageProducer.java
deleted file mode 100644
index 09fc68a2..00000000
--- a/aai-core/src/main/java/org/onap/aai/kafka/MessageProducer.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.aai.kafka;
-
-import org.json.JSONObject;
-
-/**
- * MessageProducer interface based on untyped messages
- *
- * @deprecated use {@link org.onap.aai.kafka.NotificationProducer} instead
- */
-@Deprecated
-public interface MessageProducer {
-
- void sendMessageToDefaultDestination(JSONObject finalJson);
-
- void sendMessageToDefaultDestination(String msg);
-}
diff --git a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java
index b31bfcb8..23201593 100644
--- a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java
+++ b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java
@@ -39,9 +39,7 @@ import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.apache.commons.configuration2.JSONConfiguration;
import org.glassfish.jersey.client.ClientConfig;
-import org.glassfish.jersey.client.ClientProperties;
import org.onap.aai.aailog.filter.RestControllerClientRequestLoggingInterceptor;
import org.onap.aai.aailog.filter.RestControllerClientResponseLoggingInterceptor;
import org.onap.aai.exceptions.AAIException;