Search in sources :

Example 1 with IWatchDirCallback

use of com.helger.commons.io.watchdir.IWatchDirCallback 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)

Aggregations

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 IConfig (com.helger.config.IConfig)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 IAS4ClientBuildMessageCallback (com.helger.phase4.client.IAS4ClientBuildMessageCallback)1