From d5297cf36e365801b39fc0c70cf3e9909fe034da Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 19 Aug 2016 19:40:23 +0530 Subject: [PATCH] fixing empty device enrollment body exception --- .../{exception => common}/ValidationInterceptor.java | 2 +- .../services/impl/DeviceManagementServiceImpl.java | 8 +++++++- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) rename components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/{exception => common}/ValidationInterceptor.java (98%) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ValidationInterceptor.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ValidationInterceptor.java similarity index 98% rename from components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ValidationInterceptor.java rename to components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ValidationInterceptor.java index 172a1e5ff..a563f09d1 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/exception/ValidationInterceptor.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/common/ValidationInterceptor.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.mdm.services.android.exception; +package org.wso2.carbon.mdm.services.android.common; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java index fc88819ee..805c2dd24 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementServiceImpl.java @@ -32,7 +32,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidApplication; import org.wso2.carbon.mdm.services.android.bean.wrapper.AndroidDevice; -import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; +import org.wso2.carbon.mdm.services.android.exception.*; import org.wso2.carbon.mdm.services.android.services.DeviceManagementService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.AndroidConstants; @@ -192,6 +192,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @POST @Override public Response enrollDevice(@Valid AndroidDevice androidDevice) { + if (androidDevice == null) { + String errorMessage = "The payload of the android device enrollment is incorrect."; + log.error(errorMessage); + throw new org.wso2.carbon.mdm.services.android.exception.BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } try { Device device = new Device(); device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 5423cba71..7c07ebd28 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -44,7 +44,7 @@ - +