Search in sources :

Example 1 with IConfig

use of com.helger.config.IConfig in project phase4 by phax.

the class DropFolderUserMessage method init.

public static void init(@Nonnull final IAS4CryptoFactory aCryptoFactory) {
    if (s_aWatch != null)
        throw new IllegalStateException("Already inited!");
    final IConfig aConfig = AS4Configuration.getConfig();
    final Path aOutgoingDir = Paths.get(aConfig.getAsString("server.directory.outgoing", "out"));
    final Path aIncomingDir = Paths.get(aConfig.getAsString("server.directory.incoming", "in"));
    try {
        // Ensure directories are present
        Files.createDirectories(aOutgoingDir.resolve(PATH_DONE));
        Files.createDirectories(aOutgoingDir.resolve(PATH_ERROR));
        Files.createDirectories(aIncomingDir);
        // Start watching directory for changes
        final IWatchDirCallback aCB = (eAction, aCurFile) -> {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("WatchEvent " + eAction + " - " + aCurFile);
            if (!eAction.equals(EWatchDirAction.DELETE) && aCurFile.toFile().isFile() && aCurFile.getFileName() != null && aCurFile.getFileName().toString().endsWith(".xml")) {
                _send(aCryptoFactory, aCurFile, aIncomingDir);
            }
        };
        s_aWatch = WatchDir.createAsyncRunningWatchDir(aOutgoingDir, false, aCB);
        // Send initially for all existing files
        try (final DirectoryStream<Path> aStream = Files.newDirectoryStream(aOutgoingDir, x -> x.toFile().isFile() && x.getFileName() != null && x.getFileName().toString().endsWith(".xml"))) {
            for (final Path aCur : aStream) _send(aCryptoFactory, aCur, aIncomingDir);
        }
    } catch (final IOException ex) {
        // Checked to unchecked conversion
        throw new UncheckedIOException(ex);
    }
}
Also used : IConfig(com.helger.config.IConfig) Path(java.nio.file.Path) X509Certificate(java.security.cert.X509Certificate) PeppolCertificateHelper(com.helger.peppol.utils.PeppolCertificateHelper) StreamHelper(com.helger.commons.io.stream.StreamHelper) EWatchDirAction(com.helger.commons.io.watchdir.EWatchDirAction) ESoapVersion(com.helger.phase4.soap.ESoapVersion) LoggerFactory(org.slf4j.LoggerFactory) WatchDir(com.helger.commons.io.watchdir.WatchDir) ECryptoAlgorithmSign(com.helger.phase4.crypto.ECryptoAlgorithmSign) DirectoryStream(java.nio.file.DirectoryStream) PeppolSBDHDocument(com.helger.peppol.sbdh.PeppolSBDHDocument) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ResponseHandlerByteArray(com.helger.httpclient.response.ResponseHandlerByteArray) FilenameHelper(com.helger.commons.io.file.FilenameHelper) IWatchDirCallback(com.helger.commons.io.watchdir.IWatchDirCallback) IAS4RetryCallback(com.helger.phase4.client.IAS4RetryCallback) ISMPServiceMetadataProvider(com.helger.smpclient.peppol.ISMPServiceMetadataProvider) Path(java.nio.file.Path) ESML(com.helger.peppol.sml.ESML) IAS4OutgoingDumper(com.helger.phase4.dump.IAS4OutgoingDumper) ECryptoAlgorithmSignDigest(com.helger.phase4.crypto.ECryptoAlgorithmSignDigest) KeyStore(java.security.KeyStore) SMPClient(com.helger.smpclient.peppol.SMPClient) UncheckedIOException(java.io.UncheckedIOException) CertificateHelper(com.helger.security.certificate.CertificateHelper) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) ESMPTransportProfile(com.helger.peppol.smp.ESMPTransportProfile) MessageHelperMethods(com.helger.phase4.messaging.domain.MessageHelperMethods) PeppolSBDHDocumentReader(com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader) PeppolURLProvider(com.helger.smpclient.url.PeppolURLProvider) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) AS4Configuration(com.helger.phase4.config.AS4Configuration) IConfig(com.helger.config.IConfig) IPeppolURLProvider(com.helger.smpclient.url.IPeppolURLProvider) AS4ResourceHelper(com.helger.phase4.util.AS4ResourceHelper) Nonnull(javax.annotation.Nonnull) Logger(org.slf4j.Logger) PeppolIdentifierFactory(com.helger.peppolid.factory.PeppolIdentifierFactory) Files(java.nio.file.Files) AS4ClientSentMessage(com.helger.phase4.client.AS4ClientSentMessage) W3CEndpointReferenceHelper(com.helger.smpclient.peppol.utils.W3CEndpointReferenceHelper) IOException(java.io.IOException) File(java.io.File) SimpleFileIO(com.helger.commons.io.file.SimpleFileIO) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) Paths(java.nio.file.Paths) StopWatch(com.helger.commons.timing.StopWatch) SBDHReader(com.helger.sbdh.builder.SBDHReader) AS4ClientUserMessage(com.helger.phase4.client.AS4ClientUserMessage) CAS4(com.helger.phase4.CAS4) StandardBusinessDocument(org.unece.cefact.namespaces.sbdh.StandardBusinessDocument) SBDHWriter(com.helger.sbdh.builder.SBDHWriter) IWatchDirCallback(com.helger.commons.io.watchdir.IWatchDirCallback) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 2 with IConfig

use of com.helger.config.IConfig in project phase4 by phax.

the class AS4CryptoProperties method createFromConfig.

/**
 * @return A new {@link AS4CryptoProperties} object filled with all values
 *         from the global configuration file. Values not present in the
 *         configuration are not set and stay with their default values.
 * @since 0.11.0
 */
@Nonnull
public static AS4CryptoProperties createFromConfig() {
    final IConfig aConfig = AS4Configuration.getConfig();
    final AS4CryptoProperties ret = new AS4CryptoProperties();
    for (final String sKey : new String[] { CRYPTO_PROVIDER, KEYSTORE_TYPE, KEYSTORE_FILE, KEYSTORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD, LOAD_CACERTS, TRUSTSTORE_PROVIDER, TRUSTSTORE_TYPE, TRUSTSTORE_FILE, TRUSTSTORE_PASSWORD }) {
        final String sConfigValue = aConfig.getAsString(sKey);
        if (sConfigValue != null)
            ret.m_aProps.put(sKey, sConfigValue);
    }
    return ret;
}
Also used : IConfig(com.helger.config.IConfig) Nonnull(javax.annotation.Nonnull)

Example 3 with IConfig

use of com.helger.config.IConfig in project phoss-directory by phax.

the class PDClientConfiguration method setConfig.

/**
 * Overwrite the global configuration. This is only needed for testing.
 *
 * @param aNewConfig
 *        The configuration to use globally. May not be <code>null</code>.
 * @return The old value of {@link IConfig}. Never <code>null</code>.
 */
@Nonnull
public static IConfig setConfig(@Nonnull final IConfig aNewConfig) {
    ValueEnforcer.notNull(aNewConfig, "NewConfig");
    final IConfig ret;
    RW_LOCK.writeLock().lock();
    try {
        ret = s_aConfig;
        s_aConfig = aNewConfig;
    } finally {
        RW_LOCK.writeLock().unlock();
    }
    if (!EqualsHelper.identityEqual(ret, aNewConfig))
        LOGGER.info("The SMPClient configuration provider was changed to " + aNewConfig);
    return ret;
}
Also used : IConfig(com.helger.config.IConfig) Nonnull(javax.annotation.Nonnull)

Example 4 with IConfig

use of com.helger.config.IConfig in project peppol-commons by phax.

the class SMPClientConfiguration method setConfig.

/**
 * Overwrite the global configuration. This is only needed for testing.
 *
 * @param aNewConfig
 *        The configuration to use globally. May not be <code>null</code>.
 * @return The old value of {@link IConfig}. Never <code>null</code>.
 */
@Nonnull
public static IConfig setConfig(@Nonnull final IConfig aNewConfig) {
    ValueEnforcer.notNull(aNewConfig, "NewConfig");
    final IConfig ret;
    RW_LOCK.writeLock().lock();
    try {
        ret = s_aConfig;
        s_aConfig = aNewConfig;
    } finally {
        RW_LOCK.writeLock().unlock();
    }
    if (!EqualsHelper.identityEqual(ret, aNewConfig))
        LOGGER.info("The SMPClient configuration provider was changed to " + aNewConfig);
    return ret;
}
Also used : IConfig(com.helger.config.IConfig) Nonnull(javax.annotation.Nonnull)

Example 5 with IConfig

use of com.helger.config.IConfig in project phase4 by phax.

the class AS4Configuration method setConfig.

/**
 * Overwrite the global configuration. This is only needed for testing.
 *
 * @param aNewConfig
 *        The configuration to use globally. May not be <code>null</code>.
 * @return The old value of {@link IConfig}. Never <code>null</code>.
 */
@Nonnull
public static IConfig setConfig(@Nonnull final IConfig aNewConfig) {
    ValueEnforcer.notNull(aNewConfig, "NewConfig");
    final IConfig ret;
    RW_LOCK.writeLock().lock();
    try {
        ret = s_aConfig;
        s_aConfig = aNewConfig;
    } finally {
        RW_LOCK.writeLock().unlock();
    }
    if (!EqualsHelper.identityEqual(ret, aNewConfig))
        LOGGER.info("The phase4 configuration provider was changed to " + aNewConfig);
    return ret;
}
Also used : IConfig(com.helger.config.IConfig) Nonnull(javax.annotation.Nonnull)

Aggregations

IConfig (com.helger.config.IConfig)6 Nonnull (javax.annotation.Nonnull)6 FilenameHelper (com.helger.commons.io.file.FilenameHelper)1 SimpleFileIO (com.helger.commons.io.file.SimpleFileIO)1 StreamHelper (com.helger.commons.io.stream.StreamHelper)1 EWatchDirAction (com.helger.commons.io.watchdir.EWatchDirAction)1 IWatchDirCallback (com.helger.commons.io.watchdir.IWatchDirCallback)1 WatchDir (com.helger.commons.io.watchdir.WatchDir)1 StopWatch (com.helger.commons.timing.StopWatch)1 ResponseHandlerByteArray (com.helger.httpclient.response.ResponseHandlerByteArray)1 PeppolSBDHDocument (com.helger.peppol.sbdh.PeppolSBDHDocument)1 PeppolSBDHDocumentReader (com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader)1 ESML (com.helger.peppol.sml.ESML)1 ESMPTransportProfile (com.helger.peppol.smp.ESMPTransportProfile)1 PeppolCertificateHelper (com.helger.peppol.utils.PeppolCertificateHelper)1 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)1 PeppolIdentifierFactory (com.helger.peppolid.factory.PeppolIdentifierFactory)1 CAS4 (com.helger.phase4.CAS4)1 AS4ClientSentMessage (com.helger.phase4.client.AS4ClientSentMessage)1 AS4ClientUserMessage (com.helger.phase4.client.AS4ClientUserMessage)1