From 9e0f7abdc08884ec405f267570690dd0f60b261f Mon Sep 17 00:00:00 2001 From: Jakub Toth Date: Fri, 11 Mar 2016 11:20:39 +0100 Subject: [PATCH] Bug 5526 - Supported MediaTypes from Draft11 in all writers from old restconf(reusing them in new) Change-Id: Ibbc34d8bdd3b057c0d344764d8bf5c6021bb2ae7 Signed-off-by: Jakub Toth --- .../SchemaExportContentYangBodyWriter.java | 3 ++- .../SchemaExportContentYinBodyWriter.java | 4 +++- .../impl/NormalizedNodeJsonBodyWriter.java | 18 +++++++++------ .../impl/NormalizedNodeXmlBodyWriter.java | 22 +++++++++++-------- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContentYangBodyWriter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContentYangBodyWriter.java index 27c132f28b..d6fb460100 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContentYangBodyWriter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContentYangBodyWriter.java @@ -18,9 +18,10 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.Provider; +import org.opendaylight.restconf.Draft11; @Provider -@Produces(SchemaRetrievalService.YANG_MEDIA_TYPE) +@Produces({ SchemaRetrievalService.YANG_MEDIA_TYPE, Draft11.MediaTypes.YANG }) public class SchemaExportContentYangBodyWriter implements MessageBodyWriter { @Override diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContentYinBodyWriter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContentYinBodyWriter.java index 98d4f5476c..2dabce3b71 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContentYinBodyWriter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/md/sal/rest/schema/SchemaExportContentYinBodyWriter.java @@ -18,10 +18,12 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.Provider; import javax.xml.stream.XMLStreamException; +import org.opendaylight.restconf.Draft11; +import org.opendaylight.restconf.utils.RestconfConstants; import org.opendaylight.yangtools.yang.model.export.YinExportUtils; @Provider -@Produces(SchemaRetrievalService.YIN_MEDIA_TYPE) +@Produces({ SchemaRetrievalService.YIN_MEDIA_TYPE, Draft11.MediaTypes.YIN + RestconfConstants.XML }) public class SchemaExportContentYinBodyWriter implements MessageBodyWriter { @Override diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeJsonBodyWriter.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeJsonBodyWriter.java index 594a115bd4..3b65083c05 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeJsonBodyWriter.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/rest/impl/NormalizedNodeJsonBodyWriter.java @@ -27,6 +27,8 @@ import org.opendaylight.netconf.sal.rest.api.RestconfNormalizedNodeWriter; import org.opendaylight.netconf.sal.rest.api.RestconfService; import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext; import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext; +import org.opendaylight.restconf.Draft11; +import org.opendaylight.restconf.utils.RestconfConstants; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; @@ -45,7 +47,9 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; @Provider @Produces({ Draft02.MediaTypes.API + RestconfService.JSON, Draft02.MediaTypes.DATA + RestconfService.JSON, - Draft02.MediaTypes.OPERATION + RestconfService.JSON, MediaType.APPLICATION_JSON }) + Draft02.MediaTypes.OPERATION + RestconfService.JSON, + Draft11.MediaTypes.API + RestconfConstants.JSON, Draft11.MediaTypes.DATA + RestconfConstants.JSON, + Draft11.MediaTypes.OPERATION + RestconfConstants.JSON, MediaType.APPLICATION_JSON }) public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter { private static final int DEFAULT_INDENT_SPACES_NUM = 2; @@ -64,7 +68,7 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { - NormalizedNode data = t.getData(); + final NormalizedNode data = t.getData(); if (data == null) { return; } @@ -72,7 +76,7 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter context = (InstanceIdentifierContext) t.getInstanceIdentifierContext(); - SchemaPath path = context.getSchemaNode().getPath(); + final SchemaPath path = context.getSchemaNode().getPath(); final JsonWriter jsonWriter = createJsonWriter(entityStream, t.getWriterParameters().isPrettyPrint()); jsonWriter.beginObject(); writeNormalizedNode(jsonWriter,path,context,data, t.getWriterParameters().getDepth()); @@ -80,8 +84,8 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter context, NormalizedNode data, Optional depth) throws + private void writeNormalizedNode(final JsonWriter jsonWriter, SchemaPath path, + final InstanceIdentifierContext context, NormalizedNode data, final Optional depth) throws IOException { final RestconfNormalizedNodeWriter nnWriter; if (SchemaPath.ROOT.equals(path)) { @@ -121,7 +125,7 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter context, - final SchemaPath path, final JsonWriter jsonWriter, Optional depth) { + final SchemaPath path, final JsonWriter jsonWriter, final Optional depth) { final SchemaNode schema = context.getSchemaNode(); final JSONCodecFactory codecs = getCodecFactory(context); @@ -144,7 +148,7 @@ public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter { private static final XMLOutputFactory XML_FACTORY; @@ -86,8 +90,8 @@ public class NormalizedNodeXmlBodyWriter implements MessageBodyWriter data = t.getData(); - SchemaPath schemaPath = pathContext.getSchemaNode().getPath(); + final NormalizedNode data = t.getData(); + final SchemaPath schemaPath = pathContext.getSchemaNode().getPath(); @@ -95,8 +99,8 @@ public class NormalizedNodeXmlBodyWriter implements MessageBodyWriter - pathContext, NormalizedNode data, Optional depth) throws IOException { + private void writeNormalizedNode(final XMLStreamWriter xmlWriter, final SchemaPath schemaPath, final InstanceIdentifierContext + pathContext, NormalizedNode data, final Optional depth) throws IOException { final RestconfNormalizedNodeWriter nnWriter; final SchemaContext schemaCtx = pathContext.getSchemaContext(); if (SchemaPath.ROOT.equals(schemaPath)) { @@ -118,9 +122,9 @@ public class NormalizedNodeXmlBodyWriter implements MessageBodyWriter depth) { - NormalizedNodeStreamWriter xmlStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, schemaContext, schemaPath); + private RestconfNormalizedNodeWriter createNormalizedNodeWriter(final XMLStreamWriter xmlWriter, + final SchemaContext schemaContext, final SchemaPath schemaPath, final Optional depth) { + final NormalizedNodeStreamWriter xmlStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, schemaContext, schemaPath); if (depth.isPresent()) { return DepthAwareNormalizedNodeWriter.forStreamWriter(xmlStreamWriter, depth.get()); } else { @@ -135,7 +139,7 @@ public class NormalizedNodeXmlBodyWriter implements MessageBodyWriter child : data.getValue()) { + for(final NormalizedNode child : data.getValue()) { nnWriter.write(child); } nnWriter.flush(); -- 2.36.6