diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/AndroidEnterpriseAPIImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/AndroidEnterpriseAPIImpl.java index 1ea0effe3..aa195ed56 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/AndroidEnterpriseAPIImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/AndroidEnterpriseAPIImpl.java @@ -18,6 +18,7 @@ */ package org.wso2.carbon.device.mgt.mobile.android.api.impl; +import com.google.api.client.http.HttpStatusCodes; import com.google.api.services.androidenterprise.model.ProductsListResponse; import com.google.api.services.androidenterprise.model.StoreCluster; import com.google.api.services.androidenterprise.model.StoreLayout; @@ -57,9 +58,7 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.EnterpriseU import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.TokenWrapper; import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseManagedConfig; import org.wso2.carbon.device.mgt.mobile.android.common.dto.AndroidEnterpriseUser; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException; import org.wso2.carbon.device.mgt.mobile.android.common.exception.EnterpriseServiceException; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.NotFoundException; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidEnterpriseUtils; @@ -191,8 +190,9 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { } catch (EnterpriseServiceException e) { String errorMessage = "App install failed. No user found for name " + device.getUsername(); log.error(errorMessage); - throw new NotFoundException( - new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage(errorMessage).build()); + return Response.status(Response.Status.NOT_FOUND).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND) + .setMessage(errorMessage).build()).build(); } if (sentToDevice) { return Response.status(Response.Status.OK).build(); @@ -759,9 +759,9 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { String errorMessage = "App: " + applicationPolicyDTO.getApplicationDTO() .getPackageName() + " for device " + deviceIdentifier.getId(); log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(Response.Status.BAD_REQUEST - .getStatusCode()).setMessage(errorMessage).build()); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(errorMessage).build()).build(); } } googleAPIInvoker.installApps(enterpriseConfigs.getEnterpriseId(), userDetail @@ -783,15 +783,15 @@ public class AndroidEnterpriseAPIImpl implements AndroidEnterpriseAPI { } catch (EnterpriseServiceException e) { String errorMessage = "App install failed for device " + deviceIdentifier.getId(); log.error(errorMessage); - throw new NotFoundException( - new ErrorResponse.ErrorResponseBuilder().setCode(Response.Status.NOT_FOUND - .getStatusCode()).setMessage(errorMessage).build()); + return Response.status(Response.Status.NOT_FOUND).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND) + .setMessage(errorMessage).build()).build(); } catch (FeatureManagementException e) { String errorMessage = "Could not fetch effective policy for device " + deviceIdentifier.getId(); log.error(errorMessage); - throw new NotFoundException( - new ErrorResponse.ErrorResponseBuilder().setCode(Response.Status.INTERNAL_SERVER_ERROR - .getStatusCode()).setMessage(errorMessage).build()); } + return Response.status(Response.Status.NOT_FOUND).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND) + .setMessage(errorMessage).build()).build(); } } if (sentToDevice) { diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAPIImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAPIImpl.java index 633d37231..445593c97 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAPIImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAPIImpl.java @@ -47,10 +47,7 @@ import org.wso2.carbon.device.mgt.mobile.android.common.Message; import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidApplication; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.AndroidDevice; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.UnexpectedServerErrorException; +import org.wso2.carbon.device.mgt.mobile.android.common.exception.*; import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils; @@ -95,8 +92,9 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI { } catch (ApplicationManagementException e) { String msg = "Error occurred while modifying the application list."; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(msg).build()).build(); } } @@ -124,9 +122,15 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI { } catch (DeviceManagementException e) { String msg = "Error occurred while getting pending operations of the device."; log.error(msg, e); - throw new UnexpectedServerErrorException( + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while executing get pending operations"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) - .setMessage(msg).build()); + .setMessage(errorMessage).build()).build(); } } @@ -136,8 +140,9 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI { if (androidDevice == null) { String errorMessage = "The payload of the android device enrollment is incorrect."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) + .setMessage(errorMessage).build()).build(); } try { AndroidService androidService = AndroidAPIUtils.getAndroidService(); @@ -147,8 +152,15 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI { String msg = "Error occurred while enrolling the android, which carries the id '" + androidDevice.getDeviceIdentifier() + "'"; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(msg).build()).build(); + } catch (AndroidDeviceMgtPluginException e) { + String errorMessage = "Error occured while enrolling device"; + log.error(errorMessage, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(errorMessage).build()).build(); } } @@ -164,9 +176,9 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI { } catch (DeviceManagementException e) { String msg = "Error occurred while checking enrollment status of the device."; log.error(msg, e); - throw new UnexpectedServerErrorException( + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) - .setMessage(msg).build()); + .setMessage(msg).build()).build(); } } @@ -193,14 +205,21 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI { String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" + id + "'"; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(msg).build()).build(); } catch (BadRequestExceptionDup e){ String msg = "Invalid request"; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity( new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) .setMessage(msg).build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Class not found"; + log.error(errorMessage, e); + return Response.status(Response.Status.NOT_FOUND).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND) + .setMessage(errorMessage).build()).build(); } catch (AndroidDeviceMgtPluginException e) { String errorMessage = "Error occured"; log.error(errorMessage, e); @@ -232,8 +251,9 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI { String msg = "Error occurred while %s the Android device that carries the id '" + id + "'"; msg = String.format(msg, "dis-enrolling"); log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(msg).build()).build(); } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAdminAPIImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAdminAPIImpl.java index a7032677e..f186cd28b 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAdminAPIImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceManagementAdminAPIImpl.java @@ -90,7 +90,6 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WipeDataBea import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException; import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceTypeConfigurationAPIImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceTypeConfigurationAPIImpl.java index 7635e1e8a..03015fe74 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceTypeConfigurationAPIImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/DeviceTypeConfigurationAPIImpl.java @@ -46,7 +46,6 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestException; import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup; -import org.wso2.carbon.device.mgt.mobile.android.common.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; @@ -78,9 +77,9 @@ public class DeviceTypeConfigurationAPIImpl implements DeviceTypeConfigurationAP } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving the Android tenant configuration"; log.error(msg, e); - throw new UnexpectedServerErrorException( + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) - .setMessage(msg).build()); + .setMessage(msg).build()).build(); } } @@ -102,9 +101,9 @@ public class DeviceTypeConfigurationAPIImpl implements DeviceTypeConfigurationAP } catch (AndroidDeviceMgtPluginException e) { String msg = "Error occurred while modifying configuration settings of Android platform"; log.error(msg, e); - throw new UnexpectedServerErrorException( + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) - .setMessage(msg).build()); + .setMessage(msg).build()).build(); } } @@ -122,9 +121,9 @@ public class DeviceTypeConfigurationAPIImpl implements DeviceTypeConfigurationAP } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving the license configured for Android device enrolment"; log.error(msg, e); - throw new UnexpectedServerErrorException( + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) - .setMessage(msg).build()); + .setMessage(msg).build()).build(); } } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/EventReceiverAPIImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/EventReceiverAPIImpl.java index 4d55877c7..172a02809 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/EventReceiverAPIImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/device/mgt/mobile/android/api/impl/EventReceiverAPIImpl.java @@ -110,15 +110,18 @@ public class EventReceiverAPIImpl implements EventReceiverAPI { log.warn("Error occurred while trying to publish the event. This could be due to unavailability " + "of the publishing service. Please make sure that analytics server is running and accessible " + "by this server"); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(503l).setMessage("Error occurred due to " + - "unavailability of the publishing service.").build()); + String msg = "Error occurred due to " + + "unavailability of the publishing service."; + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(msg).build()).build(); } } catch (DataPublisherConfigurationException e) { String msg = "Error occurred while getting the Data publisher Service instance."; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) + .setMessage(msg).build()).build(); } } @@ -142,6 +145,12 @@ public class EventReceiverAPIImpl implements EventReceiverAPI { return Response.status(Response.Status.BAD_REQUEST).entity( new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST) .setMessage(msg).build()).build(); + } catch (NotFoundExceptionDup e) { + String errorMessage = "Class not found"; + log.error(errorMessage, e); + return Response.status(Response.Status.NOT_FOUND).entity( + new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND) + .setMessage(errorMessage).build()).build(); } catch (AndroidDeviceMgtPluginException e) { String errorMessage = "Error occured while retrieving alerts"; log.error(errorMessage, e); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/exception/UnexpectedServerErrorExceptionDup.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/exception/UnexpectedServerErrorExceptionDup.java new file mode 100644 index 000000000..156404ef3 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/exception/UnexpectedServerErrorExceptionDup.java @@ -0,0 +1,12 @@ +package org.wso2.carbon.device.mgt.mobile.android.common.exception; + +public class UnexpectedServerErrorExceptionDup extends AndroidDeviceMgtPluginException{ + + public UnexpectedServerErrorExceptionDup(String message, Throwable ex) { + super(message, ex); + } + + public UnexpectedServerErrorExceptionDup(String message) { + super(message); + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/spi/AndroidService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/spi/AndroidService.java index b6565ad95..18d16ce31 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/spi/AndroidService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.common/src/main/java/org/wso2/carbon/device/mgt/mobile/android/common/spi/AndroidService.java @@ -418,7 +418,7 @@ public interface AndroidService { */ List getPendingOperations (String id, List resultOperations, boolean disableGoogleApps) - throws DeviceManagementException, InvalidDeviceException; + throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException; /** * Method to enroll device @@ -427,7 +427,7 @@ public interface AndroidService { * @return {@link Response} * @throws {@link DeviceManagementException} */ - Response enrollDevice(AndroidDevice androidDevice) throws DeviceManagementException; + Response enrollDevice(AndroidDevice androidDevice) throws DeviceManagementException, AndroidDeviceMgtPluginException; /** * Method to check if a device is enrolled diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/main/java/org/wso2/carbon/device/mgt/mobile/android/core/impl/AndroidServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/main/java/org/wso2/carbon/device/mgt/mobile/android/core/impl/AndroidServiceImpl.java index 3d4562abb..a3043f352 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/main/java/org/wso2/carbon/device/mgt/mobile/android/core/impl/AndroidServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.core/src/main/java/org/wso2/carbon/device/mgt/mobile/android/core/impl/AndroidServiceImpl.java @@ -274,8 +274,7 @@ public class AndroidServiceImpl implements AndroidService { if (deviceLockBeanWrapper == null || deviceLockBeanWrapper.getOperation() == null) { String errorMessage = "Lock bean is empty."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } DeviceLock lock = deviceLockBeanWrapper.getOperation(); ProfileOperation operation = new ProfileOperation(); @@ -346,8 +345,7 @@ public class AndroidServiceImpl implements AndroidService { if (cameraBeanWrapper == null || cameraBeanWrapper.getOperation() == null) { String errorMessage = "The payload of the configure camera operation is incorrect."; log.error(errorMessage); - throw new BadRequestException( - new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + throw new BadRequestExceptionDup(errorMessage); } Camera camera = cameraBeanWrapper.getOperation(); CommandOperation operation = new CommandOperation(); @@ -850,17 +848,11 @@ public class AndroidServiceImpl implements AndroidService { } catch (OperationManagementException e) { String errorMessage = "Issue in retrieving operation management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder() - .setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) - .setMessage(errorMessage).build()); + throw new UnexpectedServerErrorExceptionDup(errorMessage); } catch (DeviceManagementException e) { String errorMessage = "Issue in retrieving device management service instance"; log.error(errorMessage, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder() - .setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) - .setMessage(errorMessage).build()); + throw new UnexpectedServerErrorExceptionDup(errorMessage, e); } } @@ -923,7 +915,8 @@ public class AndroidServiceImpl implements AndroidService { @Override public List getPendingOperations(String deviceId, List resultOperations, - boolean disableGoogleApps) throws DeviceManagementException, InvalidDeviceException { + boolean disableGoogleApps) + throws DeviceManagementException, InvalidDeviceException, AndroidDeviceMgtPluginException { DeviceIdentifier deviceIdentifier = AndroidDeviceUtils.convertToDeviceIdentifierObject(deviceId); if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) { String msg = "Device not found for identifier '" + deviceId + "'"; @@ -979,14 +972,13 @@ public class AndroidServiceImpl implements AndroidService { } catch (OperationManagementException e) { String msg = "Issue in retrieving operation management service instance"; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR) - .setMessage(msg).build()); + throw new UnexpectedServerErrorExceptionDup(msg, e); } } @Override - public Response enrollDevice(AndroidDevice androidDevice) throws DeviceManagementException { + public Response enrollDevice(AndroidDevice androidDevice) + throws DeviceManagementException, AndroidDeviceMgtPluginException { try { String token = null; Device device = new Device(); @@ -1040,8 +1032,7 @@ public class AndroidServiceImpl implements AndroidService { String msg = "Error occurred while updating the device location upon android " + "', which carries the id '" + androidDevice.getDeviceIdentifier() + "'"; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + throw new UnexpectedServerErrorExceptionDup(msg, e); } } @@ -1096,27 +1087,12 @@ public class AndroidServiceImpl implements AndroidService { androidDevice.getDeviceIdentifier() + "'"); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseMessage).build(); } - } catch (PolicyManagementException e) { - String msg = "Error occurred while enforcing default enrollment policy upon android " + - "', which carries the id '" + - androidDevice.getDeviceIdentifier() + "'"; - log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); - } catch (OperationManagementException e) { - String msg = "Error occurred while enforcing default enrollment policy upon android " + - "', which carries the id '" + - androidDevice.getDeviceIdentifier() + "'"; - log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); - } catch (InvalidDeviceException e) { + } catch (PolicyManagementException | InvalidDeviceException | OperationManagementException e) { String msg = "Error occurred while enforcing default enrollment policy upon android " + "', which carries the id '" + androidDevice.getDeviceIdentifier() + "'"; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + throw new UnexpectedServerErrorExceptionDup(msg, e); } } @@ -1133,8 +1109,7 @@ public class AndroidServiceImpl implements AndroidService { String msg = "Error occurred while getting enrollment details of the Android device that carries the id '" + id + "'"; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + throw new UnexpectedServerErrorExceptionDup(msg, e); } if (androidDevice == null) { @@ -1145,8 +1120,7 @@ public class AndroidServiceImpl implements AndroidService { if (device == null) { String errorMessage = "The device to be modified doesn't exist."; log.error(errorMessage); - throw new NotFoundException( - new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage(errorMessage).build()); + throw new NotFoundExceptionDup(errorMessage); } if(androidDevice.getEnrolmentInfo() != null){ device.setEnrolmentInfo(device.getEnrolmentInfo()); @@ -1222,7 +1196,7 @@ public class AndroidServiceImpl implements AndroidService { } } - private Response retrieveAlert(String deviceId) { + private Response retrieveAlert(String deviceId) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup { if (log.isDebugEnabled()) { log.debug("Retrieving events for given device Identifier."); } @@ -1231,21 +1205,20 @@ public class AndroidServiceImpl implements AndroidService { try { deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); if (deviceStates == null) { - throw new NotFoundException( - new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + - "published for Device: " + deviceId + ".").build()); + String errorMessage = "No any alerts are " + + "published for Device: " + deviceId + "."; + throw new NotFoundExceptionDup(errorMessage); } else { return Response.status(Response.Status.OK).entity(deviceStates).build(); } } catch (AnalyticsException e) { String msg = "Error occurred while getting published events for specific device: " + deviceId + "."; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + throw new UnexpectedServerErrorExceptionDup(msg, e); } } - private Response retrieveAlertFromDate(String deviceId, long from, long to) { + private Response retrieveAlertFromDate(String deviceId, long from, long to) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup { String fromDate = String.valueOf(from); String toDate = String.valueOf(to); if (log.isDebugEnabled()) { @@ -1257,9 +1230,9 @@ public class AndroidServiceImpl implements AndroidService { try { deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); if (deviceStates == null) { - throw new NotFoundException( - new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + - "published on given date for given Device: " + deviceId + ".").build()); + String errorMessage = "No any alerts are " + + "published on given date for given Device: " + deviceId + "."; + throw new NotFoundExceptionDup(errorMessage); } else { return Response.status(Response.Status.OK).entity(deviceStates).build(); @@ -1268,12 +1241,11 @@ public class AndroidServiceImpl implements AndroidService { String msg = "Error occurred while getting published events for specific " + "Device: " + deviceId + " on given Date."; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + throw new UnexpectedServerErrorExceptionDup(msg, e); } } - private Response retrieveAlertByType(String deviceId, String type) { + private Response retrieveAlertByType(String deviceId, String type) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup { if (log.isDebugEnabled()) { log.debug("Retrieving events for given device identifier and type."); } @@ -1282,9 +1254,9 @@ public class AndroidServiceImpl implements AndroidService { try { deviceStates = AndroidDeviceUtils.getAllEventsForDevice(EVENT_STREAM_DEFINITION, query); if (deviceStates == null) { - throw new NotFoundException( - new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No any alerts are " + - "published for given Device: '" + deviceId + "' and given specific Type.").build()); + String errorMessage = "No any alerts are " + + "published for given Device: '" + deviceId + "' and given specific Type."; + throw new NotFoundExceptionDup(errorMessage); } else { return Response.status(Response.Status.OK).entity(deviceStates).build(); @@ -1293,8 +1265,7 @@ public class AndroidServiceImpl implements AndroidService { String msg = "Error occurred while getting published events for specific " + "Device: " + deviceId + "and given specific Type."; log.error(msg, e); - throw new UnexpectedServerErrorException( - new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build()); + throw new UnexpectedServerErrorExceptionDup(msg, e); } }