You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2014/12/17 11:49:18 UTC
stratos git commit: Fixing tenant add cli method response handling
Repository: stratos
Updated Branches:
refs/heads/4.1.0-test ef1c73970 -> bda364c13
Fixing tenant add cli method response handling
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/bda364c1
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/bda364c1
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/bda364c1
Branch: refs/heads/4.1.0-test
Commit: bda364c132f9a93ba573ea71a8e5c81677ba21dd
Parents: ef1c739
Author: Imesh Gunaratne <im...@apache.org>
Authored: Wed Dec 17 16:19:09 2014 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Wed Dec 17 16:19:09 2014 +0530
----------------------------------------------------------------------
.../stratos/cli/RestCommandLineService.java | 28 +++++++-------------
1 file changed, 10 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/bda364c1/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
index d1d4d96..517ac04 100644
--- a/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
+++ b/components/org.apache.stratos.cli/src/main/java/org/apache/stratos/cli/RestCommandLineService.java
@@ -380,23 +380,19 @@ public class RestCommandLineService {
Gson gson = gsonBuilder.create();
String jsonString = gson.toJson(tenantInfo, TenantInfoBean.class);
-
HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
+ ENDPOINT_ADD_TENANT, jsonString);
- String responseCode = "" + response.getStatusLine().getStatusCode();
-
- if (responseCode.equals(CliConstants.RESPONSE_OK)) {
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode < 200 || responseCode >= 300) {
+ CliUtils.printError(response);
+ } else {
System.out.println("Tenant added successfully");
return;
- } else {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
}
-
} catch (Exception e) {
- handleException("Exception in creating tenant", e);
+ String message = "Could not add tenant";
+ printError(message, e);
} finally {
httpClient.getConnectionManager().shutdown();
}
@@ -424,17 +420,13 @@ public class RestCommandLineService {
HttpResponse response = restClient.doPost(httpClient, restClient.getBaseURL()
+ ENDPOINT_ADD_USER, jsonString);
- String responseCode = "" + response.getStatusLine().getStatusCode();
-
- if (responseCode.equals(CliConstants.RESPONSE_CREATED)) {
+ int responseCode = response.getStatusLine().getStatusCode();
+ if (responseCode < 200 || responseCode >= 300) {
+ CliUtils.printError(response);
+ } else {
System.out.println("User added successfully");
return;
- } else {
- String resultString = CliUtils.getHttpResponseString(response);
- ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
- System.out.println(exception);
}
-
} catch (Exception e) {
String message = "Could not add user";
printError(message, e);