Adding post method with String return type

Change-Id: I4483ad2494ccaca08f7460de212e432d46cba710
diff --git a/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/RestSBController.java b/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/RestSBController.java
index b25915b..ed79fd9 100644
--- a/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/RestSBController.java
+++ b/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/RestSBController.java
@@ -78,6 +78,20 @@
     boolean post(DeviceId device, String request, InputStream payload, String mediaType);
 
     /**
+     * Does a REST POST request with specified parameters to the device.
+     *
+     * @param device        device to make the request to
+     * @param request       url of the request
+     * @param payload       payload of the request as an InputStream
+     * @param mediaType     type of content in the payload i.e. application/json
+     * @param responseClass the type of response object we are interested in,
+     *                      such as String, InputStream.
+     * @return Object of type requested via responseClass.
+     */
+    <T> T post(DeviceId device, String request, InputStream payload,
+               String mediaType, Class<T> responseClass);
+
+    /**
      * Does a REST PUT request with specified parameters to the device.
      *
      * @param device    device to make the request to
diff --git a/protocols/rest/ctl/src/main/java/org/onosproject/protocol/rest/ctl/RestSBControllerImpl.java b/protocols/rest/ctl/src/main/java/org/onosproject/protocol/rest/ctl/RestSBControllerImpl.java
index 424914f..47372cd 100644
--- a/protocols/rest/ctl/src/main/java/org/onosproject/protocol/rest/ctl/RestSBControllerImpl.java
+++ b/protocols/rest/ctl/src/main/java/org/onosproject/protocol/rest/ctl/RestSBControllerImpl.java
@@ -134,6 +134,22 @@
 
     @Override
     public boolean post(DeviceId device, String request, InputStream payload, String mediaType) {
+        Response response = getResponse(device, request, payload, mediaType);
+        return checkReply(response);
+    }
+
+    @Override
+    public <T> T post(DeviceId device, String request, InputStream payload,
+                      String mediaType, Class<T> responseClass) {
+        Response response = getResponse(device, request, payload, mediaType);
+        if (response.hasEntity()) {
+            return response.readEntity(responseClass);
+        }
+        log.error("Response from device {} for request {} contains no entity", device, request);
+        return null;
+    }
+
+    private Response getResponse(DeviceId device, String request, InputStream payload, String mediaType) {
         WebTarget wt = getWebTarget(device, request);
 
         Response response = null;
@@ -148,7 +164,7 @@
         } else {
             response = wt.request(mediaType).post(Entity.entity(null, mediaType));
         }
-        return checkReply(response);
+        return response;
     }
 
     @Override
@@ -189,7 +205,7 @@
         Response s = wt.request(type).get();
         if (checkReply(s)) {
             return new ByteArrayInputStream(wt.request(type)
-                    .get(String.class).getBytes(StandardCharsets.UTF_8));
+                                                    .get(String.class).getBytes(StandardCharsets.UTF_8));
         }
         return null;
     }
@@ -305,7 +321,6 @@
                 public X509Certificate[] getAcceptedIssuers() {
                     return new X509Certificate[0];
                 }
-
             } }, new java.security.SecureRandom());
         } catch (NoSuchAlgorithmException | KeyManagementException e) {
             e.printStackTrace();