You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:25:36 UTC

[sling-org-apache-sling-extensions-slf4j-mdc] 20/21: SLING-6934: Remove org.json from slf4j-mdc

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-extensions-slf4j-mdc.git

commit 47d521c2b9fd38f5ad2ec09c08978e079492f5e8
Author: Karl Pauls <pa...@apache.org>
AuthorDate: Fri Jun 2 21:59:53 2017 +0000

    SLING-6934: Remove org.json from slf4j-mdc
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1797463 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                              |  6 +++---
 .../extensions/mdc/integration/ITMDCFilter.java      | 11 +++++++----
 .../mdc/integration/ServerConfiguration.java         |  2 +-
 .../mdc/integration/servlet/MDCStateServlet.java     | 20 +++++++++++++++++---
 4 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/pom.xml b/pom.xml
index 63310e8..ae15722 100644
--- a/pom.xml
+++ b/pom.xml
@@ -209,9 +209,9 @@
       <version>4.10</version>
     </dependency>
     <dependency>
-      <groupId>org.json</groupId>
-      <artifactId>json</artifactId>
-      <version>20070829</version>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.commons.johnzon</artifactId>
+      <version>1.0.0</version>
       <scope>test</scope>
     </dependency>
     <dependency>
diff --git a/src/test/java/org/apache/sling/extensions/mdc/integration/ITMDCFilter.java b/src/test/java/org/apache/sling/extensions/mdc/integration/ITMDCFilter.java
index 4bb7017..95cab61 100644
--- a/src/test/java/org/apache/sling/extensions/mdc/integration/ITMDCFilter.java
+++ b/src/test/java/org/apache/sling/extensions/mdc/integration/ITMDCFilter.java
@@ -25,7 +25,6 @@ import org.apache.sling.testing.tools.http.RequestBuilder;
 import org.apache.sling.testing.tools.http.RequestCustomizer;
 import org.apache.sling.testing.tools.http.RequestExecutor;
 import org.apache.sling.testing.tools.retry.RetryLoop;
-import org.json.JSONObject;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
@@ -39,8 +38,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.io.StringReader;
 import java.util.concurrent.TimeUnit;
 
+import javax.json.Json;
+import javax.json.JsonObject;
+
 import static junit.framework.Assert.assertNull;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -85,7 +88,7 @@ public class ITMDCFilter {
         RequestExecutor result = executor.execute(
                 rb.buildGetRequest("/mdc","foo","bar"));
 
-        JSONObject jb = new JSONObject(result.getContent());
+        JsonObject jb = Json.createReader(new StringReader(result.getContent())).readObject();
         assertEquals("/mdc", jb.getString("req.requestURI"));
         assertEquals("foo=bar", jb.getString("req.queryString"));
         assertEquals(ServerConfiguration.getServerUrl() + "/mdc", jb.getString("req.requestURL"));
@@ -113,7 +116,7 @@ public class ITMDCFilter {
                         .withHeader("mdc-test-header", "foo-test-header")
         );
 
-        JSONObject jb = new JSONObject(result.getContent());
+        JsonObject jb = Json.createReader(new StringReader(result.getContent())).readObject();
         log.info("Response  {}",result.getContent());
 
         assertEquals("/mdc", jb.getString("req.requestURI"));
@@ -124,7 +127,7 @@ public class ITMDCFilter {
         assertEquals("foo-test-cookie", jb.getString("mdc-test-cookie"));
 
         //Only configured params must be returned
-        assertFalse(jb.has("ignored-param"));
+        assertFalse(jb.containsKey("ignored-param"));
     }
 
 
diff --git a/src/test/java/org/apache/sling/extensions/mdc/integration/ServerConfiguration.java b/src/test/java/org/apache/sling/extensions/mdc/integration/ServerConfiguration.java
index 95f7156..f6a0bdc 100644
--- a/src/test/java/org/apache/sling/extensions/mdc/integration/ServerConfiguration.java
+++ b/src/test/java/org/apache/sling/extensions/mdc/integration/ServerConfiguration.java
@@ -87,7 +87,7 @@ public class ServerConfiguration {
                 mavenBundle("org.apache.felix", "org.apache.felix.http.jetty").versionAsInProject().startLevel(3),
                 mavenBundle("org.apache.felix", "org.apache.felix.http.whiteboard").versionAsInProject().startLevel(5),
                 mavenBundle("org.apache.felix", "org.apache.felix.scr").versionAsInProject(),
-                wrappedBundle(mavenBundle("org.json", "json").versionAsInProject()),
+                mavenBundle("org.apache.sling", "org.apache.sling.commons.johnzon").versionAsInProject(),
                 systemProperty("pax.exam.osgi.unresolved.fail").value("fail"),
                 systemProperty("org.osgi.service.http.port").value(getServerPort()),
                 cleanCaches(),
diff --git a/src/test/java/org/apache/sling/extensions/mdc/integration/servlet/MDCStateServlet.java b/src/test/java/org/apache/sling/extensions/mdc/integration/servlet/MDCStateServlet.java
index e86d5ef..c01b7c7 100644
--- a/src/test/java/org/apache/sling/extensions/mdc/integration/servlet/MDCStateServlet.java
+++ b/src/test/java/org/apache/sling/extensions/mdc/integration/servlet/MDCStateServlet.java
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.extensions.mdc.integration.servlet;
 
-import org.json.JSONObject;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.cm.Configuration;
@@ -26,6 +25,9 @@ import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.MDC;
 
+import javax.json.Json;
+import javax.json.JsonObject;
+import javax.json.stream.JsonGenerator;
 import javax.servlet.Servlet;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -33,9 +35,12 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.StringReader;
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.Map;
 import java.util.Properties;
+import java.util.Map.Entry;
 
 public class MDCStateServlet extends HttpServlet implements BundleActivator{
     private ServiceTracker configAdminTracker;
@@ -62,8 +67,17 @@ public class MDCStateServlet extends HttpServlet implements BundleActivator{
             return;
         }
 
-        JSONObject jb = new JSONObject(MDC.getCopyOfContextMap());
-        pw.print(jb.toString());
+        Map<String, String> copyOfContextMap = MDC.getCopyOfContextMap();
+        JsonGenerator json = Json.createGenerator(pw);
+        json.writeStartObject();
+        if (copyOfContextMap != null) {
+            for (Entry<String, String> entry : copyOfContextMap.entrySet())
+            {
+                json.write(entry.getKey(), entry.getValue());
+            }
+        }
+        json.writeEnd();
+        json.flush();
     }
 
     private void createTestConfig() throws IOException {

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.