You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/02/14 11:22:08 UTC

[2/3] git commit: fixing https://issues.apache.org/jira/browse/STRATOS-450 - cli - and fixing issues with subscribed-cartridges-info command

fixing https://issues.apache.org/jira/browse/STRATOS-450 - cli - and fixing issues with subscribed-cartridges-info command


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

Branch: refs/heads/master
Commit: c434b0561ebf54f064b0404877f9adbbcc3c3c84
Parents: 4810131
Author: Nirmal Fernando <ni...@apache.org>
Authored: Fri Feb 14 15:51:13 2014 +0530
Committer: Nirmal Fernando <ni...@apache.org>
Committed: Fri Feb 14 15:51:13 2014 +0530

----------------------------------------------------------------------
 .../stratos/cli/RestCommandLineService.java     | 78 ++++++++++++++++++--
 1 file changed, 71 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c434b056/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 959d183..e503ffc 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
@@ -434,17 +434,19 @@ public class RestCommandLineService {
             		+alias, restClientService.getUsername(), restClientService.getPassword());
 
             String responseCode = "" + response.getStatusLine().getStatusCode();
-            if ( ! responseCode.equals(CliConstants.RESPONSE_OK)) {
-                System.out.println("Error occured while listing subscribe cartridges");
+            String resultString = getHttpResponseString(response);
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            
+            if ( !responseCode.equals(CliConstants.RESPONSE_OK)) {
+            	ExceptionMapper exception = gson.fromJson(resultString, ExceptionMapper.class);
+            	System.out.println(exception);
                 return;
             }
 
-            String resultString = getHttpResponseString(response);
+            CartridgeWrapper cartridgeWrapper = gson.fromJson(resultString, CartridgeWrapper.class);
+            Cartridge cartridge = cartridgeWrapper.getCartridge();
 
-            GsonBuilder gsonBuilder = new GsonBuilder();
-            Gson gson = gsonBuilder.create();
-            CartridgeList cartridgeList = gson.fromJson(resultString, CartridgeList.class);
-            Cartridge cartridge = cartridgeList.getCartridge().get(0);
             if (cartridge == null) {
                 System.out.println("Cartridge is null");
                 return;
@@ -1741,4 +1743,66 @@ public class RestCommandLineService {
         System.out.println(message);
         throw new CommandException(message, e);
     }
+    
+    /**
+     * To map RestApiException of back-end.
+     * @author nirmal
+     *
+     */
+    public class ExceptionMapper {
+    	@Override
+		public String toString() {
+			return Error.toString();
+		}
+
+		private ErrorWrapper Error;
+
+		public ErrorWrapper getError() {
+			return Error;
+		}
+
+		public void setError(ErrorWrapper error) {
+			Error = error;
+		}
+    	
+    }
+    
+    public class ErrorWrapper {
+    	private String errorCode;
+    	private String errorMessage;
+    	public String getErrorCode() {
+    		return errorCode;
+    	}
+    	public void setErrorCode(String errorCode) {
+    		this.errorCode = errorCode;
+    	}
+    	public String getErrorMessage() {
+    		return errorMessage;
+    	}
+    	public void setErrorMessage(String errorMessage) {
+    		this.errorMessage = errorMessage;
+    	}
+    	@Override
+    	public String toString() {
+    		return "Exception [errorCode=" + errorCode
+    				+ ", errorMessage=" + errorMessage + "]";
+    	}
+    	
+    }
+    
+	// This class is to convert JSON string to Cartridge object
+	public class CartridgeWrapper {
+		private Cartridge cartridge;
+
+		public Cartridge getCartridge() {
+			return cartridge;
+		}
+
+		public void setCartridge(Cartridge cartridge) {
+			this.cartridge = cartridge;
+		}
+
+		public CartridgeWrapper() {
+		}
+	}
 }