Fix various warnings
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / jersey / providers / JsonNormalizedNodeBodyReader.java
index 5b8acd269d37fd2e8046458d9829d72bdea3973f..9dbf3f0e9ccf577ca1d99f73b9f8c8cacf55f3ca 100644 (file)
@@ -29,7 +29,7 @@ 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.Draft18;
+import org.opendaylight.restconf.Rfc8040;
 import org.opendaylight.restconf.utils.RestconfConstants;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
@@ -51,10 +51,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Provider
-@Consumes({ Draft18.MediaTypes.DATA + RestconfConstants.JSON, MediaType.APPLICATION_JSON })
-public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
+@Consumes({ Rfc8040.MediaTypes.DATA + RestconfConstants.JSON, MediaType.APPLICATION_JSON })
+public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider
+        implements MessageBodyReader<NormalizedNodeContext> {
 
-    private final static Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
+    private static final Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
 
     @Override
     public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
@@ -62,6 +63,7 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
         return true;
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public NormalizedNodeContext readFrom(final Class<NormalizedNodeContext> type, final Type genericType,
             final Annotation[] annotations, final MediaType mediaType,
@@ -75,26 +77,9 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
         }
     }
 
-    private static void propagateExceptionAs(final Exception e) throws RestconfDocumentedException {
-        if(e instanceof RestconfDocumentedException) {
-            throw (RestconfDocumentedException)e;
-        }
-
-        if(e instanceof ResultAlreadySetException) {
-            LOG.debug("Error parsing json input:", e);
-
-            throw new RestconfDocumentedException("Error parsing json input: Failed to create new parse result data. " +
-                    "Are you creating multiple resources/subresources in POST request?");
-        }
-
-        LOG.debug("Error parsing json input", e);
-
-        throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
-                ErrorTag.MALFORMED_MESSAGE, e);
-    }
-
-    private static NormalizedNodeContext readFrom(final InstanceIdentifierContext<?> path, final InputStream entityStream,
-            final boolean isPost) throws IOException {
+    private static NormalizedNodeContext readFrom(
+            final InstanceIdentifierContext<?> path, final InputStream entityStream, final boolean isPost)
+            throws IOException {
         if (entityStream.available() < 1) {
             return new NormalizedNodeContext(path, null);
         }
@@ -102,15 +87,16 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
         final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
 
         final SchemaNode parentSchema;
-        if(isPost) {
+        if (isPost) {
             parentSchema = path.getSchemaNode();
-        } else if(path.getSchemaNode() instanceof SchemaContext) {
+        } else if (path.getSchemaNode() instanceof SchemaContext) {
             parentSchema = path.getSchemaContext();
         } else {
             if (SchemaPath.ROOT.equals(path.getSchemaNode().getPath().getParent())) {
                 parentSchema = path.getSchemaContext();
             } else {
-                parentSchema = SchemaContextUtil.findDataSchemaNode(path.getSchemaContext(), path.getSchemaNode().getPath().getParent());
+                parentSchema = SchemaContextUtil
+                        .findDataSchemaNode(path.getSchemaContext(), path.getSchemaNode().getPath().getParent());
             }
         }
 
@@ -122,8 +108,8 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
         final List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
         InstanceIdentifierContext<? extends SchemaNode> newIIContext;
 
-        while ((result instanceof AugmentationNode) || (result instanceof ChoiceNode)) {
-            final Object childNode = ((DataContainerNode) result).getValue().iterator().next();
+        while (result instanceof AugmentationNode || result instanceof ChoiceNode) {
+            final Object childNode = ((DataContainerNode<?>) result).getValue().iterator().next();
             if (isPost) {
                 iiToDataList.add(result.getIdentifier());
             }
@@ -152,6 +138,24 @@ public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPr
         return new NormalizedNodeContext(newIIContext, result);
     }
 
+    private static void propagateExceptionAs(final Exception exception) throws RestconfDocumentedException {
+        if (exception instanceof RestconfDocumentedException) {
+            throw (RestconfDocumentedException)exception;
+        }
+
+        if (exception instanceof ResultAlreadySetException) {
+            LOG.debug("Error parsing json input:", exception);
+
+            throw new RestconfDocumentedException("Error parsing json input: Failed to create new parse result data. "
+                    + "Are you creating multiple resources/subresources in POST request?");
+        }
+
+        LOG.debug("Error parsing json input", exception);
+
+        throw new RestconfDocumentedException("Error parsing input: " + exception.getMessage(), ErrorType.PROTOCOL,
+                ErrorTag.MALFORMED_MESSAGE, exception);
+    }
+
     public void injectParams(final UriInfo uriInfo, final Request request) {
         setUriInfo(uriInfo);
         setRequest(request);