/** * Create an OCSP source The default constructor for OnlineOCSPSource. The default {@code OCSPDataLoader} is set. It * is possible to change it with {@code * #setDataLoader}. */ public OnlineOCSPSource() { dataLoader = new OCSPDataLoader(); }
@Override public byte[] get(final String url) { return get(url, false); }
protected KeyStore getSSLTrustStore() throws IOException, GeneralSecurityException { return loadKeyStore(sslTruststorePath, sslTruststoreType, sslTruststorePassword); }
@Test(expected = DSSException.class) // TODO check root cause SSLHandshakeException public void testWrongTrustStore() throws GeneralSecurityException, IOException { CommonsDataLoader dataLoader = new CommonsDataLoader(); dataLoader.setSslTruststorePath(WRONG_KS_PATH); dataLoader.setSslTruststoreType(KS_TYPE); dataLoader.setSslTruststorePassword("azert"); dataLoader.setSslKeystorePath(WRONG_KS_PATH); dataLoader.setSslKeystoreType(KS_TYPE); dataLoader.setSslKeystorePassword("azert"); byte[] binaries = dataLoader.get(URL); assertNotNull(binaries); assertTrue(binaries.length > 0); }
@Test public void testTrustStore() throws GeneralSecurityException, IOException { CommonsDataLoader dataLoader = new CommonsDataLoader(); dataLoader.setSslTruststorePath(CORRECT_KS_PATH); dataLoader.setSslTruststoreType(KS_TYPE); dataLoader.setSslTruststorePassword("azert"); byte[] binaries = dataLoader.get(URL); assertNotNull(binaries); assertTrue(binaries.length > 0); }
@Before public void setUp() throws Exception { cacheDirectory = testFolder.newFolder("dss-file-cache"); dataLoader = new FileCacheDataLoader(); dataLoader.setDataLoader(new CommonsDataLoader()); dataLoader.setFileCacheDirectory(cacheDirectory); }
@Test public void testNotNetworkProtocol() throws IOException { cacheDirectory = testFolder.newFolder(); FileCacheDataLoader specificDataLoader = new FileCacheDataLoader(); specificDataLoader.setDataLoader(new MemoryDataLoader(new HashMap<String, byte[]>())); specificDataLoader.setFileCacheDirectory(cacheDirectory); assertNull(specificDataLoader.get("1.2.3.4.5")); assertNull(specificDataLoader.post("1.2.3.4.5", new byte[] { 1, 2, 3 })); specificDataLoader.setResourceLoader(new ResourceLoader(FileCacheDataLoaderTest.class)); assertNotNull(specificDataLoader.get("/logback.xml")); }
@Test public void testDefault() { CommonsDataLoader dataLoader = new CommonsDataLoader(); byte[] binaries = dataLoader.get(URL); assertNotNull(binaries); assertTrue(binaries.length > 0); }
/** * The default constructor. A {@code CommonsDataLoader is created}. */ public OnlineCRLSource() { dataLoader = new CommonsDataLoader(); LOG.trace("+OnlineCRLSource with the default data loader."); }
@Test public void getUrl_whenCacheIsNotExpired_useCachedFile() throws Exception { dataLoader.setCacheExpirationTime(2000L); long cacheCreationTime = getUrlAndReturnCacheCreationTime(); waitOneSecond(); long newCacheCreationTime = getUrlAndReturnCacheCreationTime(); assertEquals(cacheCreationTime, newCacheCreationTime); }
private long getUrlAndReturnCacheCreationTime() { byte[] bytesArray = dataLoader.get(URL_TO_LOAD); assertTrue(bytesArray.length > 0); File cachedFile = getCachedFile(cacheDirectory); return cachedFile.lastModified(); }
@Test(expected = NullPointerException.class) public void testNotDefineSubDataLoader() { FileCacheDataLoader fcdl = new FileCacheDataLoader(); fcdl.get(URL_TO_LOAD); }
/** * Allows to add a given array of {@code byte} as a cache file representing by the {@code urlString}. * * @param urlString * the URL to add to the cache * @param bytes * the content of the cache file */ public void saveBytesInCache(final String urlString, final byte[] bytes) { final String fileName = ResourceLoader.getNormalizedFileName(urlString); final File out = getCacheFile(fileName); DSSUtils.saveToFile(bytes, out); }
/** * This method is useful only with the cache handling implementation of the * {@code DataLoader}. * * @param url * to access * @param refresh * if true indicates that the cached data should be refreshed * @return {@code byte} array of obtained data */ @Override public byte[] get(final String url, final boolean refresh) { return get(url); }
@Test public void getUrl_whenExpirationTimeIsNotSet_useCachedFile() throws Exception { long cacheCreationTime = getUrlAndReturnCacheCreationTime(); waitOneSecond(); long newCacheCreationTime = getUrlAndReturnCacheCreationTime(); assertEquals(cacheCreationTime, newCacheCreationTime); }
protected byte[] fileGet(final String urlString) { return ftpGet(urlString); }
/** * @param dataLoader data loader * @param configuration configuration */ public static void decorateWithProxySettings(CommonsDataLoader dataLoader, Configuration configuration) { if (configuration.isNetworkProxyEnabled()) { ProxyConfig proxyConfig = DataLoaderDecorator.create(configuration); dataLoader.setProxyConfig(proxyConfig); } }
@Test public void getUrl_whenCacheIsExpired_downloadNewCopy() throws Exception { dataLoader.setCacheExpirationTime(500L); long cacheCreationTime = getUrlAndReturnCacheCreationTime(); waitOneSecond(); long newCacheCreationTime = getUrlAndReturnCacheCreationTime(); assertTrue(cacheCreationTime < newCacheCreationTime); }
/** * Allows to load the file for a given file name from the cache folder. * * @return the content of the file or {@code null} if the file does not exist */ public byte[] loadFileFromCache(final String urlString) { final String fileName = ResourceLoader.getNormalizedFileName(urlString); final File file = getCacheFile(fileName); if (file.exists()) { final byte[] bytes = DSSUtils.toByteArray(file); return bytes; } return null; }
protected KeyStore getSSLKeyStore() throws IOException, GeneralSecurityException { return loadKeyStore(sslKeystorePath, sslKeystoreType, sslKeystorePassword); }