From f5ff9ed0e62f4a511e5f725e0e09e3b266aac098 Mon Sep 17 00:00:00 2001 From: Murali-P Date: Mon, 16 Apr 2018 17:49:28 +0530 Subject: Error message in wrong format Convert entity to JSON Issue-ID: VNFSDK-233 Change-Id: Ide6530607080e93bdea97269a8a4f49a018f6e5f Signed-off-by: Murali-P --- .../marketplace/common/CommonErrorResponse.java | 31 +++++++++++++--------- .../vnfsdk/marketplace/wrapper/PackageWrapper.java | 15 +++++++---- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java index 967d0039..a78ebac5 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/common/CommonErrorResponse.java @@ -13,24 +13,29 @@ * 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; + } + +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java index 3fbdd94d..8feab3f8 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java @@ -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(); -- cgit 1.2.3-korg