Fix bug 2821 - restconf RPC parsing returns http status 500
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / rest / impl / NormalizedNodeJsonBodyWriter.java
index edf42b681fa2a458e2429145febb8fe649c4aaaa..4944d96b546933c49637fbb66b4b91ea8add05d1 100644 (file)
@@ -37,7 +37,9 @@ import org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamW
 import org.opendaylight.yangtools.yang.data.codec.gson.JsonWriterFactory;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.data.codec.gson.JsonWriterFactory;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 @Provider
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 @Provider
@@ -64,12 +66,15 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter<Normalize
             return;
         }
 
             return;
         }
 
-        final InstanceIdentifierContext<DataSchemaNode> context = (InstanceIdentifierContext<DataSchemaNode>) t.getInstanceIdentifierContext();
+        final InstanceIdentifierContext<SchemaNode> context = (InstanceIdentifierContext<SchemaNode>) t.getInstanceIdentifierContext();
 
         SchemaPath path = context.getSchemaNode().getPath();
         boolean isDataRoot = false;
         if (SchemaPath.ROOT.equals(path)) {
             isDataRoot = true;
 
         SchemaPath path = context.getSchemaNode().getPath();
         boolean isDataRoot = false;
         if (SchemaPath.ROOT.equals(path)) {
             isDataRoot = true;
+        } else if (context.getSchemaNode() instanceof RpcDefinition) {
+            isDataRoot = true;
+            path = ((RpcDefinition) context.getSchemaNode()).getOutput().getPath();
         } else {
             path = path.getParent();
             // FIXME: Add proper handling of reading root.
         } else {
             path = path.getParent();
             // FIXME: Add proper handling of reading root.
@@ -93,14 +98,14 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter<Normalize
         jsonWriter.flush();
     }
 
         jsonWriter.flush();
     }
 
-    private NormalizedNodeWriter createNormalizedNodeWriter(final InstanceIdentifierContext<DataSchemaNode> context,
+    private NormalizedNodeWriter createNormalizedNodeWriter(final InstanceIdentifierContext<SchemaNode> context,
             final SchemaPath path, final JsonWriter jsonWriter) {
 
             final SchemaPath path, final JsonWriter jsonWriter) {
 
-        final DataSchemaNode schema = context.getSchemaNode();
+        final SchemaNode schema = context.getSchemaNode();
         final JSONCodecFactory codecs = getCodecFactory(context);
 
         URI initialNs = null;
         final JSONCodecFactory codecs = getCodecFactory(context);
 
         URI initialNs = null;
-        if(!schema.isAugmenting() && !(schema instanceof SchemaContext)) {
+        if ( ! (schema instanceof RpcDefinition) && (!((DataSchemaNode)schema).isAugmenting() && !(schema instanceof SchemaContext))) {
             initialNs = schema.getQName().getNamespace();
         }
         final NormalizedNodeStreamWriter streamWriter = JSONNormalizedNodeStreamWriter.createNestedWriter(codecs,path,initialNs,jsonWriter);
             initialNs = schema.getQName().getNamespace();
         }
         final NormalizedNodeStreamWriter streamWriter = JSONNormalizedNodeStreamWriter.createNestedWriter(codecs,path,initialNs,jsonWriter);