From 61fb3d2a1569ac605e10590045fac2eb7a6e09f9 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Wed, 14 Jun 2017 14:14:24 +0200 Subject: [PATCH 1/1] Bug 5995: remove org.json This switches sal-rest-connector to Jackson and Gson and cleans up the features. Change-Id: I587ab4638374fccb344e9a769ee2793e16863fef Signed-off-by: Stephen Kitt --- features/restconf/features-restconf/pom.xml | 9 ++-- .../src/main/features/features.xml | 5 ++- features/restconf/odl-mdsal-apidocs/pom.xml | 44 ------------------- features/restconf/odl-restconf-noauth/pom.xml | 12 ----- restconf/sal-rest-connector/pom.xml | 12 ++--- .../streams/listeners/ListenerAdapter.java | 14 ++++-- .../NotificationListenerAdapter.java | 10 +++-- 7 files changed, 29 insertions(+), 77 deletions(-) diff --git a/features/restconf/features-restconf/pom.xml b/features/restconf/features-restconf/pom.xml index d45fe415f1..ae922a5d95 100644 --- a/features/restconf/features-restconf/pom.xml +++ b/features/restconf/features-restconf/pom.xml @@ -135,8 +135,9 @@ jackson-databind - com.fasterxml.jackson.datatype - jackson-datatype-json-org + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.3.2 com.fasterxml.jackson.module @@ -150,10 +151,6 @@ com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider - - org.json - json - org.opendaylight.yangtools diff --git a/features/restconf/features-restconf/src/main/features/features.xml b/features/restconf/features-restconf/src/main/features/features.xml index 77c9687fba..cc371cde3a 100644 --- a/features/restconf/features-restconf/src/main/features/features.xml +++ b/features/restconf/features-restconf/src/main/features/features.xml @@ -37,6 +37,9 @@ mvn:com.google.code.gson/gson/{{VERSION}} mvn:org.opendaylight.yangtools/yang-data-codec-gson/{{VERSION}} mvn:org.opendaylight.yangtools/yang-model-export/{{VERSION}} + mvn:com.fasterxml.jackson.dataformat/jackson-dataformat-xml/{{VERSION}} + mvn:org.codehaus.woodstox/stax2-api/{{VERSION}} + wrap:mvn:javax.xml.stream/stax-api/{{VERSION}} mvn:org.opendaylight.netconf/sal-rest-connector-config/{{VERSION}}/xml/config mvn:org.opendaylight.netconf/sal-rest-connector-config/{{VERSION}}/xml/configrestconfservice @@ -46,14 +49,12 @@ mvn:com.fasterxml.jackson.core/jackson-annotations/{{VERSION}} mvn:com.fasterxml.jackson.core/jackson-core/{{VERSION}} mvn:com.fasterxml.jackson.core/jackson-databind/{{VERSION}} - mvn:com.fasterxml.jackson.datatype/jackson-datatype-json-org/{{VERSION}} mvn:com.fasterxml.jackson.module/jackson-module-jaxb-annotations/{{VERSION}} mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-base/{{VERSION}} mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/{{VERSION}} mvn:com.sun.jersey/jersey-core/{{VERSION}} mvn:com.sun.jersey/jersey-server/{{VERSION}} mvn:com.sun.jersey/jersey-servlet/{{VERSION}} - wrap:mvn:org.json/json/{{VERSION}} diff --git a/features/restconf/odl-mdsal-apidocs/pom.xml b/features/restconf/odl-mdsal-apidocs/pom.xml index 6944837c75..3aa0f2d136 100644 --- a/features/restconf/odl-mdsal-apidocs/pom.xml +++ b/features/restconf/odl-mdsal-apidocs/pom.xml @@ -38,49 +38,5 @@ sal-rest-docgen ${project.version} - - com.fasterxml.jackson.core - jackson-annotations - - - com.fasterxml.jackson.core - jackson-core - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.datatype - jackson-datatype-json-org - - - com.fasterxml.jackson.module - jackson-module-jaxb-annotations - - - com.fasterxml.jackson.jaxrs - jackson-jaxrs-base - - - com.fasterxml.jackson.jaxrs - jackson-jaxrs-json-provider - - - com.sun.jersey - jersey-core - - - com.sun.jersey - jersey-server - - - com.sun.jersey - jersey-servlet - - - org.json - json - \ No newline at end of file diff --git a/features/restconf/odl-restconf-noauth/pom.xml b/features/restconf/odl-restconf-noauth/pom.xml index 9d8fe92084..9b6da60170 100644 --- a/features/restconf/odl-restconf-noauth/pom.xml +++ b/features/restconf/odl-restconf-noauth/pom.xml @@ -115,18 +115,6 @@ org.opendaylight.netconf sal-rest-connector - - com.google.code.gson - gson - - - org.opendaylight.yangtools - yang-data-codec-gson - - - org.opendaylight.yangtools - yang-model-export - org.opendaylight.netconf diff --git a/restconf/sal-rest-connector/pom.xml b/restconf/sal-rest-connector/pom.xml index a332a5f69d..508eb0b4c0 100644 --- a/restconf/sal-rest-connector/pom.xml +++ b/restconf/sal-rest-connector/pom.xml @@ -146,17 +146,19 @@ net.java.dev.stax-utils stax-utils + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + 2.3.2 + ch.qos.logback logback-classic test - - org.json - json - - org.glassfish.jersey.test-framework.providers diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/ListenerAdapter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/ListenerAdapter.java index 8a2ab0511e..832aaf2481 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/ListenerAdapter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/ListenerAdapter.java @@ -7,15 +7,16 @@ */ package org.opendaylight.netconf.sal.streams.listeners; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.google.common.base.Preconditions; +import com.google.common.base.Throwables; import java.io.IOException; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import javax.xml.stream.XMLStreamException; import javax.xml.transform.dom.DOMResult; -import org.json.JSONObject; -import org.json.XML; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener; import org.opendaylight.netconf.sal.restconf.impl.ControllerContext; @@ -117,8 +118,13 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements DOMData private void prepareAndPostData(final String xml) { final Event event = new Event(EventType.NOTIFY); if (this.outputType.equals(NotificationOutputType.JSON)) { - final JSONObject jsonObject = XML.toJSONObject(xml); - event.setData(jsonObject.toString()); + try { + JsonNode node = new XmlMapper().readTree(xml.getBytes()); + event.setData(node.toString()); + } catch (IOException e) { + LOG.error("Error parsing XML {}", xml, e); + Throwables.propagate(e); + } } else { event.setData(xml); } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java index cdf1ff2645..a5999ddfac 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java @@ -9,6 +9,8 @@ package org.opendaylight.netconf.sal.streams.listeners; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import java.io.IOException; import java.io.StringWriter; import java.io.Writer; @@ -16,7 +18,6 @@ import java.time.Instant; import java.util.Collection; import javax.xml.stream.XMLStreamException; import javax.xml.transform.dom.DOMResult; -import org.json.JSONObject; import org.opendaylight.controller.md.sal.dom.api.DOMNotification; import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener; import org.opendaylight.netconf.sal.restconf.impl.ControllerContext; @@ -137,9 +138,10 @@ public class NotificationListenerAdapter extends AbstractCommonSubscriber implem */ @VisibleForTesting String prepareJson() { - final JSONObject json = new JSONObject(); - json.put("ietf-restconf:notification", - new JSONObject(writeBodyToString()).put("event-time", ListenerAdapter.toRFC3339(Instant.now()))); + JsonParser jsonParser = new JsonParser(); + JsonObject json = new JsonObject(); + json.add("ietf-restconf:notification", jsonParser.parse(writeBodyToString())); + json.addProperty("event-time", ListenerAdapter.toRFC3339(Instant.now())); return json.toString(); } -- 2.36.6