use of io.jmix.core.FileStorageException in project jmix by jmix-framework.
the class ImapStoreBuilder method getMailSSLSocketFactory.
protected MailSSLSocketFactory getMailSSLSocketFactory(ImapMailBox box) throws MessagingException {
MailSSLSocketFactory socketFactory;
try {
socketFactory = new MailSSLSocketFactory();
if (config.isTrustAllCertificates()) {
log.debug("Configure factory to trust all certificates");
socketFactory.setTrustAllHosts(true);
} else {
socketFactory.setTrustAllHosts(false);
if (box.getRootCertificate() != null) {
log.debug("Configure factory to trust only known certificates and certificated from file#{}", box.getRootCertificate());
if (fileStorage == null) {
fileStorage = fileStorageLocator.getDefault();
}
try (InputStream rootCert = fileStorage.openStream(box.getRootCertificate())) {
socketFactory.setTrustManagers(new TrustManager[] { new UnifiedTrustManager(rootCert) });
} catch (FileStorageException | GeneralSecurityException | IOException e) {
throw new RuntimeException("SSL error", e);
}
}
}
} catch (GeneralSecurityException e) {
throw new MessagingException("SSL Socket factory exception", e);
}
return socketFactory;
}
use of io.jmix.core.FileStorageException in project jmix by jmix-framework.
the class LocalFileStorage method openStream.
@Override
public InputStream openStream(FileRef reference) {
Path relativePath = getRelativePath(reference.getPath());
Path[] roots = getStorageRoots();
if (roots.length == 0) {
log.error("No storage directories available");
throw new FileStorageException(FileStorageException.Type.FILE_NOT_FOUND, reference.toString());
}
InputStream inputStream = null;
for (Path root : roots) {
Path path = root.resolve(relativePath);
if (!path.toFile().exists()) {
log.error("File " + path + " not found");
continue;
}
try {
inputStream = Files.newInputStream(path);
} catch (IOException e) {
log.error("Error opening input stream for " + path, e);
}
}
if (inputStream != null) {
return inputStream;
} else {
throw new FileStorageException(FileStorageException.Type.FILE_NOT_FOUND, reference.toString());
}
}
use of io.jmix.core.FileStorageException in project jmix by jmix-framework.
the class LocalFileStorage method getStorageRoots.
protected Path[] getStorageRoots() {
if (storageRoots == null) {
String storageDir = this.storageDir != null ? this.storageDir : properties.getStorageDir();
if (StringUtils.isBlank(storageDir)) {
String workDir = coreProperties.getWorkDir();
Path dir = Paths.get(workDir, "filestorage");
if (!dir.toFile().exists() && !dir.toFile().mkdirs()) {
throw new FileStorageException(FileStorageException.Type.IO_EXCEPTION, "Cannot create filestorage directory: " + dir.toAbsolutePath().toString());
}
storageRoots = new Path[] { dir };
} else {
List<Path> list = new ArrayList<>();
for (String str : storageDir.split(",")) {
str = str.trim();
if (!StringUtils.isEmpty(str)) {
Path path = Paths.get(str);
if (!list.contains(path))
list.add(path);
}
}
storageRoots = list.toArray(new Path[0]);
}
}
return storageRoots;
}
Aggregations