1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 28 import javax.management.ObjectName ; 29 import javax.management.MBeanServerConnection ; 30 import com.sun.enterprise.deployment.util.DeploymentProperties; 31 import com.sun.enterprise.server.Constants; 32 import com.sun.enterprise.admin.common.JMXFileTransfer; 33 import com.sun.enterprise.util.FileUtil; 34 import com.sun.enterprise.util.io.FileUtils; 35 import com.sun.enterprise.admin.common.constant.DeploymentConstants; 36 37 38 import java.io.File ; 40 import java.util.Iterator ; 41 import java.util.Properties ; 42 43 44 47 public class GetClientStubsCommand extends S1ASCommand 48 { 49 private String downloadDir; 50 private String appName; 51 public static final String APP_NAME = "appname"; 52 53 57 public void runCommand() 58 throws CommandException, CommandValidationException 59 { 60 validateOptions(); 61 62 final MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), 64 getPort(), 65 getUser(), 66 getPassword()); 67 68 String path = getClientStub(mbsc); 69 70 72 CLILogger.getInstance().printDetailMessage(getLocalizedString( 73 "CommandSuccessful", 74 new Object [] {name} ) ); 75 } 76 77 78 85 public boolean validateOptions() throws CommandValidationException 86 { 87 super.validateOptions(); 88 downloadDir = (String ) getOperands().get(0); 89 validateDirectory(); 90 appName = getAppName(); 91 return true; 92 } 93 94 95 99 private void validateDirectory() throws CommandValidationException 100 { 101 File dlDir = new File (downloadDir); 102 if (!dlDir.exists() ) 103 { 104 dlDir.mkdirs(); 105 } 106 if(!dlDir.exists() || !dlDir.canWrite() || !dlDir.isDirectory() ) { 107 throw new CommandValidationException(getLocalizedString( 108 "InvalidDirectory",new Object [] {downloadDir})); 109 } 110 } 111 112 private String getAppName() throws CommandValidationException 113 { 114 String name = getOption(APP_NAME); 115 return name; 116 } 117 118 119 120 121 124 private String getClientStub(MBeanServerConnection mbsc) 125 throws CommandException 126 { 127 try 128 { 129 130 final String fileName = new JMXFileTransfer(mbsc).downloadClientStubs( 131 appName, 132 downloadDir); 133 CLILogger.getInstance().printDebugMessage("Downloaded client stubs to: " + fileName); 134 return fileName; 135 } 136 catch (Exception e) 137 { 138 Throwable t = e.getCause(); 139 while(t!=null && t.getCause()!=null) 140 t=t.getCause(); 141 if(t==null) 142 t=e; 143 throw new CommandException(t.getLocalizedMessage(),t); 144 } 145 } 146 147 148 } 149 | Popular Tags |