summaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/container/handler
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorn.christian@seime.no>2021-02-01 23:51:00 +0100
committerGitHub <noreply@github.com>2021-02-01 23:51:00 +0100
commit42794e42e8ce223705e0a8e0e3e9293d65adaf6c (patch)
treea337188686fe568fd0dc04db5234c7ffa2ccbb63 /container-core/src/main/java/com/yahoo/container/handler
parent7f04da806204b7727f377b4099bd10571c61e5da (diff)
Revert "Remove org.json usage [run-systemtest]"
Diffstat (limited to 'container-core/src/main/java/com/yahoo/container/handler')
-rw-r--r--container-core/src/main/java/com/yahoo/container/handler/metrics/HttpHandlerBase.java23
1 files changed, 10 insertions, 13 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/metrics/HttpHandlerBase.java b/container-core/src/main/java/com/yahoo/container/handler/metrics/HttpHandlerBase.java
index 8c902f88e38..92840cee48f 100644
--- a/container-core/src/main/java/com/yahoo/container/handler/metrics/HttpHandlerBase.java
+++ b/container-core/src/main/java/com/yahoo/container/handler/metrics/HttpHandlerBase.java
@@ -1,14 +1,13 @@
// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.handler.metrics;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.jdisc.ThreadedHttpRequestHandler;
import com.yahoo.restapi.Path;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import java.net.URI;
import java.util.List;
@@ -27,8 +26,6 @@ import static java.util.logging.Level.WARNING;
*/
public abstract class HttpHandlerBase extends ThreadedHttpRequestHandler {
- private static final ObjectMapper jsonMapper = new ObjectMapper();
-
protected HttpHandlerBase(Executor executor) {
super(executor);
}
@@ -52,14 +49,15 @@ public abstract class HttpHandlerBase extends ThreadedHttpRequestHandler {
protected JsonResponse resourceListResponse(URI requestUri, List<String> resources) {
try {
return new JsonResponse(OK, resourceList(requestUri, resources));
- } catch (JsonProcessingException e) {
+ } catch (JSONException e) {
log.log(WARNING, "Bad JSON construction in generated resource list for " + requestUri.getPath(), e);
return new ErrorResponse(INTERNAL_SERVER_ERROR,
"An error occurred when generating the list of api resources.");
}
}
- private static String resourceList(URI requestUri, List<String> resources) throws JsonProcessingException {
+ // TODO: Use jackson with a "Resources" class instead of JSONObject
+ private static String resourceList(URI requestUri, List<String> resources) throws JSONException {
int port = requestUri.getPort();
String host = requestUri.getHost();
StringBuilder base = new StringBuilder("http://");
@@ -68,14 +66,13 @@ public abstract class HttpHandlerBase extends ThreadedHttpRequestHandler {
base.append(":").append(port);
}
String uriBase = base.toString();
- ArrayNode linkList = jsonMapper.createArrayNode();
+ JSONArray linkList = new JSONArray();
for (String api : resources) {
- ObjectNode resource = jsonMapper.createObjectNode();
+ JSONObject resource = new JSONObject();
resource.put("url", uriBase + api);
- linkList.add(resource);
+ linkList.put(resource);
}
- return jsonMapper.writerWithDefaultPrettyPrinter()
- .writeValueAsString(jsonMapper.createObjectNode().set("resources", linkList));
+ return new JSONObject().put("resources", linkList).toString(4);
}
}