From 74050d6db5bc2d8fee95f7088fe8db15c53ccbf8 Mon Sep 17 00:00:00 2001 From: Shamalka Navod Date: Sun, 19 Apr 2020 13:44:09 +0000 Subject: [PATCH] Improve APPM application name validating API --- .../services/ApplicationManagementPublisherAPI.java | 12 +++++------- .../impl/ApplicationManagementPublisherAPIImpl.java | 7 +++---- .../ui/request/interceptor/InvokerHandler.java | 3 ++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java index 91d17cff5b9..e566eda6082 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementPublisherAPI.java @@ -53,7 +53,6 @@ import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; -import javax.ws.rs.HEAD; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; @@ -716,10 +715,10 @@ public interface ApplicationManagementPublisherAPI { @Multipart(value = "screenshot3") Attachment screenshot3 ); - @HEAD + @GET @Path("/device-type/{deviceType}/app-name/{appName}") @ApiOperation( - httpMethod = "HEAD", + httpMethod = "GET", value = "Check the application existence", notes = "This API is responsible to check whether application exist or not for the given device type and " + "application name.", @@ -734,11 +733,10 @@ public interface ApplicationManagementPublisherAPI { value = { @ApiResponse( code = 200, - message = "OK. \n Application exists."), + message = "OK. \n Application doesn't exists."), @ApiResponse( - code = 404, - message = "NOT FOUND. \n Could.t find an application for given device type and application " - + "name."), + code = 409, + message = "CONFLICT. \n Application exists"), @ApiResponse( code = 400, message = "Bad Request. \n Found invalid device type with the request."), diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index 033dfaf0cae..52cd45fc28a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -59,7 +59,6 @@ import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; -import javax.ws.rs.HEAD; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; @@ -386,7 +385,7 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem } @Override - @HEAD + @GET @Path("/device-type/{deviceType}/app-name/{appName}") public Response isExistingApplication( @PathParam("deviceType") String deviceType, @@ -394,9 +393,9 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem try { ApplicationManager applicationManager = APIUtil.getApplicationManager(); if (applicationManager.isExistingAppName(appName, deviceType)) { - return Response.status(Response.Status.OK).build(); + return Response.status(Response.Status.CONFLICT).build(); } - return Response.status(Response.Status.NOT_FOUND).build(); + return Response.status(Response.Status.OK).build(); } catch (BadRequestException e) { log.error("Found invalid device type to check application existence.", e); return Response.status(Response.Status.BAD_REQUEST).build(); diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/InvokerHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/InvokerHandler.java index 348f51430bf..49536194ba6 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/InvokerHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/InvokerHandler.java @@ -254,7 +254,8 @@ public class InvokerHandler extends HttpServlet { */ private String generateBackendRequestURL(HttpServletRequest req) { StringBuilder urlBuilder = new StringBuilder(); - urlBuilder.append(apiEndpoint).append(HandlerConstants.API_COMMON_CONTEXT).append(req.getPathInfo()); + urlBuilder.append(apiEndpoint).append(HandlerConstants.API_COMMON_CONTEXT) + .append(req.getPathInfo().replace(" ", "%20")); if (StringUtils.isNotEmpty(req.getQueryString())) { urlBuilder.append("?").append(req.getQueryString()); }