use of org.demoiselle.signer.core.exception.CertificateValidatorException in project signer by demoiselle.
the class RepositoryService method update.
private static void update(String url) {
try {
Configuration config = Configuration.getInstance();
File fileCLR = new File(config.getCrlPath(), RepositoryUtil.urlToMD5(url));
print(coreMessagesBundle.getString("info.repository.service.download", url));
RepositoryUtil.saveURL(url, fileCLR);
println("...[Ok]");
} catch (CertificateValidatorException e) {
println(coreMessagesBundle.getString("error.repository.service.fail"));
println(coreMessagesBundle.getString("error.repository.service.cause") + e.getMessage());
}
}
use of org.demoiselle.signer.core.exception.CertificateValidatorException in project signer by demoiselle.
the class RepositoryUtil method saveURL.
/**
* @param sUrl source url
* @param destinationFile destination file
*/
public static void saveURL(String sUrl, File destinationFile) {
URL url;
byte[] buf;
int ByteRead;
setByteWritten(0);
BufferedOutputStream outStream = null;
URLConnection uCon = null;
InputStream is = null;
try {
url = new URL(sUrl);
uCon = url.openConnection();
uCon.setConnectTimeout(5000);
is = uCon.getInputStream();
outStream = new BufferedOutputStream(new FileOutputStream(destinationFile));
buf = new byte[1024];
while ((ByteRead = is.read(buf)) != -1) {
outStream.write(buf, 0, ByteRead);
setByteWritten(getByteWritten() + ByteRead);
}
} catch (MalformedURLException e) {
throw new CertificateValidatorException(coreMessagesBundle.getString("error.malformed.url", sUrl), e);
} catch (FileNotFoundException e) {
throw new CertificateValidatorException(coreMessagesBundle.getString("error.file.not.found", sUrl), e);
} catch (IOException e) {
logger.info(coreMessagesBundle.getString("error.crl.open.connection", sUrl) + e.getMessage());
} finally {
try {
if (is != null) {
is.close();
}
if (outStream != null) {
outStream.close();
}
} catch (Throwable e) {
throw new CertificateValidatorException(coreMessagesBundle.getString("error.crl.close.connection", sUrl), e);
}
}
}
Aggregations