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;
* 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);
/**
* 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,
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();
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