diff --git a/apps/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/AbstractResourceBodyTest.java b/apps/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/AbstractResourceBodyTest.java index cf325020dd0..4629e27cb29 100644 --- a/apps/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/AbstractResourceBodyTest.java +++ b/apps/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/AbstractResourceBodyTest.java @@ -25,10 +25,10 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.netconf.databind.DatabindContext; import org.opendaylight.netconf.databind.ErrorMessage; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.ApiPath; import org.opendaylight.restconf.mdsal.spi.data.MdsalRestconfStrategy; import org.opendaylight.restconf.server.api.ResourceBody; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.restconf.server.mdsal.MdsalMountPointResolver; import org.opendaylight.restconf.server.mdsal.MdsalServerStrategy; @@ -106,7 +106,7 @@ NotSupportedServerActionOperations.INSTANCE, new MdsalRestconfStrategy(IID_DATAB } } - static final ServerError assertError(final Executable executable) { + static final RequestError assertError(final Executable executable) { final var ex = assertThrows(ServerException.class, executable); final var errors = ex.errors(); assertEquals(1, errors.size()); diff --git a/apps/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/YangErrorsBodyTest.java b/apps/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/YangErrorsBodyTest.java index 968f8bd20c0..20829a50a54 100644 --- a/apps/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/YangErrorsBodyTest.java +++ b/apps/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/YangErrorsBodyTest.java @@ -13,7 +13,7 @@ import org.opendaylight.netconf.databind.ErrorInfo; import org.opendaylight.netconf.databind.ErrorMessage; import org.opendaylight.netconf.databind.ErrorPath; -import org.opendaylight.restconf.server.api.ServerError; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.server.api.YangErrorsBody; import org.opendaylight.restconf.server.api.testlib.AbstractJukeboxTest; import org.opendaylight.yangtools.yang.common.ErrorTag; @@ -34,11 +34,11 @@ class YangErrorsBodyTest extends AbstractJukeboxTest { @Test void sampleComplexError() { final var body = new YangErrorsBody(List.of( - new ServerError(ErrorType.APPLICATION, ErrorTag.BAD_ATTRIBUTE, new ErrorMessage("message 1"), "app tag #1", + new RequestError(ErrorType.APPLICATION, ErrorTag.BAD_ATTRIBUTE, new ErrorMessage("message 1"), "app tag #1", null, null), - new ServerError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, new ErrorMessage("message 2"), + new RequestError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, new ErrorMessage("message 2"), "app tag #2", null, new ErrorInfo("my info")), - new ServerError(ErrorType.RPC, ErrorTag.DATA_MISSING, new ErrorMessage("message 3"), " app tag #3", + new RequestError(ErrorType.RPC, ErrorTag.DATA_MISSING, new ErrorMessage("message 3"), " app tag #3", new ErrorPath(DATABIND, YangInstanceIdentifier.builder() .node(QName.create(MONITORING_MODULE_INFO, "patch-cont")) .node(QName.create(MONITORING_MODULE_INFO, "my-list1")) diff --git a/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/DOMRpcResultCallback.java b/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/DOMRpcResultCallback.java index ea61d847f5d..7c5d0cabc26 100644 --- a/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/DOMRpcResultCallback.java +++ b/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/DOMRpcResultCallback.java @@ -16,8 +16,8 @@ import org.opendaylight.mdsal.dom.api.DOMActionException; import org.opendaylight.mdsal.dom.api.DOMRpcResult; import org.opendaylight.netconf.databind.DatabindPath.OperationPath; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.server.api.InvokeResult; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.restconf.server.api.ServerRequest; import org.opendaylight.restconf.server.spi.InterceptingServerRpcOperations; @@ -51,7 +51,7 @@ public void onSuccess(final DOMRpcResult result) { } return true; }) - .map(ServerError::ofRpcError) + .map(RequestError::ofRpcError) .collect(Collectors.toList()); if (errors.isEmpty()) { request.completeWith(InterceptingServerRpcOperations.invokeResultOf(path, result.value())); diff --git a/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/DOMServerRpcOperations.java b/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/DOMServerRpcOperations.java index e830b3fb3d1..24a6ed4fbf5 100644 --- a/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/DOMServerRpcOperations.java +++ b/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/DOMServerRpcOperations.java @@ -18,8 +18,8 @@ import org.opendaylight.mdsal.dom.api.DOMRpcResult; import org.opendaylight.mdsal.dom.api.DOMRpcService; import org.opendaylight.netconf.databind.DatabindPath.Rpc; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.server.api.InvokeResult; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.restconf.server.api.ServerRequest; import org.opendaylight.restconf.server.spi.InterceptingServerRpcOperations; @@ -54,7 +54,7 @@ public void onSuccess(final DOMRpcResult result) { } else { LOG.debug("RPC invocation reported {}", result.errors()); request.completeWith(new ServerException(result.errors().stream() - .map(ServerError::ofRpcError) + .map(RequestError::ofRpcError) .collect(Collectors.toList()), null, "Opereation implementation reported errors")); } } diff --git a/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/data/ExistenceCheck.java b/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/data/ExistenceCheck.java index 4c8b2944768..414881b0300 100644 --- a/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/data/ExistenceCheck.java +++ b/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/data/ExistenceCheck.java @@ -23,7 +23,7 @@ import org.opendaylight.mdsal.common.api.ReadFailedException; import org.opendaylight.mdsal.dom.api.DOMDataTreeReadOperations; import org.opendaylight.netconf.databind.DatabindContext; -import org.opendaylight.restconf.server.api.ServerError; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -108,7 +108,7 @@ public void onFailure(final Throwable throwable) { // are okay -- they differ only in what we report. We rely on SettableFuture's synchronization faculties to // reconcile any conflict with onSuccess() failure path. future.completeExceptionally(new ServerException(cause.getErrorList().stream() - .map(ServerError::ofRpcError) + .map(RequestError::ofRpcError) .collect(Collectors.toList()), cause, "Could not determine the existence of path %s", parentPath)); } } diff --git a/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/data/RestconfStrategy.java b/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/data/RestconfStrategy.java index 07f589b10be..3fef191fcf9 100644 --- a/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/data/RestconfStrategy.java +++ b/plugins/restconf-mdsal-spi/src/main/java/org/opendaylight/restconf/mdsal/spi/data/RestconfStrategy.java @@ -38,6 +38,7 @@ import org.opendaylight.netconf.databind.DatabindContext; import org.opendaylight.netconf.databind.DatabindPath.Data; import org.opendaylight.netconf.databind.ErrorPath; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.ApiPath; import org.opendaylight.restconf.api.query.ContentParam; import org.opendaylight.restconf.api.query.WithDefaultsParam; @@ -50,7 +51,6 @@ import org.opendaylight.restconf.server.api.PatchContext; import org.opendaylight.restconf.server.api.PatchStatusContext; import org.opendaylight.restconf.server.api.PatchStatusEntity; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.restconf.server.api.ServerRequest; import org.opendaylight.restconf.server.spi.AbstractServerDataOperations; @@ -499,7 +499,7 @@ public final void patchData(final ServerRequest request, fi break; default: editCollection.add(new PatchStatusEntity(editId, false, List.of( - new ServerError(ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, + new RequestError(ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, "Not supported Yang Patch operation")))); noError = false; break; diff --git a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/ServerError.java b/protocol/databind/src/main/java/org/opendaylight/netconf/databind/RequestError.java similarity index 76% rename from protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/ServerError.java rename to protocol/databind/src/main/java/org/opendaylight/netconf/databind/RequestError.java index accee4b15ef..04dd0416f94 100644 --- a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/ServerError.java +++ b/protocol/databind/src/main/java/org/opendaylight/netconf/databind/RequestError.java @@ -5,25 +5,21 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.restconf.server.api; +package org.opendaylight.netconf.databind; import static java.util.Objects.requireNonNull; import com.google.common.base.MoreObjects; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.opendaylight.netconf.databind.DatabindContext; -import org.opendaylight.netconf.databind.ErrorInfo; -import org.opendaylight.netconf.databind.ErrorMessage; -import org.opendaylight.netconf.databind.ErrorPath; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcError; /** - * Encapsulates a single {@code error} within the - * "errors" YANG Data Template as bound to a particular - * {@link DatabindContext}. + * A basic request error, as defined in both + * RFC6241 rpc-error element and a single {@code error} + * within the RFC8040 "errors" YANG Data Template. * * @param type value of {@code error-type} leaf * @param tag value of {@code error-tag} leaf @@ -33,27 +29,27 @@ * @param info optional content of {@code error-info} anydata */ @NonNullByDefault -public record ServerError( +public record RequestError( ErrorType type, ErrorTag tag, @Nullable ErrorMessage message, @Nullable String appTag, @Nullable ErrorPath path, @Nullable ErrorInfo info) { - public ServerError { + public RequestError { requireNonNull(type); requireNonNull(tag); } - public ServerError(final ErrorType type, final ErrorTag tag, final String message) { + public RequestError(final ErrorType type, final ErrorTag tag, final String message) { this(type, tag, new ErrorMessage(message), null, null, null); } - public static ServerError ofRpcError(final RpcError rpcError) { + public static RequestError ofRpcError(final RpcError rpcError) { final var tag = rpcError.getTag(); final var errorTag = tag != null ? tag : ErrorTag.OPERATION_FAILED; final var errorMessage = rpcError.getMessage(); - return new ServerError(rpcError.getErrorType(), errorTag, + return new RequestError(rpcError.getErrorType(), errorTag, errorMessage != null ? new ErrorMessage(errorMessage) : null, rpcError.getApplicationTag(), null, extractErrorInfo(rpcError)); } diff --git a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/PatchStatusContext.java b/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/PatchStatusContext.java index 7a31ee267a9..98cb6ea88dc 100644 --- a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/PatchStatusContext.java +++ b/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/PatchStatusContext.java @@ -12,6 +12,7 @@ import java.util.List; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.netconf.databind.RequestError; /** * Holder of patch status context. @@ -20,7 +21,7 @@ public record PatchStatusContext( @NonNull String patchId, @NonNull List editCollection, boolean ok, - @Nullable List globalErrors) { + @Nullable List globalErrors) { public PatchStatusContext { requireNonNull(patchId); diff --git a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/PatchStatusEntity.java b/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/PatchStatusEntity.java index e6039104e6b..fc7335b6d83 100644 --- a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/PatchStatusEntity.java +++ b/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/PatchStatusEntity.java @@ -10,13 +10,14 @@ import static java.util.Objects.requireNonNull; import java.util.List; +import org.opendaylight.netconf.databind.RequestError; public class PatchStatusEntity { private final String editId; - private final List editErrors; + private final List editErrors; private final boolean ok; - public PatchStatusEntity(final String editId, final boolean ok, final List editErrors) { + public PatchStatusEntity(final String editId, final boolean ok, final List editErrors) { this.editId = requireNonNull(editId); this.ok = ok; this.editErrors = editErrors; @@ -30,7 +31,7 @@ public boolean isOk() { return ok; } - public List getEditErrors() { + public List getEditErrors() { return editErrors; } } diff --git a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/RequestBody.java b/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/RequestBody.java index 74c5797f0c5..0f665235f50 100644 --- a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/RequestBody.java +++ b/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/RequestBody.java @@ -20,6 +20,7 @@ import org.opendaylight.netconf.databind.DatabindPath; import org.opendaylight.netconf.databind.ErrorMessage; import org.opendaylight.netconf.databind.ErrorPath; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.ConsumableBody; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; @@ -59,11 +60,12 @@ private static ServerException newServerParseException(final DatabindPath path, final ErrorTag tag, final String messagePrefix, final Exception caught) { final var message = requireNonNull(messagePrefix) + ": " + caught.getMessage(); final var errors = exceptionErrors(path.databind(), caught); - return new ServerException(message, errors != null ? errors : List.of(new ServerError(type, tag, message)), + return new ServerException(message, errors != null ? errors : List.of(new RequestError(type, tag, message)), caught); } - private static @Nullable List exceptionErrors(final DatabindContext databind, final Exception caught) { + private static @Nullable List exceptionErrors(final DatabindContext databind, + final Exception caught) { Throwable cause = caught; do { if (cause instanceof YangNetconfErrorAware infoAware) { @@ -72,7 +74,7 @@ private static ServerException newServerParseException(final DatabindPath path, final var message = error.message(); final var path = error.path(); - return new ServerError(error.type(), error.tag(), + return new RequestError(error.type(), error.tag(), message != null ? new ErrorMessage(message) : null, error.appTag(), path != null ? new ErrorPath(databind, path) : null, // FIXME: pass down error.info() diff --git a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/ServerException.java b/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/ServerException.java index b67c1726435..00915bbe87a 100644 --- a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/ServerException.java +++ b/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/ServerException.java @@ -21,11 +21,12 @@ import org.opendaylight.netconf.databind.ErrorInfo; import org.opendaylight.netconf.databind.ErrorMessage; import org.opendaylight.netconf.databind.ErrorPath; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; /** - * A server-side processing exception, reporting a single {@link ServerError}. This exception is not serializable on + * A server-side processing exception, reporting a single {@link RequestError}. This exception is not serializable on * purpose. */ @NonNullByDefault @@ -34,15 +35,15 @@ public final class ServerException extends Exception { private static final long serialVersionUID = 0L; @SuppressWarnings("serial") - private final List errors; + private final List errors; - ServerException(final String message, final List errors, final @Nullable Throwable cause) { + ServerException(final String message, final List errors, final @Nullable Throwable cause) { super(message, cause); this.errors = requireNonNull(errors); verify(!errors.isEmpty()); } - private ServerException(final String message, final ServerError error, final @Nullable Throwable cause) { + private ServerException(final String message, final RequestError error, final @Nullable Throwable cause) { super(message, cause); errors = List.of(error); } @@ -68,14 +69,14 @@ public ServerException(final ErrorType type, final ErrorTag tag, final String me } public ServerException(final ErrorType type, final ErrorTag tag, final Throwable cause) { - this(cause.toString(), new ServerError(type, tag, new ErrorMessage(cause.getMessage()), null, null, null), + this(cause.toString(), new RequestError(type, tag, new ErrorMessage(cause.getMessage()), null, null, null), cause); } public ServerException(final ErrorType type, final ErrorTag tag, final String message, final @Nullable Throwable cause) { this(requireNonNull(message), - new ServerError(type, tag, new ErrorMessage(message), null, null, errorInfoOf(cause)), cause); + new RequestError(type, tag, new ErrorMessage(message), null, null, errorInfoOf(cause)), cause); } public ServerException(final ErrorType type, final ErrorTag tag, final String format, @@ -90,24 +91,24 @@ public ServerException(final ErrorType type, final ErrorTag tag, final String me public ServerException(final ErrorType type, final ErrorTag tag, final String message, final @Nullable ErrorPath path, final @Nullable Throwable cause) { - this(message, new ServerError(type, tag, new ErrorMessage(message), null, path, null), cause); + this(message, new RequestError(type, tag, new ErrorMessage(message), null, path, null), cause); } - public ServerException(final List errors, final @Nullable Throwable cause, final String message) { + public ServerException(final List errors, final @Nullable Throwable cause, final String message) { this(message, errors, cause); } - public ServerException(final List errors, final @Nullable Throwable cause, final String format, + public ServerException(final List errors, final @Nullable Throwable cause, final String format, final Object... args) { this(errors, cause, format.formatted(args)); } /** - * Return the reported {@link ServerError}. + * Return the reported {@link RequestError}. * - * @return the reported {@link ServerError} + * @return the reported {@link RequestError} */ - public List errors() { + public List errors() { return errors; } diff --git a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/YangErrorsBody.java b/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/YangErrorsBody.java index 962d6c1a661..e0ba45ad889 100644 --- a/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/YangErrorsBody.java +++ b/protocol/restconf-server-api/src/main/java/org/opendaylight/restconf/server/api/YangErrorsBody.java @@ -13,6 +13,7 @@ import java.util.List; import javax.xml.stream.XMLStreamException; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.FormattableBody; import org.opendaylight.restconf.api.query.PrettyPrintParam; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.errors.Errors; @@ -35,16 +36,16 @@ public final class YangErrorsBody extends FormattableBody { private static final String ERROR_INFO = "error-info"; private static final String ERROR_PATH = "error-path"; - private final List errors; + private final List errors; - public YangErrorsBody(final List errors) { + public YangErrorsBody(final List errors) { if (errors.isEmpty()) { throw new IllegalArgumentException("empty errors"); } this.errors = List.copyOf(errors); } - public YangErrorsBody(final ServerError error) { + public YangErrorsBody(final RequestError error) { this(List.of(error)); } @@ -53,7 +54,7 @@ public YangErrorsBody(final ServerError error) { * * @return reported errors, guaranteed to have at least one element */ - public List errors() { + public List errors() { return errors; } diff --git a/protocol/restconf-server-api/src/test/java/org/opendaylight/restconf/server/api/ServerExceptionTest.java b/protocol/restconf-server-api/src/test/java/org/opendaylight/restconf/server/api/ServerExceptionTest.java index 94de55535a2..46e7f10b63c 100644 --- a/protocol/restconf-server-api/src/test/java/org/opendaylight/restconf/server/api/ServerExceptionTest.java +++ b/protocol/restconf-server-api/src/test/java/org/opendaylight/restconf/server/api/ServerExceptionTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test; import org.opendaylight.netconf.databind.ErrorInfo; import org.opendaylight.netconf.databind.ErrorMessage; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; @@ -24,7 +25,7 @@ void stringConstructor() { final var ex = new ServerException("some message"); assertEquals("some message", ex.getMessage()); assertNull(ex.getCause()); - assertServerError(new ServerError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "some message"), ex); + assertServerError(new RequestError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "some message"), ex); } @Test @@ -33,7 +34,7 @@ void causeConstructor() { final var ex = new ServerException(cause); assertEquals("java.lang.Throwable: cause message", ex.getMessage()); assertSame(cause, ex.getCause()); - assertServerError(new ServerError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "cause message"), ex); + assertServerError(new RequestError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "cause message"), ex); } @Test @@ -42,7 +43,7 @@ void causeConstructorIAE() { final var ex = new ServerException(cause); assertEquals("java.lang.IllegalArgumentException: cause message", ex.getMessage()); assertSame(cause, ex.getCause()); - assertServerError(new ServerError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, "cause message"), ex); + assertServerError(new RequestError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, "cause message"), ex); } @Test @@ -52,7 +53,7 @@ void causeConstructorUOE() { assertEquals("java.lang.UnsupportedOperationException: cause message", ex.getMessage()); assertSame(cause, ex.getCause()); assertServerError( - new ServerError(ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, "cause message"), + new RequestError(ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, "cause message"), ex); } @@ -63,7 +64,7 @@ void messageCauseConstructor() { assertEquals("some message", ex.getMessage()); assertSame(cause, ex.getCause()); assertServerError( - new ServerError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, new ErrorMessage("some message"), null, + new RequestError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, new ErrorMessage("some message"), null, null, new ErrorInfo("cause message")), ex); } @@ -75,8 +76,8 @@ void messageCauseConstructorIAE() { assertEquals("some message", ex.getMessage()); assertSame(cause, ex.getCause()); assertServerError( - new ServerError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, new ErrorMessage("some message"), null, null, - new ErrorInfo("cause message")), + new RequestError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, new ErrorMessage("some message"), null, + null, new ErrorInfo("cause message")), ex); } @@ -87,7 +88,7 @@ void messageCauseConstructorUOE() { assertEquals("some message", ex.getMessage()); assertSame(cause, ex.getCause()); assertServerError( - new ServerError(ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, new ErrorMessage("some message"), + new RequestError(ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, new ErrorMessage("some message"), null, null, new ErrorInfo("cause message")), ex); } @@ -97,10 +98,10 @@ void formatConstructor() { final var ex = new ServerException("huh %s: %s", 1, "hah"); assertEquals("huh 1: hah", ex.getMessage()); assertNull(ex.getCause()); - assertServerError(new ServerError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "huh 1: hah"), ex); + assertServerError(new RequestError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "huh 1: hah"), ex); } - private static void assertServerError(final ServerError expected, final ServerException ex) { + private static void assertServerError(final RequestError expected, final ServerException ex) { assertEquals(List.of(expected), ex.errors()); } } diff --git a/protocol/restconf-server-jaxrs/pom.xml b/protocol/restconf-server-jaxrs/pom.xml index 08a4fb368f5..d3ffb020b7c 100644 --- a/protocol/restconf-server-jaxrs/pom.xml +++ b/protocol/restconf-server-jaxrs/pom.xml @@ -61,6 +61,10 @@ org.opendaylight.mdsal.binding.model.ietf rfc6991-ietf-inet-types + + org.opendaylight.netconf + databind + org.opendaylight.netconf restconf-api @@ -127,11 +131,6 @@ ietf-topology test - - org.opendaylight.netconf - databind - test - org.opendaylight.netconf netconf-dom-api diff --git a/protocol/restconf-server-jaxrs/src/main/java/org/opendaylight/restconf/server/jaxrs/JaxRsRestconf.java b/protocol/restconf-server-jaxrs/src/main/java/org/opendaylight/restconf/server/jaxrs/JaxRsRestconf.java index 67bc8344daf..c6ee1b2b460 100644 --- a/protocol/restconf-server-jaxrs/src/main/java/org/opendaylight/restconf/server/jaxrs/JaxRsRestconf.java +++ b/protocol/restconf-server-jaxrs/src/main/java/org/opendaylight/restconf/server/jaxrs/JaxRsRestconf.java @@ -50,6 +50,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.ApiPath; import org.opendaylight.restconf.api.FormattableBody; import org.opendaylight.restconf.api.HttpStatusCode; @@ -75,7 +76,6 @@ import org.opendaylight.restconf.server.api.OptionsResult; import org.opendaylight.restconf.server.api.PatchStatusContext; import org.opendaylight.restconf.server.api.RestconfServer; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.restconf.server.api.XmlChildBody; import org.opendaylight.restconf.server.api.XmlDataPostBody; @@ -530,7 +530,7 @@ private HttpStatusCode statusOf(final PatchStatusContext result) { return HttpStatusCode.INTERNAL_SERVER_ERROR; } - private HttpStatusCode statusOfFirst(final List error) { + private HttpStatusCode statusOfFirst(final List error) { return errorTagMapping.statusOf(error.get(0).tag()); } }; diff --git a/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/AbstractRestconfTest.java b/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/AbstractRestconfTest.java index 2a2fc9a0150..8755d9e1192 100644 --- a/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/AbstractRestconfTest.java +++ b/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/AbstractRestconfTest.java @@ -35,10 +35,10 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.mdsal.dom.api.DOMRpcService; import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.ApiPath; import org.opendaylight.restconf.api.FormattableBody; import org.opendaylight.restconf.api.query.PrettyPrintParam; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.YangErrorsBody; import org.opendaylight.restconf.server.api.testlib.AbstractJukeboxTest; import org.opendaylight.restconf.server.mdsal.MdsalDatabindProvider; @@ -115,7 +115,7 @@ static final Object assertEntity(final int expectedStatus, final Consumer invocation) { + static final RequestError assertError(final int expectedStatus, final Consumer invocation) { final var errors = assertErrors(expectedStatus, invocation); assertEquals(1, errors.size()); final var error = errors.get(0); @@ -123,7 +123,7 @@ static final ServerError assertError(final int expectedStatus, final Consumer assertErrors(final int expectedStatus, final Consumer invocation) { + static final List assertErrors(final int expectedStatus, final Consumer invocation) { return assertInstanceOf(YangErrorsBody.class, assertEntity(JaxRsFormattableBody.class, expectedStatus, invocation).body()).errors(); } diff --git a/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/MappingServerRequestTest.java b/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/MappingServerRequestTest.java index 90188ba9e97..c3253a86595 100644 --- a/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/MappingServerRequestTest.java +++ b/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/MappingServerRequestTest.java @@ -18,11 +18,11 @@ import org.opendaylight.netconf.databind.ErrorInfo; import org.opendaylight.netconf.databind.ErrorMessage; import org.opendaylight.netconf.databind.ErrorPath; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.FormattableBody; import org.opendaylight.restconf.api.HttpStatusCode; import org.opendaylight.restconf.api.QueryParameters; import org.opendaylight.restconf.api.query.PrettyPrintParam; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.restconf.server.api.testlib.AbstractJukeboxTest; import org.opendaylight.restconf.server.spi.ErrorTagMapping; @@ -86,8 +86,8 @@ void messageOnlyException() { @Test void mismatchedErrorTags() { final var body = assertMapped(HttpStatusCode.BAD_REQUEST, new ServerException(List.of( - new ServerError(ErrorType.APPLICATION, ErrorTag.BAD_ATTRIBUTE, "message 1"), - new ServerError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "message 2")), + new RequestError(ErrorType.APPLICATION, ErrorTag.BAD_ATTRIBUTE, "message 1"), + new RequestError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "message 2")), new IllegalStateException("cause"), "general message")); assertFormat(""" @@ -128,11 +128,11 @@ void mismatchedErrorTags() { @Test void complexException() { final var body = assertMapped(HttpStatusCode.BAD_REQUEST, new ServerException(List.of( - new ServerError(ErrorType.APPLICATION, ErrorTag.BAD_ATTRIBUTE, new ErrorMessage("message 1"), "app tag #1", + new RequestError(ErrorType.APPLICATION, ErrorTag.BAD_ATTRIBUTE, new ErrorMessage("message 1"), "app tag #1", null, null), - new ServerError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, new ErrorMessage("message 2"), + new RequestError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, new ErrorMessage("message 2"), "app tag #2", null, new ErrorInfo("my info")), - new ServerError(ErrorType.RPC, ErrorTag.DATA_MISSING, new ErrorMessage("message 3"), " app tag #3", + new RequestError(ErrorType.RPC, ErrorTag.DATA_MISSING, new ErrorMessage("message 3"), " app tag #3", new ErrorPath(DATABIND, YangInstanceIdentifier.builder() .node(QName.create(MONITORING_MODULE_INFO, "patch-cont")) .node(QName.create(MONITORING_MODULE_INFO, "my-list1")) diff --git a/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/RestconfModulesGetTest.java b/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/RestconfModulesGetTest.java index 6ee308396b5..df4a3525f2e 100644 --- a/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/RestconfModulesGetTest.java +++ b/protocol/restconf-server-jaxrs/src/test/java/org/opendaylight/restconf/server/jaxrs/RestconfModulesGetTest.java @@ -30,10 +30,10 @@ import org.opendaylight.mdsal.dom.api.DOMSchemaService.YangTextSourceExtension; import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService; import org.opendaylight.netconf.databind.ErrorMessage; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.netconf.dom.api.NetconfDataTreeService; import org.opendaylight.restconf.api.ApiPath; import org.opendaylight.restconf.mdsal.spi.DOMServerStrategy; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.spi.ErrorTags; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; @@ -289,7 +289,7 @@ private String assertYang(final ApiPath mountPath, final String fileName, final } } - private ServerError assertInvalidValue(final String fileName, final String revision) { + private RequestError assertInvalidValue(final String fileName, final String revision) { final var error = assertError(400, ar -> restconf.modulesYangGET(fileName, revision, sc, ar)); assertEquals(ErrorType.PROTOCOL, error.type()); assertEquals(ErrorTag.INVALID_VALUE, error.tag()); diff --git a/protocol/restconf-server-spi/src/main/java/org/opendaylight/restconf/server/spi/YangPatchStatusBody.java b/protocol/restconf-server-spi/src/main/java/org/opendaylight/restconf/server/spi/YangPatchStatusBody.java index 9dce75f35d5..57d916233f0 100644 --- a/protocol/restconf-server-spi/src/main/java/org/opendaylight/restconf/server/spi/YangPatchStatusBody.java +++ b/protocol/restconf-server-spi/src/main/java/org/opendaylight/restconf/server/spi/YangPatchStatusBody.java @@ -17,11 +17,11 @@ import javax.xml.XMLConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.FormattableBody; import org.opendaylight.restconf.api.query.PrettyPrintParam; import org.opendaylight.restconf.server.api.FormattableBodySupport; import org.opendaylight.restconf.server.api.PatchStatusContext; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.patch.rev170222.yang.patch.status.YangPatchStatus; import org.opendaylight.yangtools.yang.data.codec.gson.DefaultJSONValueWriter; @@ -121,7 +121,7 @@ private static void writeOk(final JsonWriter writer) throws IOException { writer.name("ok").beginArray().nullValue().endArray(); } - private static void writeErrors(final List errors, final JsonWriter writer) throws IOException { + private static void writeErrors(final List errors, final JsonWriter writer) throws IOException { writer.name("errors").beginObject().name("error").beginArray(); for (var error : errors) { @@ -150,7 +150,7 @@ private static void writeErrors(final List errors, final JsonWriter writer.endArray().endObject(); } - private static void reportErrors(final List errors, final XMLStreamWriter writer) + private static void reportErrors(final List errors, final XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("errors"); diff --git a/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/ApiPathCanonizerTest.java b/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/ApiPathCanonizerTest.java index 5064332feea..2eccb40649c 100644 --- a/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/ApiPathCanonizerTest.java +++ b/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/ApiPathCanonizerTest.java @@ -18,8 +18,8 @@ import org.opendaylight.netconf.databind.DatabindContext; import org.opendaylight.netconf.databind.DatabindPath.Data; import org.opendaylight.netconf.databind.ErrorMessage; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.ApiPath; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; @@ -365,7 +365,7 @@ private static YangInstanceIdentifier assertNormalized(final String str) { } } - private static ServerError assertError(final YangInstanceIdentifier path) { + private static RequestError assertError(final YangInstanceIdentifier path) { final var errors = assertThrows(ServerException.class, () -> CANONIZER.dataToApiPath(path)).errors(); assertEquals(1, errors.size()); return errors.get(0); diff --git a/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/ApiPathNormalizerTest.java b/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/ApiPathNormalizerTest.java index b5cec205b67..a02fa4a5c23 100644 --- a/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/ApiPathNormalizerTest.java +++ b/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/ApiPathNormalizerTest.java @@ -20,8 +20,8 @@ import org.opendaylight.netconf.databind.DatabindPath.Data; import org.opendaylight.netconf.databind.ErrorInfo; import org.opendaylight.netconf.databind.ErrorMessage; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.ApiPath; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; @@ -447,7 +447,7 @@ void deserializePathWithInvalidIdentityrefKeyValueTest() { "deserializer-test-included:refs/list-with-identityref=deserializer-test:derived-identity/foo"); } - private static ServerError assertErrorPath(final String path) { + private static RequestError assertErrorPath(final String path) { final var apiPath = assertApiPath(path); final var errors = assertThrows(ServerException.class, () -> NORMALIZER.normalizePath(apiPath)).errors(); assertEquals(1, errors.size()); diff --git a/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/NC1265Test.java b/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/NC1265Test.java index c3c58b076d6..a039b45c1e5 100644 --- a/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/NC1265Test.java +++ b/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/NC1265Test.java @@ -15,8 +15,8 @@ import org.opendaylight.netconf.databind.DatabindContext; import org.opendaylight.netconf.databind.ErrorInfo; import org.opendaylight.netconf.databind.ErrorMessage; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.ApiPath; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; @@ -129,7 +129,7 @@ private static void assertNormalized(final YangInstanceIdentifier expected, fina } } - private static ServerError assertError(final String apiPath) { + private static RequestError assertError(final String apiPath) { final var parsed = assertApiPath(apiPath); final var errors = assertThrows(ServerException.class, () -> NORMALIZER.normalizeDataPath(parsed)).errors(); assertEquals(1, errors.size()); diff --git a/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/YangPatchStatusBodyTest.java b/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/YangPatchStatusBodyTest.java index 43e8f3f4558..0dd4bb47324 100644 --- a/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/YangPatchStatusBodyTest.java +++ b/protocol/restconf-server-spi/src/test/java/org/opendaylight/restconf/server/spi/YangPatchStatusBodyTest.java @@ -9,15 +9,15 @@ import java.util.List; import org.junit.jupiter.api.Test; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.server.api.PatchStatusContext; import org.opendaylight.restconf.server.api.PatchStatusEntity; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.testlib.AbstractJukeboxTest; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; class YangPatchStatusBodyTest extends AbstractJukeboxTest { - private final ServerError error = new ServerError(ErrorType.PROTOCOL, new ErrorTag("data-exists"), + private final RequestError error = new RequestError(ErrorType.PROTOCOL, new ErrorTag("data-exists"), "Data already exists"); private final PatchStatusEntity statusEntity = new PatchStatusEntity("patch1", true, null); private final PatchStatusEntity statusEntityError = new PatchStatusEntity("patch1", false, List.of(error)); diff --git a/protocol/restconf-server/pom.xml b/protocol/restconf-server/pom.xml index b125554b88c..39ae295c137 100644 --- a/protocol/restconf-server/pom.xml +++ b/protocol/restconf-server/pom.xml @@ -88,8 +88,8 @@ repackaged-shiro - org.opendaylight.netconf.model - draft-ietf-restconf-server + org.opendaylight.netconf + databind org.opendaylight.netconf @@ -115,6 +115,10 @@ org.opendaylight.netconf transport-tcp + + org.opendaylight.netconf.model + draft-ietf-restconf-server + org.opendaylight.yangtools binding-spec diff --git a/protocol/restconf-server/src/test/java/org/opendaylight/restconf/server/DataRequestProcessorTest.java b/protocol/restconf-server/src/test/java/org/opendaylight/restconf/server/DataRequestProcessorTest.java index 9c8a9bf06f8..1fb3ba03bd6 100644 --- a/protocol/restconf-server/src/test/java/org/opendaylight/restconf/server/DataRequestProcessorTest.java +++ b/protocol/restconf-server/src/test/java/org/opendaylight/restconf/server/DataRequestProcessorTest.java @@ -37,6 +37,7 @@ import org.junit.jupiter.params.provider.MethodSource; import org.mockito.ArgumentCaptor; import org.mockito.Captor; +import org.opendaylight.netconf.databind.RequestError; import org.opendaylight.restconf.api.ApiPath; import org.opendaylight.restconf.api.ApiPath.ApiIdentifier; import org.opendaylight.restconf.api.ApiPath.ListInstance; @@ -59,7 +60,6 @@ import org.opendaylight.restconf.server.api.PatchStatusContext; import org.opendaylight.restconf.server.api.PatchStatusEntity; import org.opendaylight.restconf.server.api.ResourceBody; -import org.opendaylight.restconf.server.api.ServerError; import org.opendaylight.restconf.server.api.XmlChildBody; import org.opendaylight.restconf.server.api.XmlDataPostBody; import org.opendaylight.restconf.server.api.XmlPatchBody; @@ -339,13 +339,13 @@ private static Stream yangPatch() { final var contextOk = new PatchStatusContext("patch-id1", List.of(), true, null); final var containsOk = List.of("patch-id1"); final var contextError1 = new PatchStatusContext("patch-id2", List.of(), false, - List.of(new ServerError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "operation-failed-error"))); + List.of(new RequestError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "operation-failed-error"))); final var containsError1 = List.of( "patch-id2", ErrorTag.OPERATION_FAILED.elementBody(), "operation-failed-error"); final var contextError2 = new PatchStatusContext("patch-id3", List.of( new PatchStatusEntity("edit-id1", true, null), new PatchStatusEntity("edit-id2", false, - List.of(new ServerError(ErrorType.APPLICATION, ErrorTag.DATA_MISSING, "data-missing-error"))) + List.of(new RequestError(ErrorType.APPLICATION, ErrorTag.DATA_MISSING, "data-missing-error"))) ), false, null); final var containsError2 = List.of("patch-id3", "edit-id1", "edit-id2", ErrorTag.DATA_MISSING.elementBody(), "data-missing-error");