From 3e74785ba264a1b457dbfdf618c69c630781e13e Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 20 May 2021 13:52:41 +0200 Subject: [PATCH] Add support for RFC8072 media types 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 --- .../opendaylight/restconf/nb/rfc8040/Rfc8040.java | 4 ++++ .../errors/RestconfDocumentedExceptionMapper.java | 12 ++++++++++-- .../providers/patch/JsonToPatchBodyReader.java | 5 ++++- .../jersey/providers/patch/PatchJsonBodyWriter.java | 5 ++--- .../jersey/providers/patch/PatchXmlBodyWriter.java | 4 ++-- .../jersey/providers/patch/XmlToPatchBodyReader.java | 9 ++++++--- .../rests/services/api/RestconfDataService.java | 11 +++++++++-- .../services/api/RootResourceDiscoveryService.java | 7 ++++--- .../simple/api/RestconfOperationsService.java | 2 ++ .../rfc8040/services/simple/api/RestconfService.java | 1 + 10 files changed, 44 insertions(+), 16 deletions(-) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040.java index 228ce0a4b0..c736e0de9c 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040.java @@ -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"; } /** diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java index d79b14e102..2f525b81f7 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/errors/RestconfDocumentedExceptionMapper.java @@ -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); } /** diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonToPatchBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonToPatchBodyReader.java index 7af23cf7db..71f48a4734 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonToPatchBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonToPatchBodyReader.java @@ -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); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/PatchJsonBodyWriter.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/PatchJsonBodyWriter.java index 99710ce87f..1eeab2b534 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/PatchJsonBodyWriter.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/PatchJsonBodyWriter.java @@ -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 { @Override diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/PatchXmlBodyWriter.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/PatchXmlBodyWriter.java index 0d6ce8455a..d56127ebcc 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/PatchXmlBodyWriter.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/PatchXmlBodyWriter.java @@ -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 { private static final XMLOutputFactory XML_FACTORY; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlToPatchBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlToPatchBodyReader.java index 49b4222e2f..9351411b5e 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlToPatchBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlToPatchBodyReader.java @@ -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); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfDataService.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfDataService.java index dbad05a6ca..570dcb83fa 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfDataService.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfDataService.java @@ -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. * diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RootResourceDiscoveryService.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RootResourceDiscoveryService.java index f670b8be10..1eb3d34a27 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RootResourceDiscoveryService.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RootResourceDiscoveryService.java @@ -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(); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfOperationsService.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfOperationsService.java index a1f8103c1f..3026d08b08 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfOperationsService.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfOperationsService.java @@ -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, diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfService.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfService.java index de7e2aaa05..3746907b4c 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfService.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/api/RestconfService.java @@ -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, -- 2.36.6