Bug 6848 - update url pattern of restconf from 16 to 17
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / netconf / sal / rest / impl / JsonNormalizedNodeBodyReader.java
index 83d2449a81a5629f8820287c3839fca5f359cf26..179d2ad59c5ed20a6a6821efb83949d77dbd6729 100644 (file)
@@ -30,6 +30,8 @@ import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.restconf.Draft17;
+import org.opendaylight.restconf.utils.RestconfConstants;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
@@ -51,7 +53,7 @@ import org.slf4j.LoggerFactory;
 
 @Provider
 @Consumes({ Draft02.MediaTypes.DATA + RestconfService.JSON, Draft02.MediaTypes.OPERATION + RestconfService.JSON,
-        MediaType.APPLICATION_JSON })
+        Draft17.MediaTypes.DATA + RestconfConstants.JSON, MediaType.APPLICATION_JSON })
 public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
 
     private final static Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
@@ -68,14 +70,21 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
             final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException,
             WebApplicationException {
         try {
-            return readFrom(getInstanceIdentifierContext(), entityStream, isPost());
+            if (getUriInfo().getAbsolutePath().getPath().contains(RestconfConstants.DRAFT_PATTERN)) {
+                final org.opendaylight.restconf.jersey.providers.JsonNormalizedNodeBodyReader jsonReaderNewRest =
+                        new org.opendaylight.restconf.jersey.providers.JsonNormalizedNodeBodyReader();
+                jsonReaderNewRest.injectParams(getUriInfo(), getRequest());
+                return jsonReaderNewRest.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);
+            } else {
+                return readFrom(getInstanceIdentifierContext(), entityStream, isPost());
+            }
         } catch (final Exception e) {
             propagateExceptionAs(e);
             return null; // no-op
         }
     }
 
-    private static void propagateExceptionAs(Exception e) throws RestconfDocumentedException {
+    private static void propagateExceptionAs(final Exception e) throws RestconfDocumentedException {
         if(e instanceof RestconfDocumentedException) {
             throw (RestconfDocumentedException)e;
         }
@@ -134,7 +143,7 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
         final List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
         InstanceIdentifierContext<? extends SchemaNode> newIIContext;
 
-        while (result instanceof AugmentationNode || result instanceof ChoiceNode) {
+        while ((result instanceof AugmentationNode) || (result instanceof ChoiceNode)) {
             final Object childNode = ((DataContainerNode) result).getValue().iterator().next();
             if (isPost) {
                 iiToDataList.add(result.getIdentifier());