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/exception/AndroidOperationException.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/exception/AndroidOperationException.java deleted file mode 100644 index 6cd49eded9..0000000000 --- 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/exception/AndroidOperationException.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.android.api.exception; - -import org.wso2.carbon.device.mgt.mobile.android.common.Message; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -/** - * Custom exception class for wrapping Android Operation related exceptions. - */ -public class AndroidOperationException extends WebApplicationException { - - public AndroidOperationException(Message message, MediaType mediaType) { - super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message). - type(mediaType).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/exception/BadRequestException.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/exception/BadRequestException.java deleted file mode 100644 index a93e39a8ed..0000000000 --- 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/exception/BadRequestException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.android.api.exception; - -import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; - -/** - * Custom exception class for wrapping BadRequest related exceptions. - */ -public class BadRequestException extends WebApplicationException { - - public BadRequestException(ErrorResponse error) { - super(Response.status(Response.Status.BAD_REQUEST).entity(error).build()); - } -} \ No newline at end of file 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/exception/ForbiddenException.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/exception/ForbiddenException.java deleted file mode 100644 index 9c0741ded8..0000000000 --- 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/exception/ForbiddenException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.android.api.exception; - -import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants; -import org.wso2.carbon.device.mgt.mobile.android.common.dto.ErrorDTO; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; - -/** - * Exception class that is corresponding to 401 Forbidden response - */ - -public class ForbiddenException extends WebApplicationException { - - private String message; - - public ForbiddenException() { - super(Response.status(Response.Status.FORBIDDEN) - .build()); - } - - public ForbiddenException(ErrorDTO errorDTO) { - super(Response.status(Response.Status.FORBIDDEN) - .entity(errorDTO) - .header(AndroidConstants.HEADER_CONTENT_TYPE, AndroidConstants.APPLICATION_JSON) - .build()); - message = errorDTO.getDescription(); - } - - @Override - public String getMessage() { - return message; - } -} 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/exception/GlobalThrowableMapper.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/exception/GlobalThrowableMapper.java deleted file mode 100644 index 9d0c7fdc6a..0000000000 --- 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/exception/GlobalThrowableMapper.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.android.api.exception; - -import com.google.gson.JsonParseException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.android.common.dto.ErrorDTO; -import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils; - -import javax.naming.AuthenticationException; -import javax.validation.ConstraintViolationException; -import javax.ws.rs.ClientErrorException; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; - -/** - * Handle the cxf level exceptions. - */ -public class GlobalThrowableMapper implements ExceptionMapper { - private static final Log log = LogFactory.getLog(GlobalThrowableMapper.class); - - private ErrorDTO e500 = new ErrorDTO(); - - GlobalThrowableMapper() { - e500.setCode((long) 500); - e500.setMessage("Internal server error."); - e500.setMoreInfo(""); - e500.setDescription("The server encountered an internal error. Please contact administrator."); - - } - - @Override - public Response toResponse(Throwable e) { - - if (e instanceof JsonParseException) { - String errorMessage = "Malformed request body."; - if (log.isDebugEnabled()) { - log.debug(errorMessage, e); - } - return new BadRequestException(AndroidDeviceUtils.buildBadRequestException(errorMessage)).getResponse(); - } - if (e instanceof NotFoundException) { - return ((NotFoundException) e).getResponse(); - } - if (e instanceof BadRequestException) { - return ((BadRequestException) e).getResponse(); - } - if (e instanceof UnexpectedServerErrorException) { - if (log.isDebugEnabled()) { - log.debug("Unexpected server error", e); - } - return ((UnexpectedServerErrorException) e).getResponse(); - } - if (e instanceof ConstraintViolationException) { - if (log.isDebugEnabled()) { - log.debug("Constraint violation issue.", e); - return ((ParameterValidationException) e).getResponse(); - } - } - if (e instanceof IllegalArgumentException) { - ErrorDTO errorDetail = new ErrorDTO(); - errorDetail.setCode((long) 400); - errorDetail.setMoreInfo(""); - errorDetail.setMessage(""); - errorDetail.setDescription(e.getMessage()); - return Response - .status(Response.Status.BAD_REQUEST) - .entity(errorDetail) - .build(); - } - if (e instanceof ClientErrorException) { - if (log.isDebugEnabled()) { - log.debug("Client error", e); - } - return ((ClientErrorException) e).getResponse(); - } - if (e instanceof AuthenticationException) { - ErrorDTO errorDetail = new ErrorDTO(); - errorDetail.setCode((long) 401); - errorDetail.setMoreInfo(""); - errorDetail.setMessage(""); - errorDetail.setDescription(e.getMessage()); - return Response - .status(Response.Status.UNAUTHORIZED) - .entity(errorDetail) - .build(); - } - if (e instanceof ForbiddenException) { - if (log.isDebugEnabled()) { - log.debug("Resource forbidden", e); - } - return ((ForbiddenException) e).getResponse(); - } - //unknown exception log and return - log.error("An Unknown exception has been captured by global exception mapper.", e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).header("Content-Type", "application/json") - .entity(e500).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/exception/NotFoundException.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/exception/NotFoundException.java deleted file mode 100644 index 59367917b1..0000000000 --- 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/exception/NotFoundException.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.mobile.android.api.exception; - -import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants; -import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; -import org.wso2.carbon.device.mgt.mobile.android.common.dto.ErrorDTO; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; - -public class NotFoundException extends WebApplicationException { - private String message; - private static final long serialVersionUID = 147943572342342340L; - - public NotFoundException(ErrorResponse error) { - super(Response.status(Response.Status.NOT_FOUND).entity(error).build()); - } - public NotFoundException(ErrorDTO errorDTO) { - super(Response.status(Response.Status.NOT_FOUND) - .entity(errorDTO) - .header(AndroidConstants.HEADER_CONTENT_TYPE, AndroidConstants.APPLICATION_JSON) - .build()); - message = errorDTO.getDescription(); - } - - @Override - public String getMessage() { - return message; - } -} 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/exception/ParameterValidationException.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/exception/ParameterValidationException.java deleted file mode 100644 index bf729a9e92..0000000000 --- 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/exception/ParameterValidationException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.mobile.android.api.exception; - -import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants; -import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils; - -import javax.validation.ConstraintViolation; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; -import java.util.Set; - -public class ParameterValidationException extends WebApplicationException { - - private String message; - public ParameterValidationException(Set> violations) { - super(Response.status(Response.Status.BAD_REQUEST) - .entity(AndroidDeviceUtils.getConstraintViolationErrorDTO(violations)) - .header(AndroidConstants.HEADER_CONTENT_TYPE, AndroidConstants.APPLICATION_JSON) - .build()); - - //Set the error message - StringBuilder stringBuilder = new StringBuilder(); - for (ConstraintViolation violation : violations) { - stringBuilder.append(violation.getRootBeanClass().getSimpleName()); - stringBuilder.append("."); - stringBuilder.append(violation.getPropertyPath()); - stringBuilder.append(": "); - stringBuilder.append(violation.getMessage()); - stringBuilder.append(", "); - } - message = stringBuilder.toString(); - } - - @Override - public String getMessage() { - return message; - } - -} 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/exception/UnexpectedServerErrorException.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/exception/UnexpectedServerErrorException.java deleted file mode 100644 index c4390aaa7e..0000000000 --- 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/exception/UnexpectedServerErrorException.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.wso2.carbon.device.mgt.mobile.android.api.exception; - -import org.wso2.carbon.device.mgt.mobile.android.common.AndroidConstants; -import org.wso2.carbon.device.mgt.mobile.android.common.bean.ErrorResponse; -import org.wso2.carbon.device.mgt.mobile.android.common.dto.ErrorDTO; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; - -public class UnexpectedServerErrorException extends WebApplicationException { - private String message; - private static final long serialVersionUID = 147943579458906890L; - - public UnexpectedServerErrorException(ErrorResponse error) { - super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build()); - } - public UnexpectedServerErrorException(ErrorDTO errorDTO) { - super(Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity(errorDTO) - .header(AndroidConstants.HEADER_CONTENT_TYPE, AndroidConstants.APPLICATION_JSON) - .build()); - message = errorDTO.getDescription(); - } - - @Override - public String getMessage() { - return message; - } - - -} 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 438a31f4ef..3011763d8e 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 @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.mobile.android.api.impl; import com.google.api.client.http.HttpStatusCodes; -import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; 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 5523186c97..b3afc3e282 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,6 @@ -