DSS的Java类TLValidationJob说onlineLoader未定义,但我做到了

nimxete2  于 5个月前  发布在  Java
关注(0)|答案(1)|浏览(79)

我正在尝试DSS数字签名库5.12.1(https://ec.europa.eu/digital-building-blocks/sites/display/DIGITAL/Digital+Signature+Service+-++DSS)使用类TLValidationJob在本地存储欧盟信任的X509证书。运行onlineRefresh方法时,我遇到了意外异常“java.lang.NullPointerException:The onlineLoader must be defined!”
我已经正确运行了TLValidationJob.setOnlineDataLoader,并在运行了onlineRefresh方法后不久。它应该将源/证书信息放在我的缓存中,但onlineRefresh引发了异常“Unable to retrieve the content for url 'https://ec.europa.eu/tools/lotl/eu-lotl.xml'”,原因:“java.lang.NullPointerException:The onlineLoader must be defined!",怎么回事?这是我的准系统代码(有些是分开的):

private static File tlCacheDirectory() {
    return new File("./myLOTLcache");
}
public static DSSFileLoader onlineLoader() {
    FileCacheDataLoader onlineFileLoader = new FileCacheDataLoader();
    onlineFileLoader.setCacheExpirationTime(-1); // negative value means cache never expires
    onlineFileLoader.setFileCacheDirectory(tlCacheDirectory());
    return onlineFileLoader;
}
public static CacheCleaner cacheCleaner() {
    CacheCleaner cacheCleaner = new CacheCleaner();
    cacheCleaner.setCleanMemory(true); // free the space in memory
    cacheCleaner.setCleanFileSystem(true); // and the filesystem
    cacheCleaner.setDSSFileLoader(onlineLoader());
    return cacheCleaner;
}

public static LOTLSource europeanLOTLSource() {

    LOTLSource lotlSource = new LOTLSource();
    lotlSource.setUrl("https://ec.europa.eu/tools/lotl/eu-lotl.xml");
    // I know what "pivot" is here, but "pivot support"?
    lotlSource.setPivotSupport(true);
    lotlSource.setLotlPredicate(TLPredicateFactory.createEULOTLPredicate());
    lotlSource.setTlPredicate(TLPredicateFactory.createEUTLPredicate());
    return lotlSource;
}

public static void main(String[] args) {

    TrustedListsCertificateSource myTLcertSource = new TrustedListsCertificateSource();

    TLValidationJob tlValidationJob = new TLValidationJob();
    LOTLSource mylotl = europeanLOTLSource();
    tlValidationJob.setListOfTrustedListSources(mylotl);

    // set the TrustedListsCertificateSource to be filled with the job results,
    // i.e. the list[s] should go into myTLcertSource
    tlValidationJob.setTrustedListCertificateSource(myTLcertSource);
    tlValidationJob.setOnlineDataLoader(onlineLoader());
    tlValidationJob.onlineRefresh();
}

字符串

byqmnocz

byqmnocz1#

我解决了。我从onlineLoader切换到数字签名EU库(DSS)的offlineLoader解决方案,但最重要的是我添加了setDataLoader的正确调用。代码片段是:

public static DSSFileLoader offlineLoader() {
        FileCacheDataLoader offlineFileLoader = new FileCacheDataLoader();
        offlineFileLoader.setCacheExpirationTime(-1); // negative value means cache never expires
        offlineFileLoader.setDataLoader(new NativeHTTPDataLoader());
        offlineFileLoader.setFileCacheDirectory(tlCacheDirectory());
        return offlineFileLoader;
    }

字符串
在主方法中:

tlValidationJob.setOfflineDataLoader(offlineLoader());
tlValidationJob.offlineRefresh();

相关问题