Use new exception, ApplicationAlreadyDeployedException to catch already deployed case
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/a9d8188b Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/a9d8188b Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/a9d8188b Branch: refs/heads/master Commit: a9d8188b945456930ac8ea38f7ef8c43063879a0 Parents: a2e1aa3 Author: Lahiru Sandaruwan <[email protected]> Authored: Tue Apr 28 14:06:41 2015 +0530 Committer: Lahiru Sandaruwan <[email protected]> Committed: Wed Apr 29 15:38:08 2015 +0530 ---------------------------------------------------------------------- .../rest/endpoint/api/StratosApiV41.java | 18 +++-- .../rest/endpoint/api/StratosApiV41Utils.java | 5 +- .../ApplicationAlreadyDeployedException.java | 70 ++++++++++++++++++++ 3 files changed, 81 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/a9d8188b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java index 5ebf027..c176b9f 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41.java @@ -41,6 +41,7 @@ import org.apache.stratos.common.beans.topology.ClusterBean; import org.apache.stratos.rest.endpoint.Utils; import org.apache.stratos.rest.endpoint.annotation.AuthorizationAction; import org.apache.stratos.rest.endpoint.annotation.SuperTenantService; +import org.apache.stratos.rest.endpoint.exception.ApplicationAlreadyDeployedException; import org.apache.stratos.rest.endpoint.exception.ApplicationAlreadyExistException; import org.apache.stratos.rest.endpoint.exception.RestAPIException; import org.apache.stratos.rest.endpoint.exception.TenantNotFoundException; @@ -647,11 +648,8 @@ public class StratosApiV41 extends AbstractApi { String.format("Application added successfully: [application] %s", applicationDefinition.getApplicationId()))).build(); } catch (RestAPIException e) { - if (e.getMessage().contains("already exists")) { - return Response.status(Response.Status.CONFLICT).build(); - } else { - throw e; - } + + throw e; } } @@ -718,12 +716,12 @@ public class StratosApiV41 extends AbstractApi { StratosApiV41Utils.deployApplication(applicationId, applicationPolicyId); return Response.accepted().entity(new SuccessResponseBean(Response.Status.ACCEPTED.getStatusCode(), String.format("Application deployed successfully: [application] %s", applicationId))).build(); + } catch (ApplicationAlreadyDeployedException e) { + + return Response.status(Response.Status.CONFLICT).build(); } catch (RestAPIException e) { - if (e.getMessage().contains("already in DEPLOYED")) { - return Response.status(Response.Status.CONFLICT).build(); - } else { - throw e; - } + + throw e; } } http://git-wip-us.apache.org/repos/asf/stratos/blob/a9d8188b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java index 35f5f87..87b628f 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java @@ -73,6 +73,7 @@ import org.apache.stratos.messaging.domain.topology.Cluster; import org.apache.stratos.messaging.message.receiver.application.ApplicationManager; import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; import org.apache.stratos.rest.endpoint.ServiceHolder; +import org.apache.stratos.rest.endpoint.exception.ApplicationAlreadyDeployedException; import org.apache.stratos.rest.endpoint.exception.ApplicationAlreadyExistException; import org.apache.stratos.rest.endpoint.exception.RestAPIException; import org.apache.stratos.rest.endpoint.exception.TenantNotFoundException; @@ -1073,7 +1074,7 @@ public class StratosApiV41Utils { */ public static void addApplication(ApplicationBean appDefinition, ConfigurationContext ctxt, String userName, String tenantDomain) - throws RestAPIException, ApplicationAlreadyExistException { + throws RestAPIException { if (StringUtils.isBlank(appDefinition.getApplicationId())) { String message = "Please specify the application name"; @@ -1291,7 +1292,7 @@ public class StratosApiV41Utils { applicationId, application.getStatus()); log.error(message); - throw new RestAPIException(message); + throw new ApplicationAlreadyDeployedException(message); } // This is a redundant state since there is only CREATED,DEPLOYED state. http://git-wip-us.apache.org/repos/asf/stratos/blob/a9d8188b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/ApplicationAlreadyDeployedException.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/ApplicationAlreadyDeployedException.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/ApplicationAlreadyDeployedException.java new file mode 100644 index 0000000..22132c4 --- /dev/null +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/ApplicationAlreadyDeployedException.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.stratos.rest.endpoint.exception; + +import javax.ws.rs.core.Response; + +public class ApplicationAlreadyDeployedException extends RestAPIException { + + private static final long serialVersionUID = 1L; + + private String message; + private Response.Status httpStatusCode; + + public ApplicationAlreadyDeployedException() { + super(); + } + + public ApplicationAlreadyDeployedException(String message, Throwable cause) { + super(message, cause); + this.message = message; + } + + public ApplicationAlreadyDeployedException(Response.Status httpStatusCode, String message, Throwable cause) { + super(message, cause); + this.message = message; + this.httpStatusCode = httpStatusCode; + } + + public ApplicationAlreadyDeployedException(String message) { + super(message); + this.message = message; + } + + public ApplicationAlreadyDeployedException(Response.Status httpStatusCode, String message) { + super(message); + this.message = message; + this.httpStatusCode = httpStatusCode; + } + + public ApplicationAlreadyDeployedException(Throwable cause) { + super(cause); + } + + public String getMessage() { + return message; + } + + public Response.Status getHTTPStatusCode() { + return httpStatusCode; + } + + +}
