Remove RestconfError.ErrorType
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / jersey / providers / errors / RestconfDocumentedExceptionMapper.java
index bec5c57cceb37431f5a893c8adef18d37172bc6b..9f6619c897938fd91f15f53d72a4df33cb0bb14f 100644 (file)
@@ -15,7 +15,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.net.URI;
 import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.LinkedHashSet;
@@ -37,13 +36,14 @@ import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.errors.Errors;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.errors.errors.Error;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
@@ -68,7 +68,7 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
     private static final QName ERROR_MESSAGE_QNAME = qnameOf("error-message");
     private static final QName ERROR_INFO_QNAME = qnameOf("error-info");
     private static final QName ERROR_PATH_QNAME = qnameOf("error-path");
-    private static final URI IETF_RESTCONF_URI = Errors.QNAME.getModule().getNamespace();
+    private static final XMLNamespace IETF_RESTCONF_URI = Errors.QNAME.getModule().getNamespace();
 
     @Context
     private HttpHeaders headers;
@@ -92,10 +92,9 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
         if (responseStatus != Response.Status.FORBIDDEN
                 && responseStatus.getFamily() == Response.Status.Family.CLIENT_ERROR
                 && exception.getErrors().isEmpty()) {
-            // there should be at least one error entry for 4xx errors except 409 according to the RFC 8040
-            // - creation of WARN log that something went wrong way on the server side
-            LOG.warn("Input exception has a family of 4xx but doesn't contain any descriptive errors: {}",
-                    exception.getMessage());
+            // There should be at least one error entry for 4xx errors except 409 according to RFC8040, but we do not
+            // have it. Issue a warning with the call trace so we can fix whoever was the originator.
+            LOG.warn("Input exception has a family of 4xx but does not contain any descriptive errors", exception);
         }
 
         final ContainerNode errorsContainer = buildErrorsContainer(exception);
@@ -145,7 +144,7 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
         final DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> entryBuilder =
             ImmutableUnkeyedListEntryNodeBuilder.create()
                 .withNodeIdentifier(NodeIdentifier.create(Error.QNAME))
-                .withChild(ImmutableNodes.leafNode(ERROR_TYPE_QNAME, restconfError.getErrorType().getErrorTypeTag()))
+                .withChild(ImmutableNodes.leafNode(ERROR_TYPE_QNAME, restconfError.getErrorType().elementBody()))
                 .withChild(ImmutableNodes.leafNode(ERROR_TAG_QNAME, restconfError.getErrorTag().getTagValue()));
 
         // filling in optional fields
@@ -200,7 +199,7 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
         }
     }
 
-    private static String writeNormalizedNode(final NormalizedNode<?, ?> errorsContainer,
+    private static String writeNormalizedNode(final NormalizedNode errorsContainer,
             final ByteArrayOutputStream outputStream, final StreamWriterWithDisabledValidation streamWriter) {
         try (NormalizedNodeWriter nnWriter = NormalizedNodeWriter.forStreamWriter(streamWriter)) {
             nnWriter.write(errorsContainer);
@@ -368,4 +367,4 @@ public final class RestconfDocumentedExceptionMapper implements ExceptionMapper<
     void setHttpHeaders(final HttpHeaders httpHeaders) {
         this.headers = httpHeaders;
     }
-}
\ No newline at end of file
+}