From: Jaroslav Tóth Date: Mon, 12 Aug 2019 15:10:52 +0000 (+0200) Subject: Fixed response errors for HTTP PUT X-Git-Tag: release/neon-sr3~17 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=commitdiff_plain;h=485ad9e9946bf38f9e50033e7e91e0acd9042f0a Fixed response errors for HTTP PUT - Added correct error types and tags that previously weren't specified at all so it always returned 500 status code. Change-Id: Ie77d324ee6b2fc149714e24451f40b01b3e47827 Signed-off-by: Jaroslav Tóth (cherry picked from commit 0c41499f46507f3e59f472aa955eaccf3f21f67e) --- diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java index ab6f26d855..075fd1a09d 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java @@ -194,7 +194,8 @@ public class RestconfDataServiceImpl implements RestconfDataService { insertUsed = true; insert = entry.getValue().iterator().next(); } else { - throw new RestconfDocumentedException("Insert parameter can be used only once."); + throw new RestconfDocumentedException("Insert parameter can be used only once.", + RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT); } break; case "point": @@ -202,11 +203,13 @@ public class RestconfDataServiceImpl implements RestconfDataService { pointUsed = true; point = entry.getValue().iterator().next(); } else { - throw new RestconfDocumentedException("Point parameter can be used only once."); + throw new RestconfDocumentedException("Point parameter can be used only once.", + RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT); } break; default: - throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey()); + throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey(), + RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT); } } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java index d8cd95f35e..10217a07f3 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java @@ -21,6 +21,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; +import org.opendaylight.restconf.common.errors.RestconfError; import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; import org.opendaylight.restconf.common.validation.RestconfValidationUtils; @@ -287,8 +288,9 @@ public final class PutDataTransactionUtil { } } default: - throw new RestconfDocumentedException("Used bad value of insert parameter. Possible values are " - + "first, last, before or after, but was: " + insert); + throw new RestconfDocumentedException( + "Used bad value of insert parameter. Possible values are first, last, before or after, " + + "but was: " + insert, RestconfError.ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE); } } @@ -408,17 +410,20 @@ public final class PutDataTransactionUtil { if (dataSchemaNode instanceof ListSchemaNode) { if (!((ListSchemaNode) dataSchemaNode).isUserOrdered()) { - throw new RestconfDocumentedException("Insert parameter can be used only with ordered-by user list."); + throw new RestconfDocumentedException("Insert parameter can be used only with ordered-by user list.", + RestconfError.ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT); } return dataSchemaNode; } if (dataSchemaNode instanceof LeafListSchemaNode) { if (!((LeafListSchemaNode) dataSchemaNode).isUserOrdered()) { throw new RestconfDocumentedException( - "Insert parameter can be used only with ordered-by user leaf-list."); + "Insert parameter can be used only with ordered-by user leaf-list.", + RestconfError.ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT); } return dataSchemaNode; } - throw new RestconfDocumentedException("Insert parameter can be used only with list or leaf-list"); + throw new RestconfDocumentedException("Insert parameter can be used only with list or leaf-list", + RestconfError.ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT); } }