Add support for RFC8072 media types 87/96287/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 20 May 2021 11:52:41 +0000 (13:52 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 20 May 2021 11:55:08 +0000 (13:55 +0200)
The media type assignments have changed in draft-ietf-netconf-yang-patch-09,
make sure we support the new assignements.

JIRA: NETCONF-780
Change-Id: I00484ccf2536c598bca54207154025006742aea8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonToPatchBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/PatchJsonBodyWriter.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/PatchXmlBodyWriter.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlToPatchBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfDataService.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RootResourceDiscoveryService.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfOperationsService.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfService.java

index 228ce0a4b0dd4c39c32eac486e9cbee444cfc45d..c736e0de9c85b868e9995b2e898e17c89a5edfb1 100644 (file)
@@ -49,8 +49,12 @@ public final class Rfc8040 {
         public static final String XRD = "application/xrd";
 
         public static final String DATA = "application/yang-data";
+        // up to and including draft-ietf-netconf-yang-patch-08
         public static final String YANG_PATCH = "application/yang.patch";
         public static final String YANG_PATCH_STATUS = "application/yang.patch-status";
+
+        // since draft-ietf-netconf-yang-patch-09
+        public static final String YANG_PATCH_RFC8072 = "application/yang-patch";
     }
 
     /**
index d79b14e1022d94d6d94001ceb4529b043a6357a4..2f525b81f7841377975c022cb71692cabe251b36 100644 (file)
@@ -63,6 +63,10 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
     static final MediaType YANG_PATCH_JSON_TYPE = MediaType.valueOf(MediaTypes.YANG_PATCH + RestconfConstants.JSON);
     @VisibleForTesting
     static final MediaType YANG_PATCH_XML_TYPE = MediaType.valueOf(MediaTypes.YANG_PATCH + RestconfConstants.XML);
+    private static final MediaType YANG_PATCH_RFC8072_JSON_TYPE =
+        MediaType.valueOf(MediaTypes.YANG_PATCH_RFC8072 + RestconfConstants.JSON);
+    private static final MediaType YANG_PATCH_RFC8072_XML_TYPE =
+        MediaType.valueOf(MediaTypes.YANG_PATCH_RFC8072 + RestconfConstants.XML);
 
     private static final Logger LOG = LoggerFactory.getLogger(RestconfDocumentedExceptionMapper.class);
     private static final MediaType DEFAULT_MEDIA_TYPE = MediaType.APPLICATION_JSON_TYPE;
@@ -359,12 +363,16 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
 
     private static boolean isJsonCompatibleMediaType(final MediaType mediaType) {
         return mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE)
-                || mediaType.isCompatible(YANG_DATA_JSON_TYPE) || mediaType.isCompatible(YANG_PATCH_JSON_TYPE);
+                || mediaType.isCompatible(YANG_DATA_JSON_TYPE)
+                || mediaType.isCompatible(YANG_PATCH_RFC8072_JSON_TYPE)
+                || mediaType.isCompatible(YANG_PATCH_JSON_TYPE);
     }
 
     private static boolean isXmlCompatibleMediaType(final MediaType mediaType) {
         return mediaType.isCompatible(MediaType.APPLICATION_XML_TYPE)
-                || mediaType.isCompatible(YANG_DATA_XML_TYPE) || mediaType.isCompatible(YANG_PATCH_XML_TYPE);
+                || mediaType.isCompatible(YANG_DATA_XML_TYPE)
+                || mediaType.isCompatible(YANG_PATCH_RFC8072_XML_TYPE)
+                || mediaType.isCompatible(YANG_PATCH_XML_TYPE);
     }
 
     /**
index 7af23cf7dba858939a09334d939d1a778370f31e..71f48a4734e9c7dac5c922cb93257d87642f9ba6 100644 (file)
@@ -55,7 +55,10 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Provider
-@Consumes({Rfc8040.MediaTypes.YANG_PATCH + RestconfConstants.JSON})
+@Consumes({
+    Rfc8040.MediaTypes.YANG_PATCH + RestconfConstants.JSON,
+    Rfc8040.MediaTypes.YANG_PATCH_RFC8072 + RestconfConstants.JSON
+})
 public class JsonToPatchBodyReader extends AbstractToPatchBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(JsonToPatchBodyReader.class);
 
index 99710ce87f7ede8b540b2769a6fa4e058d58475a..1eeab2b5345c0338ce37686c900105fca9582cee 100644 (file)
@@ -25,13 +25,12 @@ import javax.ws.rs.ext.Provider;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MediaTypes;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.yangtools.yang.data.codec.gson.JsonWriterFactory;
 
-
 @Provider
-@Produces({ Rfc8040.MediaTypes.YANG_PATCH_STATUS + RestconfConstants.JSON })
+@Produces({ MediaTypes.YANG_PATCH_STATUS + RestconfConstants.JSON, MediaTypes.DATA + RestconfConstants.JSON })
 public class PatchJsonBodyWriter implements MessageBodyWriter<PatchStatusContext> {
 
     @Override
index 0d6ce8455a852dc2c7bc7881e9cfae134e717eea..d56127ebcc9418e204a0f916075602ac43820c92 100644 (file)
@@ -26,11 +26,11 @@ import javax.xml.stream.XMLStreamWriter;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MediaTypes;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 
 @Provider
-@Produces({ Rfc8040.MediaTypes.YANG_PATCH_STATUS + RestconfConstants.XML })
+@Produces({ MediaTypes.YANG_PATCH_STATUS + RestconfConstants.XML, MediaTypes.DATA + RestconfConstants.XML })
 public class PatchXmlBodyWriter implements MessageBodyWriter<PatchStatusContext> {
 
     private static final XMLOutputFactory XML_FACTORY;
index 49b4222e2fca888c22217b1b196ea0ff44a640b7..9351411b5e6d5ed1513e5ad8e06d96b2958e1498 100644 (file)
@@ -62,13 +62,16 @@ import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
 @Provider
-@Consumes({Rfc8040.MediaTypes.YANG_PATCH + RestconfConstants.XML})
+@Consumes({
+    Rfc8040.MediaTypes.YANG_PATCH + RestconfConstants.XML,
+    Rfc8040.MediaTypes.YANG_PATCH_RFC8072 + RestconfConstants.XML
+})
 public class XmlToPatchBodyReader extends AbstractToPatchBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(XmlToPatchBodyReader.class);
     private static final Splitter SLASH_SPLITTER = Splitter.on('/');
 
-    public XmlToPatchBodyReader(SchemaContextHandler schemaContextHandler,
-            DOMMountPointServiceHandler mountPointServiceHandler) {
+    public XmlToPatchBodyReader(final SchemaContextHandler schemaContextHandler,
+            final DOMMountPointServiceHandler mountPointServiceHandler) {
         super(schemaContextHandler, mountPointServiceHandler);
     }
 
index dbad05a6ca4d3ace39164b1695f106d302434dee..570dcb83fac826e8c6529a9c4298268544951029 100644 (file)
@@ -168,10 +168,14 @@ public interface RestconfDataService extends UpdateHandlers {
     @Patch
     @Path("/data/{identifier:.+}")
     @Consumes({
+        Rfc8040.MediaTypes.YANG_PATCH_RFC8072 + RestconfConstants.JSON,
+        Rfc8040.MediaTypes.YANG_PATCH_RFC8072 + RestconfConstants.XML,
         Rfc8040.MediaTypes.YANG_PATCH + RestconfConstants.JSON,
-        Rfc8040.MediaTypes.YANG_PATCH + RestconfConstants.XML
+        Rfc8040.MediaTypes.YANG_PATCH + RestconfConstants.XML,
     })
     @Produces({
+        Rfc8040.MediaTypes.DATA + RestconfConstants.JSON,
+        Rfc8040.MediaTypes.DATA + RestconfConstants.XML,
         Rfc8040.MediaTypes.YANG_PATCH_STATUS + RestconfConstants.JSON,
         Rfc8040.MediaTypes.YANG_PATCH_STATUS + RestconfConstants.XML
     })
@@ -190,16 +194,19 @@ public interface RestconfDataService extends UpdateHandlers {
     @Patch
     @Path("/data")
     @Consumes({
+        Rfc8040.MediaTypes.YANG_PATCH_RFC8072 + RestconfConstants.JSON,
+        Rfc8040.MediaTypes.YANG_PATCH_RFC8072 + RestconfConstants.XML,
         Rfc8040.MediaTypes.YANG_PATCH + RestconfConstants.JSON,
         Rfc8040.MediaTypes.YANG_PATCH + RestconfConstants.XML
     })
     @Produces({
+        Rfc8040.MediaTypes.DATA + RestconfConstants.JSON,
+        Rfc8040.MediaTypes.DATA + RestconfConstants.XML,
         Rfc8040.MediaTypes.YANG_PATCH_STATUS + RestconfConstants.JSON,
         Rfc8040.MediaTypes.YANG_PATCH_STATUS + RestconfConstants.XML
     })
     PatchStatusContext patchData(PatchContext context, @Context UriInfo uriInfo);
 
-
     /**
      * Partially modify the target data resource.
      *
index f670b8be105fd0e3334134561a569905a126307e..1eb3d34a271f28010fb7731fb2fc743a0c1d761f 100644 (file)
@@ -10,8 +10,9 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.api;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MediaTypes;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 
 /**
@@ -27,7 +28,7 @@ public interface RootResourceDiscoveryService {
      */
     @GET
     @Path("/host-meta")
-    @Produces({Rfc8040.MediaTypes.XRD + RestconfConstants.XML})
+    @Produces({ MediaTypes.XRD + RestconfConstants.XML })
     Response readXrdData();
 
     /**
@@ -35,6 +36,6 @@ public interface RootResourceDiscoveryService {
      */
     @GET
     @Path("/host-meta.json")
-    @Produces({Rfc8040.MediaTypes.XRD + RestconfConstants.JSON})
+    @Produces({ MediaTypes.XRD + RestconfConstants.JSON, MediaType.APPLICATION_JSON })
     Response readJsonData();
 }
index a1f8103c1f4b9bcee0e95d8417e75b5240cb88ca..3026d08b08cfe59775fd5d5b7c18c21137c6c3af 100644 (file)
@@ -33,6 +33,7 @@ public interface RestconfOperationsService extends UpdateHandlers {
     @Path("/operations")
     @Produces({
         Rfc8040.MediaTypes.DATA + RestconfConstants.JSON,
+        Rfc8040.MediaTypes.DATA + RestconfConstants.XML,
         Rfc8040.MediaTypes.DATA,
         MediaType.APPLICATION_JSON,
         MediaType.APPLICATION_XML,
@@ -53,6 +54,7 @@ public interface RestconfOperationsService extends UpdateHandlers {
     @Path("/operations/{identifier:.+}")
     @Produces({
         Rfc8040.MediaTypes.DATA + RestconfConstants.JSON,
+        Rfc8040.MediaTypes.DATA + RestconfConstants.XML,
         Rfc8040.MediaTypes.DATA,
         MediaType.APPLICATION_JSON,
         MediaType.APPLICATION_XML,
index de7e2aaa05452b23b1a2a8542ede4a46fe828673..3746907b4cf39f26736254bf41de2c72d27b41e9 100644 (file)
@@ -28,6 +28,7 @@ public interface RestconfService extends UpdateHandlers {
     @Path("/yang-library-version")
     @Produces({
         Rfc8040.MediaTypes.DATA + RestconfConstants.JSON,
+        Rfc8040.MediaTypes.DATA + RestconfConstants.XML,
         Rfc8040.MediaTypes.DATA,
         MediaType.APPLICATION_JSON,
         MediaType.APPLICATION_XML,