Search in sources :

Example 1 with NonBlockingProperties

use of com.helger.commons.lang.NonBlockingProperties in project ph-web by phax.

the class AbstractScpTestBase method initializeClass.

@BeforeClass
public static void initializeClass() {
    try (final InputStream inputStream = ClassLoader.getSystemResourceAsStream("configuration.properties")) {
        Assume.assumeNotNull(inputStream);
        s_aProperties = new NonBlockingProperties();
        s_aProperties.load(inputStream);
    } catch (final IOException e) {
        LOGGER.warn("cant find properties file (tests will be skipped): " + e.getMessage());
        s_aProperties = null;
        return;
    }
    final String knownHosts = s_aProperties.getProperty("ssh.knownHosts");
    final String privateKey = s_aProperties.getProperty("ssh.privateKey");
    s_sScpPath = s_aProperties.getProperty("scp.out.test.scpPath");
    s_sFileSystemPath = s_aProperties.getProperty("scp.out.test.filesystemPath");
    final String username = s_aProperties.getProperty("scp.out.test.username");
    final String hostname = "localhost";
    final int port = Integer.parseInt(s_aProperties.getProperty("scp.out.test.port"));
    final DefaultSessionFactory defaultSessionFactory = new DefaultSessionFactory(username, hostname, port);
    try {
        defaultSessionFactory.setKnownHosts(knownHosts);
        defaultSessionFactory.setIdentityFromPrivateKey(privateKey);
    } catch (final JSchException e) {
        Assume.assumeNoException(e);
    }
    s_aSessionFactory = defaultSessionFactory;
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties) JSchException(com.jcraft.jsch.JSchException) DefaultSessionFactory(com.helger.jsch.session.DefaultSessionFactory) InputStream(java.io.InputStream) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 2 with NonBlockingProperties

use of com.helger.commons.lang.NonBlockingProperties in project ph-web by phax.

the class TunnelConnectionTest method initializeClass.

@BeforeClass
public static void initializeClass() {
    try (final InputStream inputStream = ClassLoader.getSystemResourceAsStream("configuration.properties")) {
        Assume.assumeNotNull(inputStream);
        properties = new NonBlockingProperties();
        properties.load(inputStream);
    } catch (final IOException e) {
        LOGGER.warn("cant find properties file (tests will be skipped)", e);
        properties = null;
        return;
    }
    final String knownHosts = properties.getProperty("ssh.knownHosts");
    final String privateKey = properties.getProperty("ssh.privateKey");
    final String username = properties.getProperty("scp.out.test.username");
    final String hostname = "localhost";
    final int port = Integer.parseInt(properties.getProperty("scp.out.test.port"));
    final DefaultSessionFactory defaultSessionFactory = new DefaultSessionFactory(username, hostname, port);
    try {
        defaultSessionFactory.setKnownHosts(knownHosts);
        defaultSessionFactory.setIdentityFromPrivateKey(privateKey);
    } catch (final JSchException e) {
        LOGGER.error("Failed to configure default session, skipping tests", e);
        Assume.assumeNoException(e);
    }
    sessionFactory = defaultSessionFactory;
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties) JSchException(com.jcraft.jsch.JSchException) DefaultSessionFactory(com.helger.jsch.session.DefaultSessionFactory) InputStream(java.io.InputStream) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 3 with NonBlockingProperties

use of com.helger.commons.lang.NonBlockingProperties in project phase4 by phax.

the class AS4CryptoProperties method _setProperty.

private void _setProperty(@Nonnull final String sName, @Nullable final String sValue) {
    ValueEnforcer.notNull(sName, "Name");
    NonBlockingProperties aProps = m_aProps;
    if (sValue == null) {
        // Remove property
        if (aProps != null)
            aProps.remove(sName);
    } else {
        // Set property
        if (aProps == null)
            aProps = m_aProps = new NonBlockingProperties();
        aProps.put(sName, sValue);
    }
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties)

Example 4 with NonBlockingProperties

use of com.helger.commons.lang.NonBlockingProperties in project ph-commons by phax.

the class SettingsPersistenceProperties method writeSettings.

@Nonnull
public ESuccess writeSettings(@Nonnull final ISettings aSettings, @Nonnull @WillClose final OutputStream aOS) {
    ValueEnforcer.notNull(aOS, "OutputStream");
    try {
        final NonBlockingProperties aProps = new NonBlockingProperties();
        // Must not be sorted, as Properties sorts them as it wishes...
        for (final Map.Entry<String, Object> aEntry : aSettings.entrySet()) {
            final String sName = aEntry.getKey();
            final Object aValue = aEntry.getValue();
            if (aValue instanceof ISettings)
                throw new IllegalArgumentException("When saving settings to a Properties object, it may not contained nested settings! Now the key '" + sName + "' is mapped to a nested ISettings object!");
            final String sValue = TypeConverter.convert(aValue, String.class);
            aProps.put(sName, sValue);
        }
        // Does not close the output stream!
        aProps.store(aOS, aSettings.getName());
        return ESuccess.SUCCESS;
    } catch (final IOException ex) {
        LOGGER.error("Failed to write settings to properties file", ex);
        return ESuccess.FAILURE;
    } finally {
        StreamHelper.close(aOS);
    }
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties) IOException(java.io.IOException) ISettings(com.helger.settings.ISettings) Map(java.util.Map) Nonnull(javax.annotation.Nonnull)

Example 5 with NonBlockingProperties

use of com.helger.commons.lang.NonBlockingProperties in project ph-web by phax.

the class ConnectionTest method initializeClass.

@BeforeClass
public static void initializeClass() {
    NonBlockingProperties properties = null;
    try (final InputStream inputStream = ClassLoader.getSystemResourceAsStream("configuration.properties")) {
        Assume.assumeNotNull(inputStream);
        properties = new NonBlockingProperties();
        properties.load(inputStream);
    } catch (final IOException e) {
        LOGGER.warn("cant find properties file (tests will be skipped)", e);
        Assume.assumeNoException(e);
    }
    username = properties.getProperty("scp.out.test.username");
    hostname = properties.getProperty("scp.out.test.host");
    correctPassword = properties.getProperty("scp.out.test.password");
    port = Integer.parseInt(properties.getProperty("scp.out.test.port"));
    incorrectPassword = correctPassword + ".";
}
Also used : NonBlockingProperties(com.helger.commons.lang.NonBlockingProperties) InputStream(java.io.InputStream) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Aggregations

NonBlockingProperties (com.helger.commons.lang.NonBlockingProperties)10 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 BeforeClass (org.junit.BeforeClass)5 DefaultSessionFactory (com.helger.jsch.session.DefaultSessionFactory)4 JSchException (com.jcraft.jsch.JSchException)4 Nonnull (javax.annotation.Nonnull)3 ISettings (com.helger.settings.ISettings)2 File (java.io.File)1 Map (java.util.Map)1 MissingResourceException (java.util.MissingResourceException)1 Test (org.junit.Test)1