@Test(expected = IllegalArgumentException.class) public void extract_invalid_port() throws Exception { Map<String, String> config = new HashMap<>(); config.put(JschProcessExecutor.KEY_USER, "tester"); config.put(JschProcessExecutor.KEY_HOST, "example.com"); config.put(JschProcessExecutor.KEY_PORT, "__INVALID__"); config.put(JschProcessExecutor.KEY_PRIVATE_KEY, privateKey.getAbsolutePath()); Map<String, String> variables = new HashMap<>(); VariableResolver resolver = new VariableResolver(variables); JschProcessExecutor.extract("testing", config, resolver); }
public static JschProcessExecutor extract( String servicePrefix, Map<String, String> configuration, VariableResolver variables) throws JSchException { if (servicePrefix == null) { throw new IllegalArgumentException("servicePrefix must not be null"); } if (configuration == null) { throw new IllegalArgumentException("configuration must not be null"); } if (variables == null) { throw new IllegalArgumentException("variables must not be null"); } String user = extract(KEY_USER, servicePrefix, configuration, variables, true); String host = extract(KEY_HOST, servicePrefix, configuration, variables, true); String portString = extract(KEY_PORT, servicePrefix, configuration, variables, false); String privateKey = extract(KEY_PRIVATE_KEY, servicePrefix, configuration, variables, false); String passPhrase = extract(KEY_PASS_PHRASE, servicePrefix, configuration, variables, false); String tempBlob = extract(KEY_TEMPORARY_BLOB_PREFIX, servicePrefix, configuration, variables, false); tempBlob = tempBlob == null ? DEFAULT_TEMPORARY_BLOB_PREFIX : tempBlob; Integer port = null; if (portString != null) { try { port = Integer.valueOf(portString); } catch (NumberFormatException e) { throw new IllegalArgumentException(MessageFormat.format( "Invalid port number in \"{0}\": {1}", servicePrefix + '.' + KEY_PORT, portString)); } } return new JschProcessExecutor(user, host, port, privateKey, passPhrase, tempBlob); }
JschProcessExecutor implements ProcessExecutor { public static JschProcessExecutor extract( String servicePrefix, Map<String, String> configuration, VariableResolver variables) throws JSchException { if (servicePrefix == null) { throw new IllegalArgumentException("servicePrefix must not be null"); } if (configuration == null) { throw new IllegalArgumentException("configuration must not be null"); } if (variables == null) { throw new IllegalArgumentException("variables must not be null"); } String user = extract(KEY_USER, servicePrefix, configuration, variables, true); String host = extract(KEY_HOST, servicePrefix, configuration, variables, true); String portString = extract(KEY_PORT, servicePrefix, configuration, variables, false); String privateKey = extract(KEY_PRIVATE_KEY, servicePrefix, configuration, variables, false); String passPhrase = extract(KEY_PASS_PHRASE, servicePrefix, configuration, variables, false); String tempBlob = extract(KEY_TEMPORARY_BLOB_PREFIX, servicePrefix, configuration, variables, false); tempBlob = tempBlob == null ? DEFAULT_TEMPORARY_BLOB_PREFIX : tempBlob; Integer port = null; if (portString != null) { try { port = Integer.valueOf(portString); } catch (NumberFormatException e) { throw new IllegalArgumentException(MessageFormat.format( "Invalid port number in \"{0}\": {1}", servicePrefix + '.' + KEY_PORT, portString)); } } return new JschProcessExecutor(user, host, port, privateKey, passPhrase, tempBlob); } }
JschProcessExecutor implements ProcessExecutor { public static JschProcessExecutor extract( String servicePrefix, Map<String, String> configuration, VariableResolver variables) throws JSchException { if (servicePrefix == null) { throw new IllegalArgumentException("servicePrefix must not be null"); } if (configuration == null) { throw new IllegalArgumentException("configuration must not be null"); } if (variables == null) { throw new IllegalArgumentException("variables must not be null"); } String user = extract(KEY_USER, servicePrefix, configuration, variables, true); String host = extract(KEY_HOST, servicePrefix, configuration, variables, true); String portString = extract(KEY_PORT, servicePrefix, configuration, variables, false); String privateKey = extract(KEY_PRIVATE_KEY, servicePrefix, configuration, variables, false); String passPhrase = extract(KEY_PASS_PHRASE, servicePrefix, configuration, variables, false); String tempBlob = extract(KEY_TEMPORARY_BLOB_PREFIX, servicePrefix, configuration, variables, false); tempBlob = tempBlob == null ? DEFAULT_TEMPORARY_BLOB_PREFIX : tempBlob; Integer port = null; if (portString != null) { try { port = Integer.valueOf(portString); } catch (NumberFormatException e) { throw new IllegalArgumentException(MessageFormat.format( "Invalid port number in \"{0}\": {1}", servicePrefix + '.' + KEY_PORT, portString)); } } return new JschProcessExecutor(user, host, port, privateKey, passPhrase, tempBlob); } JschProcessExecutor(
            String user,
            String host,
            Integer portOrNull,
            String privateKeyPath,
            String passPhraseOrNull);  JschProcessExecutor(
            String user,
            String host,
            Integer portOrNull,
            String privateKeyPath,
            String passPhraseOrNull,
            String temporaryBlobPrefix); }
JschProcessExecutor implements ProcessExecutor { public static JschProcessExecutor extract( String servicePrefix, Map<String, String> configuration, VariableResolver variables) throws JSchException { if (servicePrefix == null) { throw new IllegalArgumentException("servicePrefix must not be null"); } if (configuration == null) { throw new IllegalArgumentException("configuration must not be null"); } if (variables == null) { throw new IllegalArgumentException("variables must not be null"); } String user = extract(KEY_USER, servicePrefix, configuration, variables, true); String host = extract(KEY_HOST, servicePrefix, configuration, variables, true); String portString = extract(KEY_PORT, servicePrefix, configuration, variables, false); String privateKey = extract(KEY_PRIVATE_KEY, servicePrefix, configuration, variables, false); String passPhrase = extract(KEY_PASS_PHRASE, servicePrefix, configuration, variables, false); String tempBlob = extract(KEY_TEMPORARY_BLOB_PREFIX, servicePrefix, configuration, variables, false); tempBlob = tempBlob == null ? DEFAULT_TEMPORARY_BLOB_PREFIX : tempBlob; Integer port = null; if (portString != null) { try { port = Integer.valueOf(portString); } catch (NumberFormatException e) { throw new IllegalArgumentException(MessageFormat.format( "Invalid port number in \"{0}\": {1}", servicePrefix + '.' + KEY_PORT, portString)); } } return new JschProcessExecutor(user, host, port, privateKey, passPhrase, tempBlob); } JschProcessExecutor(
            String user,
            String host,
            Integer portOrNull,
            String privateKeyPath,
            String passPhraseOrNull);  JschProcessExecutor(
            String user,
            String host,
            Integer portOrNull,
            String privateKeyPath,
            String passPhraseOrNull,
            String temporaryBlobPrefix); String getUser(); String getHost(); Integer getPort(); String getPrivateKey(); String getPassPhrase(); String getTemporaryBlobPrefix(); static JschProcessExecutor extract(
            String servicePrefix,
            Map<String, String> configuration,
            VariableResolver variables); @Override int execute(
            ExecutionContext context,
            List<String> commandLineTokens,
            Map<String, String> environmentVariables,
            Map<String, Blob> extensions,
            OutputStream output); }
JschProcessExecutor implements ProcessExecutor { public static JschProcessExecutor extract( String servicePrefix, Map<String, String> configuration, VariableResolver variables) throws JSchException { if (servicePrefix == null) { throw new IllegalArgumentException("servicePrefix must not be null"); } if (configuration == null) { throw new IllegalArgumentException("configuration must not be null"); } if (variables == null) { throw new IllegalArgumentException("variables must not be null"); } String user = extract(KEY_USER, servicePrefix, configuration, variables, true); String host = extract(KEY_HOST, servicePrefix, configuration, variables, true); String portString = extract(KEY_PORT, servicePrefix, configuration, variables, false); String privateKey = extract(KEY_PRIVATE_KEY, servicePrefix, configuration, variables, false); String passPhrase = extract(KEY_PASS_PHRASE, servicePrefix, configuration, variables, false); String tempBlob = extract(KEY_TEMPORARY_BLOB_PREFIX, servicePrefix, configuration, variables, false); tempBlob = tempBlob == null ? DEFAULT_TEMPORARY_BLOB_PREFIX : tempBlob; Integer port = null; if (portString != null) { try { port = Integer.valueOf(portString); } catch (NumberFormatException e) { throw new IllegalArgumentException(MessageFormat.format( "Invalid port number in \"{0}\": {1}", servicePrefix + '.' + KEY_PORT, portString)); } } return new JschProcessExecutor(user, host, port, privateKey, passPhrase, tempBlob); } JschProcessExecutor(
            String user,
            String host,
            Integer portOrNull,
            String privateKeyPath,
            String passPhraseOrNull);  JschProcessExecutor(
            String user,
            String host,
            Integer portOrNull,
            String privateKeyPath,
            String passPhraseOrNull,
            String temporaryBlobPrefix); String getUser(); String getHost(); Integer getPort(); String getPrivateKey(); String getPassPhrase(); String getTemporaryBlobPrefix(); static JschProcessExecutor extract(
            String servicePrefix,
            Map<String, String> configuration,
            VariableResolver variables); @Override int execute(
            ExecutionContext context,
            List<String> commandLineTokens,
            Map<String, String> environmentVariables,
            Map<String, Blob> extensions,
            OutputStream output); static final String KEY_USER; static final String KEY_HOST; static final String KEY_PORT; static final String KEY_PRIVATE_KEY; static final String KEY_PASS_PHRASE; static final String KEY_TEMPORARY_BLOB_PREFIX; static final String DEFAULT_TEMPORARY_BLOB_PREFIX; }