Example usage for org.apache.commons.lang.time DateUtils MILLIS_PER_SECOND

List of usage examples for org.apache.commons.lang.time DateUtils MILLIS_PER_SECOND

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils MILLIS_PER_SECOND.

Prototype

long MILLIS_PER_SECOND

To view the source code for org.apache.commons.lang.time DateUtils MILLIS_PER_SECOND.

Click Source Link

Document

Number of milliseconds in a standard second.

Usage

From source file:mitm.common.security.certpath.CertStoreTrustAnchorBuilderTest.java

@Test
public void testInitialBuild()
        throws CertStoreException, CertificateException, NoSuchProviderException, IOException {
    addRoot("rim.cer", certStore);

    TrustAnchorBuilder builder = new CertStoreTrustAnchorBuilder(certStore, 10 * DateUtils.MILLIS_PER_SECOND);

    Set<TrustAnchor> trustAnchors = builder.getTrustAnchors();

    assertEquals(1, trustAnchors.size());
}

From source file:mitm.common.security.certpath.CertStoreTrustAnchorBuilderTest.java

@Test
public void testEmptyStore() throws CertStoreException {
    TrustAnchorBuilder builder = new CertStoreTrustAnchorBuilder(certStore, 10 * DateUtils.MILLIS_PER_SECOND);

    Set<TrustAnchor> trustAnchors = builder.getTrustAnchors();

    assertEquals(0, trustAnchors.size());
}

From source file:mitm.common.security.certpath.CertStoreTrustAnchorBuilderTest.java

@Test
public void testAddCertificate() throws CertStoreException, CertificateException, NoSuchProviderException,
        IOException, InterruptedException {
    TrustAnchorBuilder builder = new CertStoreTrustAnchorBuilder(certStore, 0 * DateUtils.MILLIS_PER_SECOND);

    Set<TrustAnchor> trustAnchors = builder.getTrustAnchors();

    assertEquals(0, trustAnchors.size());

    addRoot("rim.cer", certStore);

    assertEquals(0, trustAnchors.size());

    trustAnchors = builder.getTrustAnchors();

    assertEquals(1, trustAnchors.size());
}

From source file:mitm.common.security.crl.CRLStoreUpdaterImplTest.java

@Test
public void testUpdateCRLStoreIllegalCRLDistPoint() throws Exception {
    addCertificates(new File(testBase, "certificates/windows-xp-all-roots.p7b"), rootStore);
    addCertificates(new File(testBase, "certificates/certeurope_root_ca_illegal_crl_dist_point.crt"),
            rootStore);/*  w ww. j ava  2 s. c om*/

    KeyAndCertStore keyAndCertStore = new KeyAndCertStoreImpl(certStore, null, null);

    PKISecurityServices pKISecurityServices = TestUtils.createDefaultPKISecurityServices(keyAndCertStore,
            rootStore, crlStore);

    CRLDownloadParameters downloadParameters = new CRLDownloadParameters(
            1 * DateUtils.MILLIS_PER_MINUTE, /* total timeout */
            30 * DateUtils.MILLIS_PER_SECOND, /* connect timeout */
            30 * DateUtils.MILLIS_PER_SECOND, /* read timeout */
            25 * 1024 * 1024); /* max bytes */

    CRLDownloader crlDownloader = new CRLDownloaderImpl(downloadParameters);

    CRLStoreMaintainer crlStoreMaintainer = new CRLStoreMaintainerImpl(pKISecurityServices.getCRLStore(),
            pKISecurityServices.getCRLPathBuilderFactory(), false);

    DefaultCRLStoreUpdaterParametersBuilder paramsBuilder = new DefaultCRLStoreUpdaterParametersBuilder(
            pKISecurityServices, crlDownloader, crlStoreMaintainer);

    CRLStoreUpdaterParameters updaterParams = paramsBuilder.createCRLStoreUpdaterParameters();

    CRLStoreUpdater crlUpdater = new CRLStoreUpdaterImpl(updaterParams);

    // this should not result in an exception
    crlUpdater.update();

    // should normally not fail if a valid internet connection is available
    assertTrue("This might fail if non of the downloaded CRLs are accessible.", crlStore.size() > 0);
}

From source file:mitm.common.security.certpath.CertStoreTrustAnchorBuilderTest.java

@Test
public void testAddExtraCertificate()
        throws CertStoreException, CertificateException, NoSuchProviderException, IOException {
    TrustAnchorBuilder builder = new CertStoreTrustAnchorBuilder(certStore, 0 * DateUtils.MILLIS_PER_SECOND);

    File file = new File("test/resources/testdata/certificates", "gmail-ssl.cer");

    Collection<? extends Certificate> certificates = CertificateUtils.readCertificates(file);

    builder.addCertificates(certificates);

    Set<TrustAnchor> trustAnchors = builder.getTrustAnchors();

    assertEquals(1, trustAnchors.size());

    addRoot("rim.cer", certStore);

    trustAnchors = builder.getTrustAnchors();

    assertEquals(2, trustAnchors.size());

    file = new File("test/resources/testdata/certificates", "chinesechars.cer");

    certificates = CertificateUtils.readCertificates(file);

    builder.addCertificates(certificates);

    trustAnchors = builder.getTrustAnchors();

    assertEquals(3, trustAnchors.size());
}

From source file:mitm.common.security.certpath.CertStoreTrustAnchorBuilderTest.java

@Test(expected = UnsupportedOperationException.class)
public void testUnmodifiableCollection()
        throws CertStoreException, CertificateException, NoSuchProviderException, IOException {
    TrustAnchorBuilder builder = new CertStoreTrustAnchorBuilder(certStore, 0 * DateUtils.MILLIS_PER_SECOND);

    Set<TrustAnchor> trustAnchors = builder.getTrustAnchors();

    trustAnchors.add(null);/* www. j  a v a 2  s .  c  om*/
}

From source file:mitm.test.TestUtils.java

public static PKISecurityServices createDefaultPKISecurityServices(KeyAndCertStore keyAndCertStore,
        X509CertStoreExt rootStore, X509CRLStoreExt crlStore)
        throws NoSuchAlgorithmException, NoSuchProviderException, SecurityFactoryFactoryException {
    TrustAnchorBuilder trustAnchorBuilder = new CertStoreTrustAnchorBuilder(rootStore,
            30 * DateUtils.MILLIS_PER_SECOND);

    CertificatePathBuilderFactory certificatePathBuilderFactory = new DefaultCertificatePathBuilderFactory(
            trustAnchorBuilder, keyAndCertStore);

    Encryptor encryptor = new PasswordBasedEncryptor("djigzo");

    RevocationChecker revocationChecker = new PKIXRevocationChecker(crlStore);

    CRLPathBuilderFactory crlPathBuilderFactory = new DefaultCRLPathBuilderFactory(
            certificatePathBuilderFactory);

    PKITrustCheckCertificateValidatorFactory validatorFactory = new PKISMIMETrustCheckCertificateValidatorFactory(
            certificatePathBuilderFactory, revocationChecker, null);

    PKISecurityServicesFactory pkiSecurityServicesFactory = new DefaultPKISecurityServicesFactory(
            keyAndCertStore, rootStore, crlStore, trustAnchorBuilder, revocationChecker, encryptor,
            certificatePathBuilderFactory, crlPathBuilderFactory, validatorFactory);

    return pkiSecurityServicesFactory.createPKISecurityServices();
}

From source file:mitm.common.security.crl.CRLStoreUpdaterImplTest.java

@Test
public void testUpdateCRLStore() throws Exception {
    addCertificates(new File(testBase, "certificates/windows-xp-all-roots.p7b"), rootStore);
    addCertificates(new File(testBase, "certificates/windows-xp-all-intermediates.p7b"), certStore);
    addCertificates(new File(testBase, "certificates/some-public.p7b"), certStore);

    KeyAndCertStore keyAndCertStore = new KeyAndCertStoreImpl(certStore, null, null);

    PKISecurityServices pKISecurityServices = TestUtils.createDefaultPKISecurityServices(keyAndCertStore,
            rootStore, crlStore);/* w ww. j  av a2s .  co m*/

    CRLDownloadParameters downloadParameters = new CRLDownloadParameters(
            1 * DateUtils.MILLIS_PER_MINUTE, /* total timeout */
            30 * DateUtils.MILLIS_PER_SECOND, /* connect timeout */
            30 * DateUtils.MILLIS_PER_SECOND, /* read timeout */
            25 * 1024 * 1024); /* max bytes */

    CRLDownloader crlDownloader = new CRLDownloaderImpl(downloadParameters);

    CRLStoreMaintainer crlStoreMaintainer = new CRLStoreMaintainerImpl(pKISecurityServices.getCRLStore(),
            pKISecurityServices.getCRLPathBuilderFactory(), false);

    DefaultCRLStoreUpdaterParametersBuilder paramsBuilder = new DefaultCRLStoreUpdaterParametersBuilder(
            pKISecurityServices, crlDownloader, crlStoreMaintainer);

    CRLStoreUpdaterParameters updaterParams = paramsBuilder.createCRLStoreUpdaterParameters();

    CRLStoreUpdater crlUpdater = new CRLStoreUpdaterImpl(updaterParams);

    crlUpdater.update();
}

From source file:mitm.common.security.certpath.CertStoreTrustAnchorBuilderTest.java

@Test
public void testNoChange()
        throws CertStoreException, CertificateException, NoSuchProviderException, IOException {
    TrustAnchorBuilder builder = new CertStoreTrustAnchorBuilder(certStore,
            999999 * DateUtils.MILLIS_PER_SECOND);

    addRoot("rim.cer", certStore);

    Set<TrustAnchor> trustAnchors1 = builder.getTrustAnchors();
    Set<TrustAnchor> trustAnchors2 = builder.getTrustAnchors();

    assertSame(trustAnchors1, trustAnchors2);
}

From source file:edu.kit.dama.transfer.client.types.TransferTask.java

/**
 * Perform the transfer task by transferring the source file to the target
 * file. After the transfer the source file may be deleted if cleanup was
 * requested. If cleanup was requested and fails, only a warning is logged, as
 * the transfer has succeeded.//from w ww.ja  va 2  s.  c  o  m
 */
@Override
public final void run() {
    status = TRANSFER_TASK_STATUS.RUNNING;
    fireTransferStartedEvents();
    boolean transferSucceeded = false;
    //perform the transfer task including retry handling
    for (int attempt = 1; attempt <= MAX_TRIES; attempt++) {
        if (!transferSucceeded && attempt > 1) {
            LOGGER.info("Retrying transfer...");
        }
        try {
            LOGGER.info("TransferTask starts transfer from {} to {}",
                    new Object[] { getSourceFile(), getTargetFile() });
            getSourceFile().transfer(getTargetFile());
            transferSucceeded = true;
            break;
        } catch (AdalapiException ae) {//normal exception...retry
            LOGGER.error("Failed to transfer file " + getSourceFile() + " to " + getTargetFile() + "(Attempt: "
                    + attempt + ")", ae);
        } catch (TransferNotSupportedException tnse) {//fatal exception (file not readable, does not exist...), retry won't help.
            LOGGER.error("Failed to transfer file " + getSourceFile() + " to " + getTargetFile()
                    + ". Not using more attempts.", tnse);
            attempt = MAX_TRIES;
        }

        //wait retry delay
        try {
            Thread.sleep(RETRY_DELAY_IN_SECONDS * DateUtils.MILLIS_PER_SECOND);
        } catch (InterruptedException ie) {
        }
    }

    //do cleanup if transfer has succeeded
    if (!transferSucceeded) {
        LOGGER.error("Transfer failed within {} tries. Skipping cleanup and aborting!", MAX_TRIES);
    } else {
        if (!cleanup()) {
            //log warning
            LOGGER.info("Cleanup failed. Manual cleanup for file {} necessary.", getSourceFile());
        }
    }

    if (transferSucceeded) {
        status = TRANSFER_TASK_STATUS.SUCCEEDED;
        fireTransferFinishedEvents();
    } else {
        status = TRANSFER_TASK_STATUS.FAILED;
        fireTransferFailedEvents();
    }
}