diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
index 0876d99c1f2..127e554f50f 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml
@@ -248,6 +248,14 @@
jackson-annotationsprovided
+
+ org.hibernate
+ hibernate-validator
+
+
+ javax.ws.rs
+ javax.ws.rs-api
+
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ErrorResponse.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ErrorResponse.java
index 8804fa3add6..c695932eaef 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ErrorResponse.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ErrorResponse.java
@@ -34,7 +34,7 @@ public class ErrorResponse {
private String moreInfo = null;
private List errorItems = new ArrayList<>();
- private ErrorResponse() {
+ public ErrorResponse() {
}
@JsonProperty(value = "code")
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java
index 1795e299829..c0c768eeb29 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java
@@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import javax.validation.constraints.Size;
import java.util.List;
@ApiModel(value = "PolicyWrapper", description = "This class carries all information related to Policy "
@@ -29,9 +30,11 @@ import java.util.List;
public class PolicyWrapper {
@ApiModelProperty(name = "policyName", value = "The name of the policy", required = true)
+ @Size(max = 45)
private String policyName;
@ApiModelProperty(name = "description", value = "Gives a description on the policy", required = true)
+ @Size(max = 1000)
private String description;
@ApiModelProperty(name = "compliance", value = "Provides the non-compliance rules. WSO2 EMM provides the"
@@ -41,6 +44,7 @@ public class PolicyWrapper {
+ "Monitor - If the device does not adhere to the given policies the server is notified of the "
+ "violation unknown to the user and the administrator can take the necessary actions with regard"
+ " to the reported", required = true)
+ @Size(max = 100)
private String compliance;
@ApiModelProperty(name = "ownershipType", value = "The policy ownership type. It can be any of the "
@@ -49,6 +53,7 @@ public class PolicyWrapper {
+ "BYOD (Bring Your Own Device) - The policy will only be applied on the BYOD device type\n"
+ "COPE (Corporate-Owned, Personally-Enabled) - The policy will only be applied on the COPE "
+ "device type", required = true)
+ @Size(max = 45)
private String ownershipType;
@ApiModelProperty(name = "active", value = "If the value is true it indicates that the policy is active. "
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/Profile.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/Profile.java
index 27aebb2abf2..77bd4f9b636 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/Profile.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/Profile.java
@@ -20,7 +20,6 @@ package org.wso2.carbon.device.mgt.jaxrs.beans;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
-import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/BadRequestException.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/BadRequestException.java
new file mode 100644
index 00000000000..d97b78b6dd6
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/BadRequestException.java
@@ -0,0 +1,34 @@
+/*
+ * 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.jaxrs.exception;
+
+import org.wso2.carbon.device.mgt.jaxrs.beans.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/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ConstraintViolationException.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ConstraintViolationException.java
new file mode 100644
index 00000000000..9664057f610
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ConstraintViolationException.java
@@ -0,0 +1,55 @@
+/*
+ * 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.jaxrs.exception;
+
+import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
+import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
+
+import javax.validation.ConstraintViolation;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import java.util.Set;
+
+public class ConstraintViolationException extends WebApplicationException {
+ private String message;
+
+ public ConstraintViolationException(Set> violations) {
+ super(Response.status(Response.Status.BAD_REQUEST)
+ .entity(DeviceMgtUtil.getConstraintViolationErrorDTO(violations))
+ .header(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.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/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ErrorDTO.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ErrorDTO.java
new file mode 100644
index 00000000000..ff4e0be32a7
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ErrorDTO.java
@@ -0,0 +1,86 @@
+/*
+ * 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.jaxrs.exception;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ErrorDTO {
+
+ private Long code = null;
+ private String message = null;
+ private String description = null;
+
+ public void setMoreInfo(String moreInfo) {
+ this.moreInfo = moreInfo;
+ }
+
+ public void setCode(Long code) {
+ this.code = code;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setError(List error) {
+ this.error = error;
+ }
+
+ private String moreInfo = null;
+
+ public String getMessage() {
+ return message;
+ }
+
+ public Long getCode() {
+ return code;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getMoreInfo() {
+ return moreInfo;
+ }
+
+ public List getError() {
+ return error;
+ }
+
+ public String toString() {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("class ErrorDTO {\n");
+ stringBuilder.append(" code: ").append(code).append("\n");
+ stringBuilder.append(" message: ").append(message).append("\n");
+ stringBuilder.append(" description: ").append(description).append("\n");
+ stringBuilder.append(" moreInfo: ").append(moreInfo).append("\n");
+ stringBuilder.append(" error: ").append(error).append("\n");
+ stringBuilder.append("}\n");
+ return stringBuilder.toString();
+ }
+
+ private List error = new ArrayList<>();
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ForbiddenException.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ForbiddenException.java
new file mode 100644
index 00000000000..912f6246324
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ForbiddenException.java
@@ -0,0 +1,51 @@
+/*
+ * 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.jaxrs.exception;
+
+import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
+
+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(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
+ .build());
+ message = errorDTO.getDescription();
+ }
+
+ @Override
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/GlobalThrowableMapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/GlobalThrowableMapper.java
new file mode 100644
index 00000000000..be3d037a8d7
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/GlobalThrowableMapper.java
@@ -0,0 +1,113 @@
+/*
+ * 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.jaxrs.exception;
+
+import com.google.gson.JsonParseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
+
+import javax.naming.AuthenticationException;
+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.error(errorMessage, e);
+ }
+ return DeviceMgtUtil.buildBadRequestException(errorMessage).getResponse();
+ }
+ if (e instanceof NotFoundException) {
+ return ((NotFoundException) e).getResponse();
+ }
+ if (e instanceof UnexpectedServerErrorException) {
+ if (log.isDebugEnabled()) {
+ log.error("Unexpected server error.", e);
+ }
+ return ((UnexpectedServerErrorException) e).getResponse();
+ }
+ if (e instanceof ConstraintViolationException) {
+ if (log.isDebugEnabled()) {
+ log.error("Constraint violation.", e);
+ }
+ return ((ConstraintViolationException) 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.error("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.error("Resource forbidden.", e);
+ }
+ return ((ForbiddenException) e).getResponse();
+ }
+ //unknown exception log and return
+ if (log.isDebugEnabled()) {
+ 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/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/NotFoundException.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/NotFoundException.java
new file mode 100644
index 00000000000..ac9fc5c5685
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/NotFoundException.java
@@ -0,0 +1,47 @@
+/*
+ * 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.jaxrs.exception;
+
+
+import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
+import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
+
+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(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
+ .build());
+ message = errorDTO.getDescription();
+ }
+
+ @Override
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/UnexpectedServerErrorException.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/UnexpectedServerErrorException.java
new file mode 100644
index 00000000000..40d5d74e682
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/UnexpectedServerErrorException.java
@@ -0,0 +1,49 @@
+/*
+ * 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.jaxrs.exception;
+
+
+import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
+import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
+
+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(Constants.DeviceConstants.HEADER_CONTENT_TYPE, Constants.DeviceConstants.APPLICATION_JSON)
+ .build());
+ message = errorDTO.getDescription();
+ }
+
+ @Override
+ public String getMessage() {
+ return message;
+ }
+
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ValidationInterceptor.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ValidationInterceptor.java
new file mode 100644
index 00000000000..480911b39ba
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/exception/ValidationInterceptor.java
@@ -0,0 +1,122 @@
+/*
+ * 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.jaxrs.exception;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.executable.ExecutableValidator;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Set;
+
+public class ValidationInterceptor extends AbstractPhaseInterceptor {
+ private Log log = LogFactory.getLog(getClass());
+ private Validator validator = null; //validator interface is thread-safe
+
+ public ValidationInterceptor() {
+ super(Phase.PRE_INVOKE);
+ ValidatorFactory defaultFactory = Validation.buildDefaultValidatorFactory();
+ validator = defaultFactory.getValidator();
+ if (validator == null) {
+ log.warn("Bean Validation provider could not be found, no validation will be performed");
+ } else {
+ log.debug("Validation In-Interceptor initialized successfully");
+ }
+ }
+
+ @Override
+ public void handleMessage(Message message) throws Fault {
+ final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
+ if (operationResource == null) {
+ log.info("OperationResourceInfo is not available, skipping validation");
+ return;
+ }
+
+ final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
+ if (classResource == null) {
+ log.info("ClassResourceInfo is not available, skipping validation");
+ return;
+ }
+
+ final ResourceProvider resourceProvider = classResource.getResourceProvider();
+ if (resourceProvider == null) {
+ log.info("ResourceProvider is not available, skipping validation");
+ return;
+ }
+
+ final List