/** * Check if database port is valid. * Derby does not check this so need to add code to check the port number. */ private void checkIfPortIsValid(final String port) throws CommandValidationException { try { Integer.parseInt(port); } catch (NumberFormatException e) { throw new CommandValidationException( strings.get("InvalidPortNumber", port)); } }
/** * Converts the port string to port int * * @param port the port number * @return the port number as an int * @throws CommandValidationException if port string is not numeric */ private int convertPortStr(final String port) throws CommandValidationException { try { return Integer.parseInt(port); } catch (Exception e) { throw new CommandValidationException( strings.get("InvalidPortNumber", port)); } }
/** * Converts the port string to port int * * @param port the port number * @return the port number as an int * @throws CommandValidationException if port string is not numeric */ private int convertPortStr(final String port) throws CommandValidationException { try { return Integer.parseInt(port); } catch (Exception e) { throw new CommandValidationException( strings.get("InvalidPortNumber", port)); } }
void validateHostName(String hostName) throws CommandValidationException { if (! StringUtils.ok(hostName)) { throw new CommandValidationException( Strings.get("nodehost.required")); } try { // Check if hostName is valid by looking up it's address InetAddress addr = InetAddress.getByName(hostName); } catch (UnknownHostException e) { throw new CommandValidationException( Strings.get("unknown.host", hostName), e); } }
/** * Check if portbase option is specified. * Portbase is mutually exclusive to adminport and domainproperties options. * If portbase options is specfied and also adminport or domainproperties * is specified as well, then throw an exception. */ private boolean usePortBase() throws CommandValidationException { if (portBase != null) { if (adminPort != null) { throw new CommandValidationException( strings.get("MutuallyExclusiveOption", ADMIN_PORT, PORTBASE_OPTION)); } else if (instancePort != null) { throw new CommandValidationException( strings.get("MutuallyExclusiveOption", INSTANCE_PORT, PORTBASE_OPTION)); } else if (domainProperties != null) { throw new CommandValidationException( strings.get("MutuallyExclusiveOption", DOMAIN_PROPERTIES, PORTBASE_OPTION)); } else { return true; } } return false; }
private void validateNodeInstallDirLocal(String nodeInstallDir, String installDir) throws CommandValidationException { String canonicalNodeInstallDir = FileUtils.safeGetCanonicalPath(new File(nodeInstallDir)); String canonicalInstallDir = FileUtils.safeGetCanonicalPath(new File(installDir)); if (canonicalNodeInstallDir == null || canonicalInstallDir == null) { throw new CommandValidationException( Strings.get("Instance.installdir.null", node, canonicalInstallDir, canonicalNodeInstallDir)); } if ( !canonicalInstallDir.equals(canonicalNodeInstallDir) ) { throw new CommandValidationException( Strings.get("Instance.installdir.mismatch", node, canonicalInstallDir, canonicalNodeInstallDir)); } }
void validateHostName(String hostName) throws CommandValidationException { if (!StringUtils.ok(hostName)) { throw new CommandValidationException( Strings.get("nodehost.required")); } try { // Check if hostName is valid by looking up it's address InetAddress.getByName(hostName); } catch (UnknownHostException e) { throw new CommandValidationException( Strings.get("unknown.host", hostName), e); } }
private RemoteType parseType(ParameterMap map) throws CommandValidationException { try { return RemoteType.valueOf(map.getOne(PARAM_TYPE)); } catch (Exception e) { throw new CommandValidationException(e); } } }
/** * Verify that the portbase port is valid Port must be greater than 0 and * less than 65535. This method will also check if the port is in used. * * @param portNum the port number to verify * @throws CommandException if Port is not valid * @throws CommandValidationException is port number is not a numeric value. */ private void verifyPortBasePortIsValid(String portName, int portNum) throws CommandValidationException { if (portNum <= 0 || portNum > PORT_MAX_VAL) { throw new CommandValidationException( strings.get("InvalidPortBaseRange", portNum, portName)); } if (checkPorts && !NetUtils.isPortFree(portNum)) { throw new CommandValidationException( strings.get("PortBasePortInUse", portNum, portName)); } logger.log(Level.FINER, "Port ={0}", portNum); }
/** * Verify that the portbase port is valid * Port must be greater than 0 and less than 65535. * This method will also check if the port is in used. * * @param portNum the port number to verify * @throws CommandException if Port is not valid * @throws CommandValidationException is port number is not a numeric value. */ private void verifyPortBasePortIsValid(String portName, int portNum) throws CommandValidationException { if (portNum <= 0 || portNum > PORT_MAX_VAL) { throw new CommandValidationException( strings.get("InvalidPortBaseRange", portNum, portName)); } if (checkPorts && !NetUtils.isPortFree(portNum)) { throw new CommandValidationException( strings.get("PortBasePortInUse", portNum, portName)); } logger.finer("Port =" + portNum); }
private void validatePassword(String p) throws CommandValidationException { String expandedPassword = null; // Make sure if a password alias is used we can expand it if (StringUtils.ok(p)) { try { expandedPassword = RelativePathResolver.getRealPasswordFromAlias(p); } catch (IllegalArgumentException e) { throw new CommandValidationException( Strings.get("no.such.password.alias", p)); } catch (Exception e) { throw new CommandValidationException( Strings.get("no.such.password.alias", p), e); } if (expandedPassword == null) { throw new CommandValidationException( Strings.get("no.such.password.alias", p)); } } }
private void validatePassword(String p) throws CommandValidationException { String expandedPassword = null; // Make sure if a password alias is used we can expand it if (StringUtils.ok(p)) { try { expandedPassword = RelativePathResolver.getRealPasswordFromAlias(p); } catch (IllegalArgumentException e) { throw new CommandValidationException( Strings.get("no.such.password.alias", p)); } catch (Exception e) { throw new CommandValidationException( Strings.get("no.such.password.alias", p), e); } if (expandedPassword == null) { throw new CommandValidationException( Strings.get("no.such.password.alias", p)); } } }
private void validateString(String propname, String value, String configValue, boolean ignorecase) throws CommandValidationException { if (!StringUtils.ok(value) || !StringUtils.ok(configValue)) { // If no value was passed via the CLI then we don't check it since // the caller doesn't want it validated. // If no value exists in the config, then we don't check it since // we will update it. return; } boolean match = false; if (ignorecase) { match = value.equalsIgnoreCase(configValue); } else { match = value.equals(configValue); } if ( !match ) { throw new CommandValidationException( Strings.get("attribute.mismatch", name, propname, value, configValue)); } // Don't update an attribute that is considered a match excludeFromUpdate.add(propname); } }
protected void prepareRequest() throws CommandValidationException { File backupdir_f = null; if (backupdir != null) { backupdir_f = new File(backupdir); if (!backupdir_f.isAbsolute()) { throw new CommandValidationException( strings.get("InvalidBackupDirPath", backupdir)); } } boolean configonlybackup = false; if ((configonly != null) && (new Boolean(configonly))) { configonlybackup = true; } request = new BackupRequest(domainDirParam, domainName, backupdir_f, backupConfig, desc, recycleLimit,configonlybackup); request.setTerse(programOpts.isTerse()); request.setVerbose(verbose); }
private void initRequest() throws CommandValidationException { File backupdir_f = null; if (backupdir != null) { backupdir_f = new File(backupdir); if (!backupdir_f.isAbsolute()) { throw new CommandValidationException( strings.get("InvalidBackupDirPath", backupdir)); } } boolean configonlybackup = false; if ((configonly != null) && (new Boolean(configonly))) { configonlybackup = true; } request = new BackupRequest(domainDirParam, domainName, backupdir_f, backupConfig, backupFilename,configonlybackup); request.setTerse(programOpts.isTerse()); request.setVerbose(verbose); request.setForce(force); }
public void validatePassword(String password, ParamModel pwdOpt) throws CommandValidationException { // XXX - hack alert! the description is stored in the default value String description = pwdOpt.getParam().defaultValue(); if (!ok(description)) description = pwdOpt.getName(); if (password == null) throw new CommandValidationException( strings.get("PasswordMissing", description)); }
private void validateHostname(String propname, String value, String configValue) throws CommandValidationException { try { // First do a simple case insensitve string comparison. If that // matches then it's good enough for us. validateString(propname, value, configValue, true); return; } catch (CommandValidationException e) { // Strings don't match, but we could have a case of // "sidewinder" and "sidewinder.us.oracle.com". NetUtils // isEqual() handles this check. if (! NetUtils.isEqual(value, configValue)) { // If they both refer to the localhost then consider them // them same. if ( ! (NetUtils.isThisHostLocal(value) && NetUtils.isThisHostLocal(configValue)) ) { throw new CommandValidationException( Strings.get("attribute.mismatch", name, propname, value, configValue)); } } } // Don't update an attribute that is considered a match excludeFromUpdate.add(propname); }
private void validateHostname(String propname, String value, String configValue) throws CommandValidationException { try { // First do a simple case insensitve string comparison. If that // matches then it's good enough for us. validateString(propname, value, configValue, true); return; } catch (CommandValidationException e) { // Strings don't match, but we could have a case of // "sidewinder" and "sidewinder.us.oracle.com". NetUtils // isEqual() handles this check. if (! NetUtils.isEqual(value, configValue)) { // If they both refer to the localhost then consider them // them same. if ( ! (NetUtils.isThisHostLocal(value) && NetUtils.isThisHostLocal(configValue)) ) { throw new CommandValidationException( Strings.get("attribute.mismatch", name, propname, value, configValue)); } } } // Don't update an attribute that is considered a match excludeFromUpdate.add(propname); }
/** * Make sure we can make an SSH connection using an existing node. * * @param node Node to connect to * @throws CommandValidationException */ void pingRemoteConnection(Node node) throws CommandValidationException { RemoteType type = RemoteType.valueOf(node.getType()); validateHostName(node.getNodeHost()); switch (type) { case SSH: pingSSHConnection(node); break; default: throw new CommandValidationException("Internal Error: unknown type"); } }
/** * Inject this instance with the final values of all the command * parameters. * * @throws CommandException if execution of the command fails * @throws CommandValidationException if there's something wrong * with the options or arguments */ protected void inject() throws CommandException { // injector expects operands to be in the ParameterMap with the key // "DEFAULT" options.set("DEFAULT", operands); // if command has a "terse" option, set it from ProgramOptions if (commandModel.getModelFor("terse") != null) options.set("terse", Boolean.toString(programOpts.isTerse())); // initialize the injector. InjectionResolver<Param> injector = new MapInjectionResolver(commandModel, options); // inject try { injectionMgr.inject(this, injector); } catch (UnsatisfiedDependencyException e) { throw new CommandValidationException(e.getMessage(), e); } }