forked from community/device-mgt-core
parent
9343032c88
commit
dd6e70ce86
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.application.mgt.api;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.services.impl.ApplicationManagementServiceFactory;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds util methods required for Application-Mgt API component.
|
||||||
|
*/
|
||||||
|
public class APIUtil {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(APIUtil.class);
|
||||||
|
|
||||||
|
private static ApplicationManagementServiceFactory applicationManagementServiceFactory;
|
||||||
|
|
||||||
|
public static ApplicationManagementServiceFactory getApplicationManagementServiceFactory() {
|
||||||
|
if (applicationManagementServiceFactory == null) {
|
||||||
|
synchronized (APIUtil.class) {
|
||||||
|
if (applicationManagementServiceFactory == null) {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
applicationManagementServiceFactory =
|
||||||
|
(ApplicationManagementServiceFactory) ctx.getOSGiService(ApplicationManagementServiceFactory.class, null);
|
||||||
|
if (applicationManagementServiceFactory == null) {
|
||||||
|
String msg = "Application Management provider service has not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return applicationManagementServiceFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Response getResponse(ApplicationManagementException ex, Response.Status status) {
|
||||||
|
//TODO: check for exception type and set the response code.
|
||||||
|
ErrorResponse errorMessage = new ErrorResponse();
|
||||||
|
errorMessage.setMessage(ex.getMessage());
|
||||||
|
if (status == null) {
|
||||||
|
status = Response.Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
errorMessage.setCode(status.getStatusCode());
|
||||||
|
return Response.status(status).entity(errorMessage).build();
|
||||||
|
}
|
||||||
|
}
|
16
components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java → components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/JSONMessageHandler.java
16
components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java → components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/JSONMessageHandler.java
@ -1,59 +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.application.mgt.api.common;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom exception class for handling Application-Mgt API related exceptions.
|
|
||||||
*/
|
|
||||||
public class ApplicationMgtAPIException extends Exception {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 7950151650447893900L;
|
|
||||||
private String errorMessage;
|
|
||||||
|
|
||||||
public String getErrorMessage() {
|
|
||||||
return errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorMessage(String errorMessage) {
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationMgtAPIException(String msg, Exception e) {
|
|
||||||
super(msg, e);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationMgtAPIException(String msg, Throwable cause) {
|
|
||||||
super(msg, cause);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationMgtAPIException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationMgtAPIException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationMgtAPIException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +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.application.mgt.api.common;
|
|
||||||
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.ext.ExceptionMapper;
|
|
||||||
|
|
||||||
@Produces({ "application/json", "application/xml" })
|
|
||||||
public class ErrorHandler implements ExceptionMapper<ApplicationMgtAPIException> {
|
|
||||||
|
|
||||||
public Response toResponse(ApplicationMgtAPIException exception) {
|
|
||||||
ErrorMessage errorMessage = new ErrorMessage();
|
|
||||||
errorMessage.setErrorMessage(exception.getErrorMessage());
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +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.application.mgt.api.common;
|
|
||||||
|
|
||||||
|
|
||||||
public class ErrorMessage {
|
|
||||||
|
|
||||||
private String errorMessage;
|
|
||||||
private String errorCode;
|
|
||||||
|
|
||||||
public String getErrorMessage() {
|
|
||||||
return errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorMessage(String errorMessage) {
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getErrorCode() {
|
|
||||||
return errorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorCode(String errorCode) {
|
|
||||||
this.errorCode = errorCode;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2017, 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.application.mgt.api.util;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.device.application.mgt.core.services.impl.ApplicationManagementServiceFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds util methods required for Application-Mgt API component.
|
|
||||||
*/
|
|
||||||
public class ApplicationMgtAPIUtil {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(ApplicationMgtAPIUtil.class);
|
|
||||||
|
|
||||||
public static ApplicationManagementServiceFactory getApplicationManagementServiceFactory() {
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
ApplicationManagementServiceFactory applicationManagerServiceFactory =
|
|
||||||
(ApplicationManagementServiceFactory) ctx.getOSGiService(ApplicationManagementServiceFactory.class, null);
|
|
||||||
if (applicationManagerServiceFactory == null) {
|
|
||||||
String msg = "Application Management provider service has not initialized.";
|
|
||||||
log.error(msg);
|
|
||||||
throw new IllegalStateException(msg);
|
|
||||||
}
|
|
||||||
return applicationManagerServiceFactory;
|
|
||||||
}
|
|
||||||
}
|
|
9
components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationManagerException.java → components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationManagementException.java
9
components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationManagerException.java → components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationManagementException.java
Loading…
Reference in new issue