Remove "/" sign in AbstractRestconfStreamRegistry
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / api / RequestBody.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.server.api;
9
10 import java.io.InputStream;
11 import org.opendaylight.restconf.api.ConsumableBody;
12 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
13 import org.opendaylight.restconf.common.errors.RestconfError;
14 import org.opendaylight.yangtools.yang.data.api.YangNetconfError;
15 import org.opendaylight.yangtools.yang.data.api.YangNetconfErrorAware;
16
17 /**
18  * An abstract request body backed by an {@link InputStream}. In controls the access to input stream, so that it can
19  * only be taken once.
20  */
21 abstract sealed class RequestBody extends ConsumableBody
22         permits ChildBody, DataPostBody, OperationInputBody, PatchBody, ResourceBody {
23     RequestBody(final InputStream inputStream) {
24         super(inputStream);
25     }
26
27     /**
28      * Throw a {@link RestconfDocumentedException} if the specified exception has a {@link YangNetconfError} attachment.
29      *
30      * @param cause Proposed cause of a RestconfDocumentedException
31      */
32     static void throwIfYangError(final Exception cause) {
33         if (cause instanceof YangNetconfErrorAware infoAware) {
34             throw new RestconfDocumentedException(cause, infoAware.getNetconfErrors().stream()
35                 .map(error -> new RestconfError(error.type(), error.tag(), error.message(), error.appTag(),
36                     // FIXME: pass down error info
37                     null, error.path()))
38                 .toList());
39         }
40     }
41 }