From 624e7df6889cd994b522deffd10a29e3a76b817c Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 27 Jun 2016 16:28:49 +0530 Subject: [PATCH] Improving HTTP status code handling and the resource implementations --- .../api/ConfigurationManagementService.java | 10 ++++----- .../service/api/RoleManagementService.java | 6 ----- .../service/api/UserManagementService.java | 15 +++++-------- .../impl/ConfigurationServiceImpl.java | 22 ++++++++++--------- .../PolicyManagementServiceComponent.java | 2 +- .../mgt/core/util/PolicyManagerUtil.java | 2 +- 6 files changed, 24 insertions(+), 33 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java index ab067e0e19..5cbe24305d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java @@ -68,13 +68,14 @@ public interface ConfigurationManagementService { }), @ApiResponse( code = 304, - message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."), + message = "Not Modified. \n Empty body because the client has already the latest version of " + + "the requested resource."), @ApiResponse( code = 406, message = "Not Acceptable.\n The requested media type is not supported"), @ApiResponse( code = 500, - message = "Internal Server ErrorResponse. \n Server error occurred while fetching the general " + + message = "Internal Server Error. \n Server error occurred while fetching the general " + "platform configuration.", response = ErrorResponse.class) }) @@ -100,9 +101,6 @@ public interface ConfigurationManagementService { code = 200, message = "OK. \n General platform configuration has been updated successfully", responseHeaders = { - @ResponseHeader( - name = "Content-Location", - description = "URL of the updated general platform configuration."), @ResponseHeader( name = "Content-Type", description = "The content type of the body"), @@ -122,7 +120,7 @@ public interface ConfigurationManagementService { message = "Unsupported media type. \n The entity of the request was in a not supported format."), @ApiResponse( code = 500, - message = "Internal Server ErrorResponse. \n " + + message = "Internal Server Error. \n " + "Server error occurred while modifying general platform configuration.", response = ErrorResponse.class) }) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java index c58604a4a0..a42758e215 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java @@ -308,9 +308,6 @@ public interface RoleManagementService { code = 200, message = "OK. \n Role has been updated successfully", responseHeaders = { - @ResponseHeader( - name = "Content-Location", - description = "URL of the updated role."), @ResponseHeader( name = "Content-Type", description = "Content type of the body"), @@ -404,9 +401,6 @@ public interface RoleManagementService { code = 200, message = "OK. \n User list of the role has been updated successfully", responseHeaders = { - @ResponseHeader( - name = "Content-Location", - description = "URL of the updated user list."), @ResponseHeader( name = "Content-Type", description = "Content type of the body"), diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index 2429c805ce..781cce69a9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -162,9 +162,6 @@ public interface UserManagementService { code = 200, message = "OK. \n User has been updated successfully", responseHeaders = { - @ResponseHeader( - name = "Content-Location", - description = "URL of the updated user."), @ResponseHeader( name = "Content-Type", description = "Content type of the body"), @@ -190,7 +187,7 @@ public interface UserManagementService { response = ErrorResponse.class), @ApiResponse( code = 500, - message = "Internal Server ErrorResponse. \n " + + message = "Internal Server Error. \n " + "Server error occurred while updating the user.", response = ErrorResponse.class) }) @@ -224,7 +221,7 @@ public interface UserManagementService { response = ErrorResponse.class), @ApiResponse( code = 500, - message = "Internal Server ErrorResponse. \n " + + message = "Internal Server Error. \n " + "Server error occurred while removing the user.", response = ErrorResponse.class ) @@ -274,7 +271,7 @@ public interface UserManagementService { response = ErrorResponse.class), @ApiResponse( code = 500, - message = "Internal Server ErrorResponse. \n Server error occurred while fetching the role list" + + message = "Internal Server Error. \n Server error occurred while fetching the role list" + " assigned to the user.", response = ErrorResponse.class) }) @@ -318,7 +315,7 @@ public interface UserManagementService { response = ErrorResponse.class), @ApiResponse( code = 500, - message = "Internal Server ErrorResponse. \n Server error occurred while fetching the user list.", + message = "Internal Server Error. \n Server error occurred while fetching the user list.", response = ErrorResponse.class) }) @Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"}) @@ -384,7 +381,7 @@ public interface UserManagementService { response = ErrorResponse.class), @ApiResponse( code = 500, - message = "Internal Server ErrorResponse. \n Server error occurred while fetching the username " + + message = "Internal Server Error. \n Server error occurred while fetching the username " + "list that matches the given filter.", response = ErrorResponse.class) }) @@ -438,7 +435,7 @@ public interface UserManagementService { response = ErrorResponse.class), @ApiResponse( code = 500, - message = "Internal Server ErrorResponse. \n " + + message = "Internal Server Error. \n " + "Server error occurred while updating credentials of the user.", response = ErrorResponse.class) }) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java index c10e82e762..0c082722fd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ConfigurationServiceImpl.java @@ -55,19 +55,19 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService ConfigurationEntry configurationEntry = new ConfigurationEntry(); configurationEntry.setContentType("text"); configurationEntry.setName("notifierFrequency"); - configurationEntry.setValue(PolicyManagerUtil.getMonitoringFequency()); + configurationEntry.setValue(PolicyManagerUtil.getMonitoringFrequency()); List configList = config.getConfiguration(); if (configList == null) { configList = new ArrayList<>(); configList.add(configurationEntry); } config.setConfiguration(configList); - return Response.status(Response.Status.OK).entity(config).build(); + return Response.ok().entity(config).build(); } catch (ConfigurationManagementException | PolicyManagementException e) { - msg = "ErrorResponse occurred while retrieving the configurations."; + msg = "Error occurred while retrieving the general platform configuration"; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } } @@ -80,13 +80,15 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH); //Schedule the task service DeviceMgtAPIUtils.scheduleTaskService(DeviceMgtAPIUtils.getNotifierFrequency(config)); - return Response.status(Response.Status.CREATED) - .entity("Configuration has successfully been updated").build(); + + PlatformConfiguration updatedConfig = DeviceMgtAPIUtils.getPlatformConfigurationManagementService(). + getConfiguration(MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH); + return Response.ok().entity(updatedConfig).build(); } catch (ConfigurationManagementException e) { - String msg = "ErrorResponse occurred while updating the configuration."; + String msg = "Error occurred while updating the general platform configuration"; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java index 13711f43b0..0c456fce28 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java @@ -91,7 +91,7 @@ public class PolicyManagementServiceComponent { DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getPolicyConfiguration(); if(policyConfiguration.getMonitoringEnable()) { TaskScheduleService taskScheduleService = new TaskScheduleServiceImpl(); - taskScheduleService.startTask(PolicyManagerUtil.getMonitoringFequency()); + taskScheduleService.startTask(PolicyManagerUtil.getMonitoringFrequency()); } } catch (Throwable t) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java index c0e587b857..0d80901d21 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java @@ -196,7 +196,7 @@ public class PolicyManagerUtil { } - public static int getMonitoringFequency() throws PolicyManagementException { + public static int getMonitoringFrequency() throws PolicyManagementException { PlatformConfigurationManagementService configMgtService = new PlatformConfigurationManagementServiceImpl(); PlatformConfiguration tenantConfiguration;