Fix findbugs violations in sal-rest-docgen
[netconf.git] / restconf / sal-rest-docgen / src / main / java / org / opendaylight / netconf / sal / rest / doc / impl / ApiDocServiceImpl.java
index ea70f2655170981a9ffa084765595ef312beb3e8..f309982e54bceb9a1c0d060ae6ba9c69b949f0d4 100644 (file)
@@ -7,13 +7,16 @@
  */
 package org.opendaylight.netconf.sal.rest.doc.impl;
 
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
 import java.util.Map.Entry;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
-import org.json.JSONWriter;
 import org.opendaylight.netconf.sal.rest.doc.api.ApiDocService;
 import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointSwagger;
 import org.opendaylight.netconf.sal.rest.doc.swagger.ApiDeclaration;
@@ -85,20 +88,27 @@ public class ApiDocServiceImpl implements ApiDocService {
     public synchronized Response getListOfMounts(final UriInfo uriInfo) {
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
         try (OutputStreamWriter streamWriter = new OutputStreamWriter(baos, StandardCharsets.UTF_8)) {
-            final JSONWriter writer = new JSONWriter(streamWriter);
-            writer.array();
+            JsonGenerator writer = new JsonFactory().createGenerator(streamWriter);
+            writer.writeStartArray();
             for (final Entry<String, Long> entry : MountPointSwagger.getInstance().getInstanceIdentifiers()
                     .entrySet()) {
-                writer.object();
-                writer.key("instance").value(entry.getKey());
-                writer.key("id").value(entry.getValue());
-                writer.endObject();
+                writer.writeStartObject();
+                writer.writeObjectField("instance", entry.getKey());
+                writer.writeObjectField("id", entry.getValue());
+                writer.writeEndObject();
             }
-            writer.endArray();
-        } catch (final Exception e) {
-            return Response.status(500).entity(e.getMessage()).build();
+            writer.writeEndArray();
+            writer.flush();
+        } catch (IOException e) {
+            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
+        }
+
+        try {
+            String responseStr = baos.toString(StandardCharsets.UTF_8.name());
+            return Response.status(Response.Status.OK).entity(responseStr).build();
+        } catch (UnsupportedEncodingException e) {
+            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
         }
-        return Response.status(200).entity(baos.toString()).build();
     }
 
     @Override