Use non-deprecated writeValue()
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / api / ResourceBody.java
index ac4bda4c486e1f40b0572f7b972936de08d534b1..da143d4a2fc19fd6828dc839382f7862c2a121ed 100644 (file)
@@ -14,7 +14,6 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.restconf.restconf.Data;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
@@ -29,7 +28,7 @@ import org.slf4j.LoggerFactory;
  * The body of a resource identified in the request URL, i.e. a {@code PUT} or a plain {@code PATCH} request on RESTCONF
  * data service.
  */
-public abstract sealed class ResourceBody extends AbstractBody permits JsonResourceBody, XmlResourceBody {
+public abstract sealed class ResourceBody extends RequestBody permits JsonResourceBody, XmlResourceBody {
     private static final Logger LOG = LoggerFactory.getLogger(ResourceBody.class);
     private static final NodeIdentifier DATA_NID = NodeIdentifier.create(Data.QNAME);
 
@@ -40,16 +39,16 @@ public abstract sealed class ResourceBody extends AbstractBody permits JsonResou
     /**
      * Acquire the {@link NormalizedNode} representation of this body.
      *
-     * @param path A {@link YangInstanceIdentifier} corresponding to the body
+     * @param path A {@link DatabindPath.Data} corresponding to the body
      * @throws RestconfDocumentedException if the body cannot be decoded or it does not match {@code path}
      */
     @SuppressWarnings("checkstyle:illegalCatch")
-    public @NonNull NormalizedNode toNormalizedNode(final @NonNull DataPutPath path) {
+    public final @NonNull NormalizedNode toNormalizedNode(final DatabindPath.@NonNull Data path) {
         final var instance = path.instance();
         final var expectedName = instance.isEmpty() ? DATA_NID : instance.getLastPathArgument();
         final var holder = new NormalizationResultHolder();
         try (var streamWriter = ImmutableNormalizedNodeStreamWriter.from(holder)) {
-            streamTo(path, expectedName, acquireStream(), streamWriter);
+            streamTo(path, expectedName, consume(), streamWriter);
         } catch (IOException e) {
             LOG.debug("Error reading input", e);
             throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
@@ -58,7 +57,8 @@ public abstract sealed class ResourceBody extends AbstractBody permits JsonResou
             throw e;
         } catch (RuntimeException e) {
             throwIfYangError(e);
-            throw e;
+            throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
+                ErrorTag.MALFORMED_MESSAGE, e);
         }
 
         final var parsedData = holder.getResult().data();
@@ -81,6 +81,6 @@ public abstract sealed class ResourceBody extends AbstractBody permits JsonResou
         return data;
     }
 
-    abstract void streamTo(@NonNull DataPutPath path, @NonNull PathArgument name, @NonNull InputStream inputStream,
-        @NonNull NormalizedNodeStreamWriter writer) throws IOException;
+    abstract void streamTo(DatabindPath.@NonNull Data path, @NonNull PathArgument name,
+        @NonNull InputStream inputStream, @NonNull NormalizedNodeStreamWriter writer) throws IOException;
 }
\ No newline at end of file