Class RemoteCLICommand
- java.lang.Object
-
- com.sun.enterprise.admin.cli.CLICommand
-
- com.sun.enterprise.admin.cli.remote.RemoteCLICommand
-
- All Implemented Interfaces:
org.glassfish.hk2.api.PostConstruct
public class RemoteCLICommand extends CLICommand
A remote command handled by the asadmin CLI.
-
-
Field Summary
Fields Modifier and Type Field Description protected List<String>
reExecutedOperands
protected ParameterMap
reExecutedOptions
-
Fields inherited from class com.sun.enterprise.admin.cli.CLICommand
argv, ASADMIN, commandModel, CONNECTION_ERROR, env, ERROR, INVALID_COMMAND_ERROR, lineReader, logger, metadataErrors, name, operands, options, passwords, programOpts, SUCCESS, terminal, WARNING
-
-
Constructor Summary
Constructors Constructor Description RemoteCLICommand()
Construct a new remote command object.RemoteCLICommand(String name, ProgramOptions po, Environment env)
Construct a new remote command object.RemoteCLICommand(String name, ProgramOptions po, Environment env, String responseFormatType, OutputStream userOut)
Construct a new remote command object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
execute(String... argv)
Execute this command with the given arguemnts.ActionReport
executeAndReturnActionReport(String... args)
Execute the command and return the main attributes from the manifest instead of writing out the output.String
executeAndReturnOutput(String... args)
Execute the command and return the output as a string instead of writing it out.protected int
executeCommand()
Execute the command using the options in options and the operands in operands.BufferedReader
getManPage()
Get the man page from the server.String
getUsage()
Get the usage text.protected void
inject()
Inject this instance with the final values of all the command parameters.protected void
parse()
The parse method sets the options and operands fields based on the content of the command line arguments.protected void
prepare()
The prepare method must ensure that the commandModel field is set.protected void
prevalidate()
The prevalidate method supplies missing options from the environment.void
registerListener(String regexpForName, AdminCommandEventBroker.AdminCommandListener listener)
void
setFileOutputDirectory(File dir)
Set the directory in which any returned files will be stored.void
setReadTimeout(int readTimeout)
Set read timeout for RemoteRestCommandprotected void
validate()
The validate method can be used by a subclass to validate that the type and quantity of parameters and operands matches the requirements for this command.-
Methods inherited from class com.sun.enterprise.admin.cli.CLICommand
buildLineReader, buildTerminal, checkHelp, closeTerminal, execute, expandManPage, getBooleanOption, getBriefCommandUsage, getCommand, getCommand, getCommandScope, getCommandUsage, getName, getOperandModel, getOption, getOptions, getPassword, getPassword, getProgramOptions, getSystemProperties, getSystemProperty, initializeLogger, initializePasswords, newLineReaderBuilder, ok, postConstruct, printExceptionStackTrace, processProgramOptions, quote, readPassword, setCommandScope, toString, usageOptions
-
-
-
-
Field Detail
-
reExecutedOptions
protected ParameterMap reExecutedOptions
-
-
Constructor Detail
-
RemoteCLICommand
public RemoteCLICommand() throws CommandException
Construct a new remote command object. The command and arguments are supplied later using the execute method in the superclass.- Throws:
CommandException
-
RemoteCLICommand
public RemoteCLICommand(String name, ProgramOptions po, Environment env) throws CommandException
Construct a new remote command object. The command and arguments are supplied later using the execute method in the superclass.- Parameters:
name
- The command to executepo
- Parameters passed with the command, both those part of the command itself (i.e. enabled) and those that are inherited for all commands (i.e. adminport)env
- The environment that is executing the command- Throws:
CommandException
- if the command failed for any reason
-
RemoteCLICommand
public RemoteCLICommand(String name, ProgramOptions po, Environment env, String responseFormatType, OutputStream userOut) throws CommandException
Construct a new remote command object. The command and arguments are supplied later using the execute method in the superclass. This variant is used by the RemoteDeploymentFacility class to control and capture the output.- Parameters:
name
- The command to executepo
- Parameters passed with the command, both those part of the command itself (i.e. enabled) and those that are inherited for all commands (i.e. adminport)env
- The environment that is executing the commandresponseFormatType
-userOut
- TheOutputStream
that is used to display any output to the user- Throws:
CommandException
- if the command failed for any reason
-
-
Method Detail
-
execute
public int execute(String... argv) throws CommandException
Description copied from class:CLICommand
Execute this command with the given arguemnts. The implementation in this class saves the passed arguments in the argv field and calls the initializePasswords method. Then it calls the prepare, parse, and validate methods, finally returning the result of calling the executeCommand method. Note that argv[0] is the command name.- Overrides:
execute
in classCLICommand
- Parameters:
argv
- Arguments to execute command with- Returns:
- exit code of the command
- Throws:
CommandException
- if execution of the command failsCommandValidationException
- if there's something wrong with the options or arguments
-
setFileOutputDirectory
public void setFileOutputDirectory(File dir)
Set the directory in which any returned files will be stored. The default is the user's home directory.- Parameters:
dir
-
-
prepare
protected void prepare() throws CommandException, CommandValidationException
Description copied from class:CLICommand
The prepare method must ensure that the commandModel field is set.- Overrides:
prepare
in classCLICommand
- Throws:
CommandException
CommandValidationException
-
prevalidate
protected void prevalidate() throws CommandException
Description copied from class:CLICommand
The prevalidate method supplies missing options from the environment. It also supplies passwords from the password file or prompts for them if interactive.- Overrides:
prevalidate
in classCLICommand
- Throws:
CommandException
- if execution of the command failsCommandValidationException
- if there's something wrong with the options or arguments
-
parse
protected void parse() throws CommandException
Description copied from class:CLICommand
The parse method sets the options and operands fields based on the content of the command line arguments. If the program options say this is a help request, we set options and operands as if "--help" had been specified.- Overrides:
parse
in classCLICommand
- Throws:
CommandException
- if execution of the command failsCommandValidationException
- if there's something wrong with the options or arguments
-
validate
protected void validate() throws CommandException, CommandValidationException
Description copied from class:CLICommand
The validate method can be used by a subclass to validate that the type and quantity of parameters and operands matches the requirements for this command.- Overrides:
validate
in classCLICommand
- Throws:
CommandException
- if execution of the command failsCommandValidationException
- if there's something wrong with the options or arguments
-
inject
protected void inject() throws CommandException
Description copied from class:CLICommand
Inject this instance with the final values of all the command parameters.- Overrides:
inject
in classCLICommand
- Throws:
CommandException
- if execution of the command failsCommandValidationException
- if there's something wrong with the options or arguments
-
executeCommand
protected int executeCommand() throws CommandException, CommandValidationException
Description copied from class:CLICommand
Execute the command using the options in options and the operands in operands.- Specified by:
executeCommand
in classCLICommand
- Returns:
- the exit code
- Throws:
CommandException
- if execution of the command failsCommandValidationException
- if there's something wrong with the options or arguments
-
executeAndReturnOutput
public String executeAndReturnOutput(String... args) throws CommandException, CommandValidationException
Execute the command and return the output as a string instead of writing it out.- Parameters:
args
-- Returns:
- Throws:
CommandException
CommandValidationException
-
executeAndReturnActionReport
public ActionReport executeAndReturnActionReport(String... args) throws CommandException, CommandValidationException
Execute the command and return the main attributes from the manifest instead of writing out the output.- Parameters:
args
-- Returns:
- Throws:
CommandException
CommandValidationException
-
getUsage
public String getUsage()
Get the usage text. If we got usage information from the server, use it.- Overrides:
getUsage
in classCLICommand
- Returns:
- usage text
-
getManPage
public BufferedReader getManPage()
Get the man page from the server. If the man page isn't available, e.g., because the server is down, try to find it locally by looking in the modules directory.- Overrides:
getManPage
in classCLICommand
- Returns:
-
registerListener
public void registerListener(String regexpForName, AdminCommandEventBroker.AdminCommandListener listener)
-
setReadTimeout
public void setReadTimeout(int readTimeout)
Set read timeout for RemoteRestCommand- Parameters:
readTimeout
-
-
-