Repository: stratos
Updated Branches:
  refs/heads/master 4650bed69 -> a39e8e0a6


Handle Application existance with a new exception


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/4328f70b
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/4328f70b
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/4328f70b

Branch: refs/heads/master
Commit: 4328f70b3f72dc12cbcaa3d06b8c2e567c4cafed
Parents: 4650bed
Author: Lahiru Sandaruwan <[email protected]>
Authored: Tue Apr 28 11:28:43 2015 +0530
Committer: Lahiru Sandaruwan <[email protected]>
Committed: Tue Apr 28 11:28:43 2015 +0530

----------------------------------------------------------------------
 .../rest/endpoint/api/StratosApiV41.java        | 11 +--
 .../rest/endpoint/api/StratosApiV41Utils.java   |  5 +-
 .../ApplicationAlreadyExistException.java       | 70 ++++++++++++++++++++
 3 files changed, 79 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/4328f70b/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 9cd2688..5ebf027 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.ApplicationAlreadyExistException;
 import org.apache.stratos.rest.endpoint.exception.RestAPIException;
 import org.apache.stratos.rest.endpoint.exception.TenantNotFoundException;
 import org.wso2.carbon.context.PrivilegedCarbonContext;
@@ -616,12 +617,12 @@ public class StratosApiV41 extends AbstractApi {
             return Response.created(url).entity(new 
SuccessResponseBean(Response.Status.CREATED.getStatusCode(),
                     String.format("Application added successfully: 
[application] %s",
                             
applicationDefinition.getApplicationId()))).build();
+        } catch (ApplicationAlreadyExistException e) {
+
+            return Response.status(Response.Status.CONFLICT).build();
         } catch (RestAPIException e) {
-            if (e.getMessage().contains("already exists")) {
-                return Response.status(Response.Status.CONFLICT).build();
-            } else {
-                throw e;
-            }
+
+            throw e;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/4328f70b/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 0279759..ef6aa11 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.ApplicationAlreadyExistException;
 import org.apache.stratos.rest.endpoint.exception.RestAPIException;
 import org.apache.stratos.rest.endpoint.exception.TenantNotFoundException;
 import org.apache.stratos.rest.endpoint.util.converter.ObjectConverter;
@@ -1072,12 +1073,12 @@ public class StratosApiV41Utils {
      */
     public static void addApplication(ApplicationBean appDefinition, 
ConfigurationContext ctxt,
                                       String userName, String tenantDomain)
-            throws RestAPIException {
+            throws RestAPIException, ApplicationAlreadyExistException {
 
         if (StringUtils.isBlank(appDefinition.getApplicationId())) {
             String message = "Please specify the application name";
             log.error(message);
-            throw new RestAPIException(message);
+            throw new ApplicationAlreadyExistException(message);
         }
         // check if an application with same id already exists
         try {

http://git-wip-us.apache.org/repos/asf/stratos/blob/4328f70b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/ApplicationAlreadyExistException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/ApplicationAlreadyExistException.java
 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/ApplicationAlreadyExistException.java
new file mode 100644
index 0000000..1cba4b9
--- /dev/null
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/exception/ApplicationAlreadyExistException.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 ApplicationAlreadyExistException extends RestAPIException {
+
+    private static final long serialVersionUID = 1L;
+
+    private String message;
+    private Response.Status httpStatusCode;
+
+    public ApplicationAlreadyExistException() {
+        super();
+    }
+
+    public ApplicationAlreadyExistException(String message, Throwable cause) {
+        super(message, cause);
+        this.message = message;
+    }
+
+    public ApplicationAlreadyExistException(Response.Status httpStatusCode, 
String message, Throwable cause) {
+        super(message, cause);
+        this.message = message;
+        this.httpStatusCode = httpStatusCode;
+    }
+
+    public ApplicationAlreadyExistException(String message) {
+        super(message);
+        this.message = message;
+    }
+
+    public ApplicationAlreadyExistException(Response.Status httpStatusCode, 
String message) {
+        super(message);
+        this.message = message;
+        this.httpStatusCode = httpStatusCode;
+    }
+
+    public ApplicationAlreadyExistException(Throwable cause) {
+        super(cause);
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public Response.Status getHTTPStatusCode() {
+        return httpStatusCode;
+    }
+
+
+}

Reply via email to