From dd6e70ce86918d2eb806e4c6c6f9c28c29689494 Mon Sep 17 00:00:00 2001 From: sinthuja Date: Tue, 30 May 2017 11:44:24 +0530 Subject: [PATCH] First cut of refactoring the code. --- .../device/application/mgt/api/APIUtil.java | 68 +++++++++++++++++++ .../application/mgt/api/ApiOriginFilter.java | 3 +- ...dyHandler.java => JSONMessageHandler.java} | 16 ++--- .../mgt/api/beans/ErrorResponse.java | 62 +---------------- .../common/ApplicationMgtAPIException.java | 59 ---------------- .../mgt/api/common/ErrorHandler.java | 33 --------- .../mgt/api/common/ErrorMessage.java | 42 ------------ .../services/ApplicationManagementAPI.java | 4 +- .../impl/ApplicationManagementAPIImpl.java | 14 ++-- .../mgt/api/util/ApplicationMgtAPIUtil.java | 44 ------------ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- .../src/main/webapp/WEB-INF/web.xml | 2 +- ...va => ApplicationManagementException.java} | 9 ++- .../exception/DBConnectionException.java | 15 +--- .../IllegalTransactionStateException.java | 10 +-- .../TransactionManagementException.java | 10 +-- .../UnsupportedDatabaseEngineException.java | 10 +-- .../common/services/ApplicationManager.java | 6 +- .../ApplicationConfigurationManager.java | 8 +-- .../ApplicationManagementDAOException.java | 4 +- .../services/impl/ApplicationManagerImpl.java | 10 +-- .../core/util/ApplicationManagementUtil.java | 7 +- 22 files changed, 113 insertions(+), 325 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java rename components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/{common/GsonMessageBodyHandler.java => JSONMessageHandler.java} (86%) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ApplicationMgtAPIException.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorHandler.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorMessage.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/util/ApplicationMgtAPIUtil.java rename components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/{ApplicationManagerException.java => ApplicationManagementException.java} (78%) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java new file mode 100644 index 0000000000..754907282a --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java @@ -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(); + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/ApiOriginFilter.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/ApiOriginFilter.java index 275d9e5ec4..fc8d84d3e7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/ApiOriginFilter.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/ApiOriginFilter.java @@ -21,8 +21,9 @@ import javax.servlet.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -public class ApiOriginFilter implements Filter { +public class APIOriginFilter implements Filter { + //TODO: check no config option. public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse res = (HttpServletResponse) response; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/JSONMessageHandler.java similarity index 86% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/JSONMessageHandler.java index ddb186d833..2a1407eeae 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/JSONMessageHandler.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.application.mgt.api.common; +package org.wso2.carbon.device.application.mgt.api; import com.google.gson.Gson; @@ -40,7 +40,7 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON; @Provider @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) -public class GsonMessageBodyHandler implements MessageBodyWriter, MessageBodyReader { +public class JSONMessageHandler implements MessageBodyWriter, MessageBodyReader { private Gson gson; private static final String UTF_8 = "UTF-8"; @@ -62,13 +62,8 @@ public class GsonMessageBodyHandler implements MessageBodyWriter, Messag public Object readFrom(Class objectClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap stringStringMultivaluedMap, InputStream entityStream) throws IOException, WebApplicationException { - - InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8"); - - try { + try (InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8")) { return getGson().fromJson(reader, type); - } finally { - reader.close(); } } @@ -84,11 +79,8 @@ public class GsonMessageBodyHandler implements MessageBodyWriter, Messag MultivaluedMap stringObjectMultivaluedMap, OutputStream entityStream) throws IOException, WebApplicationException { - OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8); - try { + try (OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8)) { getGson().toJson(object, type, writer); - } finally { - writer.close(); } } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorResponse.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorResponse.java index 0b648b52c6..cfd1408c91 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorResponse.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorResponse.java @@ -28,22 +28,19 @@ import java.util.List; @ApiModel(description = "Error Response") public class ErrorResponse { - private Long code = null; + private Integer code = null; private String message = null; private String description = null; private String moreInfo = null; private List errorItems = new ArrayList<>(); - private ErrorResponse() { - } - @JsonProperty(value = "code") @ApiModelProperty(required = true, value = "") - public Long getCode() { + public Integer getCode() { return code; } - public void setCode(Long code) { + public void setCode(Integer code) { this.code = code; } @@ -94,57 +91,4 @@ public class ErrorResponse { public void setErrorItems(List error) { this.errorItems = error; } - - public static class ErrorResponseBuilder { - - private Long code = null; - private String message = null; - private String description = null; - private String moreInfo = null; - private List error; - - - public ErrorResponseBuilder() { - this.error = new ArrayList<>(); - } - - public ErrorResponseBuilder setCode(long code) { - this.code = code; - return this; - } - - public ErrorResponseBuilder setMessage(String message) { - this.message = message; - return this; - } - - public ErrorResponseBuilder setDescription(String description) { - this.description = description; - return this; - } - - public ErrorResponseBuilder setMoreInfo(String moreInfo) { - this.moreInfo = moreInfo; - return this; - } - - public ErrorResponseBuilder addErrorItem(String code, String msg) { - ErrorListItem item = new ErrorListItem(); - item.setCode(code); - item.setMessage(msg); - this.error.add(item); - return this; - } - - public ErrorResponse build() { - ErrorResponse errorResponse = new ErrorResponse(); - errorResponse.setCode(code); - errorResponse.setMessage(message); - errorResponse.setErrorItems(error); - errorResponse.setDescription(description); - errorResponse.setMoreInfo(moreInfo); - return errorResponse; - } - } - } \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ApplicationMgtAPIException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ApplicationMgtAPIException.java deleted file mode 100644 index d072229517..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ApplicationMgtAPIException.java +++ /dev/null @@ -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); - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorHandler.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorHandler.java deleted file mode 100644 index d44ab48b9e..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorHandler.java +++ /dev/null @@ -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 { - - public Response toResponse(ApplicationMgtAPIException exception) { - ErrorMessage errorMessage = new ErrorMessage(); - errorMessage.setErrorMessage(exception.getErrorMessage()); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorMessage.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorMessage.java deleted file mode 100644 index 1856305ab6..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorMessage.java +++ /dev/null @@ -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; - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java index 55ccd12913..5ac7909929 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementAPI.java @@ -76,14 +76,14 @@ public interface ApplicationManagementAPI { @ApiParam( name = "offset", - value = "Provide how many apps it should return", + value = "Provide from which position apps should return", required = false, defaultValue = "20") @QueryParam("offset") int offset, @ApiParam( name = "limit", - value = "Provide from which position apps should return", + value = "Provide how many apps it should return", required = false, defaultValue = "0") @QueryParam("limit") int limit diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java index 777820efa7..a02469577f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementAPIImpl.java @@ -20,11 +20,11 @@ package org.wso2.carbon.device.application.mgt.api.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.ApplicationList; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; -import org.wso2.carbon.device.application.mgt.api.util.ApplicationMgtAPIUtil; +import org.wso2.carbon.device.application.mgt.api.APIUtil; import org.wso2.carbon.device.application.mgt.core.services.impl.ApplicationManagementServiceFactory; import org.wso2.carbon.device.application.mgt.extensions.appupload.AppUploadManager; @@ -50,19 +50,13 @@ public class ApplicationManagementAPIImpl { @Path("applications") public Response getApplications(@QueryParam("offset") int offset, @QueryParam("limit") int limit, @QueryParam("q") String searchQuery) { - ApplicationManagementServiceFactory serviceFactory = ApplicationMgtAPIUtil.getApplicationManagementServiceFactory(); + ApplicationManagementServiceFactory serviceFactory = APIUtil.getApplicationManagementServiceFactory(); ApplicationManager applicationManager = (ApplicationManager) serviceFactory .getApplicationManagementService(APPLICATION_MANAGER); - - AppUploadManager appUploadManager = (AppUploadManager) serviceFactory - .applicationManagementExtensionsService(APPLICATION_UPLOAD_EXTENSION); - try { - if (limit == 0) { limit = DEFAULT_LIMIT; } - Filter filter = new Filter(); filter.setOffset(offset); filter.setLimit(limit); @@ -70,7 +64,7 @@ public class ApplicationManagementAPIImpl { ApplicationList applications = applicationManager.getApplications(filter); return Response.status(Response.Status.OK).entity(applications).build(); - } catch (Exception e) { + } catch (ApplicationManagementException e) { String msg = "Error occurred while getting the application list"; log.error(msg, e); return Response.status(Response.Status.NOT_FOUND).build(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/util/ApplicationMgtAPIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/util/ApplicationMgtAPIUtil.java deleted file mode 100644 index 84cb905996..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/util/ApplicationMgtAPIUtil.java +++ /dev/null @@ -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; - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 897692df30..57b99b8586 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -33,6 +33,6 @@ http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml index ef52110172..abcd6b3d1c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml @@ -54,7 +54,7 @@ ApiOriginFilter - org.wso2.carbon.device.application.mgt.api.ApiOriginFilter + org.wso2.carbon.device.application.mgt.api.APIOriginFilter diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationManagerException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationManagementException.java similarity index 78% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationManagerException.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationManagementException.java index 884193878c..adde1770e0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationManagerException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/ApplicationManagementException.java @@ -18,15 +18,20 @@ */ package org.wso2.carbon.device.application.mgt.common.exception; -public class ApplicationManagerException extends Exception { +public abstract class ApplicationManagementException extends Exception { String message; - public ApplicationManagerException(String message, Throwable throwable){ + public ApplicationManagementException(String message, Throwable throwable){ super(message, throwable); setMessage(message); } + public ApplicationManagementException(String message){ + super(message); + setMessage(message); + } + @Override public String getMessage() { return message; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/DBConnectionException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/DBConnectionException.java index d2a0f229b4..da22385c94 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/DBConnectionException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/DBConnectionException.java @@ -17,14 +17,10 @@ */ package org.wso2.carbon.device.application.mgt.common.exception; -public class DBConnectionException extends Exception { +public class DBConnectionException extends ApplicationManagementException { private static final long serialVersionUID = -3151279331929070297L; - public DBConnectionException(String msg, Exception nestedEx) { - super(msg, nestedEx); - } - public DBConnectionException(String message, Throwable cause) { super(message, cause); } @@ -32,13 +28,4 @@ public class DBConnectionException extends Exception { public DBConnectionException(String msg) { super(msg); } - - public DBConnectionException() { - super(); - } - - public DBConnectionException(Throwable cause) { - super(cause); - } - } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/IllegalTransactionStateException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/IllegalTransactionStateException.java index e7a1d05c8d..bbbe7c9c6f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/IllegalTransactionStateException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/IllegalTransactionStateException.java @@ -17,7 +17,7 @@ */ package org.wso2.carbon.device.application.mgt.common.exception; -public class IllegalTransactionStateException extends RuntimeException { +public class IllegalTransactionStateException extends ApplicationManagementException { private static final long serialVersionUID = -3151279331929070297L; @@ -33,12 +33,4 @@ public class IllegalTransactionStateException extends RuntimeException { super(msg); } - public IllegalTransactionStateException() { - super(); - } - - public IllegalTransactionStateException(Throwable cause) { - super(cause); - } - } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/TransactionManagementException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/TransactionManagementException.java index 44b28f6367..584f6fa045 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/TransactionManagementException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/TransactionManagementException.java @@ -17,7 +17,7 @@ */ package org.wso2.carbon.device.application.mgt.common.exception; -public class TransactionManagementException extends Exception { +public class TransactionManagementException extends ApplicationManagementException { private static final long serialVersionUID = -3151279321929070297L; @@ -33,12 +33,4 @@ public class TransactionManagementException extends Exception { super(msg); } - public TransactionManagementException() { - super(); - } - - public TransactionManagementException(Throwable cause) { - super(cause); - } - } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/UnsupportedDatabaseEngineException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/UnsupportedDatabaseEngineException.java index 22c23b0d10..6a9c632bda 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/UnsupportedDatabaseEngineException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/UnsupportedDatabaseEngineException.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.application.mgt.common.exception; /** * This runtime exception will be thrown if the server has configured with unsupported DB engine. */ -public class UnsupportedDatabaseEngineException extends RuntimeException { +public class UnsupportedDatabaseEngineException extends ApplicationManagementException { private static final long serialVersionUID = -3151279311929070297L; @@ -37,12 +37,4 @@ public class UnsupportedDatabaseEngineException extends RuntimeException { super(msg); } - public UnsupportedDatabaseEngineException() { - super(); - } - - public UnsupportedDatabaseEngineException(Throwable cause) { - super(cause); - } - } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 759d085836..098b3cbe3b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -21,11 +21,11 @@ package org.wso2.carbon.device.application.mgt.common.services; import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.ApplicationList; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagerException; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; public interface ApplicationManager extends ApplicationManagementService { - void createApplication(Application application) throws ApplicationManagerException; + void createApplication(Application application) throws ApplicationManagementException; - ApplicationList getApplications(Filter filter) throws ApplicationManagerException; + ApplicationList getApplications(Filter filter) throws ApplicationManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationConfigurationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationConfigurationManager.java index 4485b8470d..b787e138b4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationConfigurationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationConfigurationManager.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.application.mgt.core.config; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagerException; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil; import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagerConstants; import org.wso2.carbon.utils.CarbonUtils; @@ -51,7 +51,7 @@ public class ApplicationConfigurationManager { applicationConfigurationManager = new ApplicationConfigurationManager(); try { applicationConfigurationManager.initConfig(); - } catch (ApplicationManagerException e) { + } catch (ApplicationManagementException e) { log.error(e); } } @@ -60,7 +60,7 @@ public class ApplicationConfigurationManager { } - public synchronized void initConfig() throws ApplicationManagerException { + public synchronized void initConfig() throws ApplicationManagementException { try { File appMgtConfig = new File(applicationMgtConfigXMLPath); Document doc = ApplicationManagementUtil.convertToDocument(appMgtConfig); @@ -71,7 +71,7 @@ public class ApplicationConfigurationManager { this.applicationManagerConfiguration = (ApplicationManagementConfigurations) unmarshaller.unmarshal(doc); } catch (Exception e) { log.error(e); - throw new ApplicationManagerException("Error occurred while initializing application config", e); + throw new ApplicationManagementException("Error occurred while initializing application config", e); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOException.java index 543f82a860..fa9808c1a3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOException.java @@ -18,9 +18,9 @@ */ package org.wso2.carbon.device.application.mgt.core.dao.common; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagerException; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; -public class ApplicationManagementDAOException extends ApplicationManagerException { +public class ApplicationManagementDAOException extends ApplicationManagementException { public ApplicationManagementDAOException(String message, Throwable throwable) { super(message, throwable); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/services/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/services/impl/ApplicationManagerImpl.java index 720e75fff3..7ebe51c65c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/services/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/services/impl/ApplicationManagerImpl.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.application.mgt.core.services.impl; import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.Filter; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagerException; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; @@ -31,21 +31,21 @@ import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; public class ApplicationManagerImpl implements ApplicationManager { @Override - public void createApplication(Application application) throws ApplicationManagerException { + public void createApplication(Application application) throws ApplicationManagementException { } @Override - public ApplicationList getApplications(Filter filter) throws ApplicationManagerException { + public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { try { ConnectionManagerUtil.openConnection(); ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); return applicationDAO.getApplications(filter); } catch (ApplicationManagementDAOException e) { - throw new ApplicationManagerException("Error occurred while obtaining the applications for " + + throw new ApplicationManagementException("Error occurred while obtaining the applications for " + "the given filter.", e); } catch (DBConnectionException e) { - throw new ApplicationManagerException("Error occurred while opening a connection to the APPM data source", e); + throw new ApplicationManagementException("Error occurred while opening a connection to the APPM data source", e); } finally { ConnectionManagerUtil.closeConnection(); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java index 7a1df76036..dddc85ccf6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java @@ -21,9 +21,8 @@ package org.wso2.carbon.device.application.mgt.core.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; -import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagerException; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.core.services.impl.ApplicationManagementServiceFactory; import javax.xml.XMLConstants; @@ -47,7 +46,7 @@ public class ApplicationManagementUtil { return applicationManagerServiceFactory; } - public static Document convertToDocument(File file) throws ApplicationManagerException { + public static Document convertToDocument(File file) throws ApplicationManagementException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { @@ -55,7 +54,7 @@ public class ApplicationManagementUtil { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); return docBuilder.parse(file); } catch (Exception e) { - throw new ApplicationManagerException("Error occurred while parsing file, while converting " + + throw new ApplicationManagementException("Error occurred while parsing file, while converting " + "to a org.w3c.dom.Document : ", e); } }