import java.io.IOException;
import java.io.InputStream;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.eclipse.jdt.annotation.NonNullByDefault;
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;
* Acquire the {@link NormalizedNode} representation of this 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}
+ * @throws ServerException if the body cannot be decoded or it does not match {@code path}
*/
- @SuppressWarnings("checkstyle:illegalCatch")
- public final @NonNull NormalizedNode toNormalizedNode(final DatabindPath.@NonNull Data path) {
+ public final @NonNull NormalizedNode toNormalizedNode(final DatabindPath.@NonNull Data path)
+ throws ServerException {
final var instance = path.instance();
final var expectedName = instance.isEmpty() ? DATA_NID : instance.getLastPathArgument();
final var holder = new NormalizationResultHolder();
streamTo(path, expectedName, consume(), streamWriter);
} catch (IOException e) {
LOG.debug("Error reading input", e);
- throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
- ErrorTag.MALFORMED_MESSAGE, e);
- } catch (RestconfDocumentedException e) {
- throw e;
- } catch (RuntimeException e) {
- throwIfYangError(e);
- throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
- ErrorTag.MALFORMED_MESSAGE, e);
+ throw path.databind().newProtocolMalformedMessageServerException("Error parsing input", e);
}
final var parsedData = holder.getResult().data();
final var dataName = data.name();
if (!dataName.equals(expectedName)) {
- throw new RestconfDocumentedException(
- "Payload name (" + dataName + ") is different from identifier name (" + expectedName + ")",
- ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
+ throw new ServerException(ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE,
+ "Payload name (%s) is different from identifier name (%s)", dataName, expectedName);
}
return data;
}
- abstract void streamTo(DatabindPath.@NonNull Data path, @NonNull PathArgument name,
- @NonNull InputStream inputStream, @NonNull NormalizedNodeStreamWriter writer) throws IOException;
+ @NonNullByDefault
+ abstract void streamTo(DatabindPath.Data path, PathArgument name, InputStream inputStream,
+ NormalizedNodeStreamWriter writer) throws ServerException;
}
\ No newline at end of file