1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 import com.sun.enterprise.admin.common.JMXFileTransfer; 28 import javax.management.MBeanServerConnection ; 29 import com.sun.appserv.management.client.ProxyFactory; 30 import com.sun.appserv.management.DomainRoot; 31 import com.sun.appserv.management.config.WebServiceEndpointConfig; 32 import com.sun.appserv.management.base.UploadDownloadMgr; 33 import java.util.Iterator ; 34 import java.io.File ; 35 import java.io.FileInputStream ; 36 import java.io.IOException ; 37 import java.io.FileNotFoundException ; 38 39 public class CreateTransformationRuleCommand extends BaseTransformationRuleCommand 40 { 41 private static final String RULE_LOCATION_OPTION = "rulefilelocation"; 42 private static final String APPLY_TO_OPTION = "applyto"; 43 private static final String ENABLED_OPTION = "enabled"; 44 private static final String WEB_SERVICE_OPTION = "webservicename"; 45 46 50 public void runCommand() throws CommandException, CommandValidationException 51 { 52 validateOptions(); 53 try 54 { 55 MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 56 getUser(), getPassword()); 57 DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot(); 58 String webServiceName = getOption(WEB_SERVICE_OPTION); 60 validateWebServiceName(webServiceName, true); 61 WebServiceEndpointConfig wsc = 62 getWebServiceEndpointConfig(mbsc, webServiceName, true); 63 if (wsc == null) 64 throw new CommandException(getLocalizedString("CannotFindWebservice")); 65 String ruleName = (String ) getOperands().get(0); 66 String ruleLocation = getOption(RULE_LOCATION_OPTION); 67 boolean enabled = getBooleanOption(ENABLED_OPTION); 68 String applyTo = getOption(APPLY_TO_OPTION); 69 File ruleFile = new File (ruleLocation); 72 String msg = null; 73 74 if (! ruleFile.exists()) 75 msg = getLocalizedString("FileDoesNotExist", new Object [] {ruleLocation}); 76 else if(ruleFile.length() <= 0) 77 msg = getLocalizedString("FileIsEmpty", new Object [] {ruleLocation}); 78 else if(! ruleFile.canRead()) 79 msg = getLocalizedString("FileNotReadable", new Object [] {ruleLocation}); 80 81 if(msg != null) 82 throw new CommandValidationException(msg); 83 84 String remoteLocation = uploadFileToServer(mbsc); 85 87 CLILogger.getInstance().printDebugMessage("uploadedFile = " + 88 remoteLocation); 89 wsc.createTransformationRuleConfig(ruleName, 90 remoteLocation, enabled, applyTo, null); 91 92 CLILogger.getInstance().printDetailMessage(getLocalizedString( 93 "CommandSuccessful", 94 new Object [] {name})); 95 } 96 catch(Exception e) 97 { 98 displayExceptionMessage(e); 99 } 100 101 } 102 103 107 private String uploadFileToServer(MBeanServerConnection mbsc) 108 throws CommandException, IOException 109 { 110 String ruleLocation = getOption(RULE_LOCATION_OPTION); 111 return new JMXFileTransfer(mbsc).uploadFile(ruleLocation); 112 } 113 } 114 | Popular Tags |