Error message in wrong format 29/43029/2
authorMurali-P <murali.p@huawei.com>
Mon, 16 Apr 2018 12:19:28 +0000 (17:49 +0530)
committerMurali-P <murali.p@huawei.com>
Mon, 16 Apr 2018 12:30:34 +0000 (18:00 +0530)
Convert entity to JSON

Issue-ID: VNFSDK-233

Change-Id: Ide6530607080e93bdea97269a8a4f49a018f6e5f
Signed-off-by: Murali-P <murali.p@huawei.com>
vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java
vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java

index 967d003..a78ebac 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onap.vnfsdk.marketplace.common;
 
+package org.onap.vnfsdk.marketplace.common;
 
 public class CommonErrorResponse {
 
-  private String message;
-  
-  public CommonErrorResponse(String message) {
-           super();
-           this.message = message;
-         }
+    private String statusText;
 
-  public String getMessage() {
-        return message;
+    public CommonErrorResponse(String statusText) {
+        super();
+        this.statusText = statusText;
     }
 
-  public static Object failure(String message) {
-    return message;
-  }
-}
+    @Override
+    public String toString() {
+        return "CommonErrorResponse [statusText=" + statusText + "]";
+    }
 
+    public String getStatusText() {
+        return statusText;
+    }
+
+    public void setStatusText(String statusText) {
+        this.statusText = statusText;
+    }
+
+}
index 3fbdd94..8feab3f 100644 (file)
@@ -38,6 +38,7 @@ import org.eclipse.jetty.http.HttpStatus;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 import org.onap.validation.csar.CsarValidator;
 import org.onap.vnfsdk.marketplace.common.CommonConstant;
+import org.onap.vnfsdk.marketplace.common.CommonErrorResponse;
 import org.onap.vnfsdk.marketplace.common.FileUtil;
 import org.onap.vnfsdk.marketplace.common.RestUtil;
 import org.onap.vnfsdk.marketplace.common.ToolUtil;
@@ -257,7 +258,8 @@ public class PackageWrapper {
         if(!bResult) {
             LOG.error("Validation of Input received for Package Upload failed !!!");
             return Response.status(Status.EXPECTATION_FAILED)
-                    .entity("Input package is empty or exception happened during validation").build();
+                    .entity(new CommonErrorResponse("Input package is empty or exception happened during validation"))
+                    .build();
         }
 
         String fileName = "temp_" + packageId + ".csar";
@@ -290,19 +292,22 @@ public class PackageWrapper {
             String validationResp = cv.validateCsar();
             if("SUCCESS" != validationResp) {
                 LOG.error("Could not validate failed");
-                return Response.status(Status.EXPECTATION_FAILED).entity(validationResp).build();
+                return Response.status(Status.EXPECTATION_FAILED).entity(new CommonErrorResponse(validationResp))
+                        .build();
             }
         } catch(Exception e) {
             LOG.error("CSAR validation panicked", e);
-            return Response.status(Status.EXPECTATION_FAILED)
-                    .entity("Exception occurred while validating csar package:" + e.getMessage()).build();
+            return Response.status(Status.EXPECTATION_FAILED).entity(
+                    new CommonErrorResponse("Exception occurred while validating csar package:" + e.getMessage()))
+                    .build();
         }
 
         UploadPackageResponse result = null;
         try {
             result = manageUpload(packageId, fileName, fileLocation, details, contentRange);
         } catch(ErrorCodeException e) {
-            return Response.status(Status.EXPECTATION_FAILED).entity("Package Name already exists").build();
+            return Response.status(Status.EXPECTATION_FAILED)
+                    .entity(new CommonErrorResponse("Package Name already exists")).build();
         }
         if(null != result) {
             return Response.ok(ToolUtil.objectToString(result), MediaType.APPLICATION_JSON).build();