projects
/
lgpl
/
argeo-commons.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4d9c1bd
)
Improve exception handling
author
Mathieu Baudier <mbaudier@argeo.org>
Wed, 6 Jun 2018 16:45:22 +0000
(18:45 +0200)
committer
Mathieu Baudier <mbaudier@argeo.org>
Wed, 6 Jun 2018 16:45:22 +0000
(18:45 +0200)
org.argeo.jcr/ext/test/org/argeo/jcr/fs/JcrFileSystemTest.java
patch
|
blob
|
history
org.argeo.jcr/src/org/argeo/jackrabbit/fs/DavexFsProvider.java
patch
|
blob
|
history
org.argeo.jcr/src/org/argeo/jackrabbit/fs/JackrabbitMemoryFsProvider.java
patch
|
blob
|
history
org.argeo.jcr/src/org/argeo/jcr/fs/BinaryChannel.java
patch
|
blob
|
history
org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java
patch
|
blob
|
history
org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java
patch
|
blob
|
history
diff --git
a/org.argeo.jcr/ext/test/org/argeo/jcr/fs/JcrFileSystemTest.java
b/org.argeo.jcr/ext/test/org/argeo/jcr/fs/JcrFileSystemTest.java
index de2e8e828ff61b55ceb29382c3f7120253218ef9..e24a7de9ff2e00e0783f57fa71e93893d1c2a689 100644
(file)
--- a/
org.argeo.jcr/ext/test/org/argeo/jcr/fs/JcrFileSystemTest.java
+++ b/
org.argeo.jcr/ext/test/org/argeo/jcr/fs/JcrFileSystemTest.java
@@
-66,6
+66,9
@@
public class JcrFileSystemTest extends TestCase {
log.debug("Created sub directories " + subsubdir);
Path copiedFile = testDir.resolve("copiedFile.txt");
log.debug("Resolved " + copiedFile);
log.debug("Created sub directories " + subsubdir);
Path copiedFile = testDir.resolve("copiedFile.txt");
log.debug("Resolved " + copiedFile);
+ Path relativeCopiedFile = testDir.relativize(copiedFile);
+ assertEquals(copiedFile.getFileName().toString(), relativeCopiedFile.toString());
+ log.debug("Relative copied file " + relativeCopiedFile);
try (OutputStream out = Files.newOutputStream(copiedFile); InputStream in = Files.newInputStream(testPath)) {
IOUtils.copy(in, out);
}
try (OutputStream out = Files.newOutputStream(copiedFile); InputStream in = Files.newInputStream(testPath)) {
IOUtils.copy(in, out);
}
diff --git
a/org.argeo.jcr/src/org/argeo/jackrabbit/fs/DavexFsProvider.java
b/org.argeo.jcr/src/org/argeo/jackrabbit/fs/DavexFsProvider.java
index d9e106b56a4039d0a903a41bad37f668360fb569..764eed0354bd742123326b92052ca49ed0479965 100644
(file)
--- a/
org.argeo.jcr/src/org/argeo/jackrabbit/fs/DavexFsProvider.java
+++ b/
org.argeo.jcr/src/org/argeo/jackrabbit/fs/DavexFsProvider.java
@@
-47,7
+47,8
@@
public class DavexFsProvider extends AbstractJackrabbitFsProvider {
}
}
}
}
- private JcrFileSystem tryGetRepo(RepositoryFactory repositoryFactory, URI repoUri, String workspace) {
+ private JcrFileSystem tryGetRepo(RepositoryFactory repositoryFactory, URI repoUri, String workspace)
+ throws IOException {
Map<String, String> params = new HashMap<String, String>();
params.put(JACKRABBIT_REPOSITORY_URI, repoUri.toString());
params.put(JACKRABBIT_REMOTE_DEFAULT_WORKSPACE, "main");
Map<String, String> params = new HashMap<String, String>();
params.put(JACKRABBIT_REPOSITORY_URI, repoUri.toString());
params.put(JACKRABBIT_REMOTE_DEFAULT_WORKSPACE, "main");
diff --git
a/org.argeo.jcr/src/org/argeo/jackrabbit/fs/JackrabbitMemoryFsProvider.java
b/org.argeo.jcr/src/org/argeo/jackrabbit/fs/JackrabbitMemoryFsProvider.java
index 0ed826894e9a5e79e2df98023f0a118389d44fb4..47cf33d142de12d8b3a2a848b721c5efe0beba3b 100644
(file)
--- a/
org.argeo.jcr/src/org/argeo/jackrabbit/fs/JackrabbitMemoryFsProvider.java
+++ b/
org.argeo.jcr/src/org/argeo/jackrabbit/fs/JackrabbitMemoryFsProvider.java
@@
-2,6
+2,7
@@
package org.argeo.jackrabbit.fs;
import java.io.IOException;
import java.net.URI;
import java.io.IOException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.net.URL;
import java.nio.file.FileSystem;
import java.nio.file.Files;
@@
-9,6
+10,7
@@
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
+import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
@@
-37,8
+39,8
@@
public class JackrabbitMemoryFsProvider extends AbstractJackrabbitFsProvider {
Session session = repository.login(new SimpleCredentials(username, username.toCharArray()));
fileSystem = new JcrFileSystem(this, session);
return fileSystem;
Session session = repository.login(new SimpleCredentials(username, username.toCharArray()));
fileSystem = new JcrFileSystem(this, session);
return fileSystem;
- } catch (Exception e) {
- throw new
JcrFs
Exception("Cannot login to repository", e);
+ } catch (
RepositoryException | URISyntax
Exception e) {
+ throw new
IO
Exception("Cannot login to repository", e);
}
}
}
}
@@
-50,11
+52,11
@@
public class JackrabbitMemoryFsProvider extends AbstractJackrabbitFsProvider {
@Override
public Path getPath(URI uri) {
String path = uri.getPath();
@Override
public Path getPath(URI uri) {
String path = uri.getPath();
- if
(fileSystem==
null)
+ if
(fileSystem ==
null)
try {
newFileSystem(uri, new HashMap<String, Object>());
} catch (IOException e) {
try {
newFileSystem(uri, new HashMap<String, Object>());
} catch (IOException e) {
- throw new JcrFsException("Could not autocreate file system",e);
+ throw new JcrFsException("Could not autocreate file system",
e);
}
return fileSystem.getPath(path);
}
}
return fileSystem.getPath(path);
}
diff --git
a/org.argeo.jcr/src/org/argeo/jcr/fs/BinaryChannel.java
b/org.argeo.jcr/src/org/argeo/jcr/fs/BinaryChannel.java
index 2039f778a7a67231eab5eab4b1fd757d19044445..9213b729dd50cad6ef97e4e0230b50e337821e7b 100644
(file)
--- a/
org.argeo.jcr/src/org/argeo/jcr/fs/BinaryChannel.java
+++ b/
org.argeo.jcr/src/org/argeo/jcr/fs/BinaryChannel.java
@@
-74,7
+74,7
@@
public class BinaryChannel implements SeekableByteChannel {
session.save();
open = false;
} catch (RepositoryException e) {
session.save();
open = false;
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot close " + file, e);
+ throw new
IO
Exception("Cannot close " + file, e);
} finally {
JcrUtils.closeQuietly(newBinary);
// IOUtils.closeQuietly(fc);
} finally {
JcrUtils.closeQuietly(newBinary);
// IOUtils.closeQuietly(fc);
@@
-114,7
+114,7
@@
public class BinaryChannel implements SeekableByteChannel {
position = position + read;
return read;
} catch (RepositoryException e) {
position = position + read;
return read;
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot read into buffer", e);
+ throw new
IO
Exception("Cannot read into buffer", e);
}
}
}
}
}
}
@@
-160,7
+160,7
@@
public class BinaryChannel implements SeekableByteChannel {
try {
return binary.getSize();
} catch (RepositoryException e) {
try {
return binary.getSize();
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot get size", e);
+ throw new
IO
Exception("Cannot get size", e);
}
}
}
}
}
}
@@
-186,7
+186,7
@@
public class BinaryChannel implements SeekableByteChannel {
}
return fc;
} catch (RepositoryException e) {
}
return fc;
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot get temp file channel", e);
+ throw new
IO
Exception("Cannot get temp file channel", e);
}
}
}
}
diff --git
a/org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java
b/org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java
index 88fdb207e578cfad4ab1add8aff21c3ee0c84395..d11f0c51d6bea7896c6d9fa8fa85052aca9bc2bc 100644
(file)
--- a/
org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java
+++ b/
org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystem.java
@@
-22,7
+22,7
@@
public class JcrFileSystem extends FileSystem {
private final Session session;
private String userHomePath = null;
private final Session session;
private String userHomePath = null;
- public JcrFileSystem(JcrFileSystemProvider provider, Session session) {
+ public JcrFileSystem(JcrFileSystemProvider provider, Session session)
throws IOException
{
super();
this.provider = provider;
this.session = session;
super();
this.provider = provider;
this.session = session;
@@
-31,7
+31,7
@@
public class JcrFileSystem extends FileSystem {
try {
userHomePath = userHome.getPath();
} catch (RepositoryException e) {
try {
userHomePath = userHome.getPath();
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot retrieve user home path", e);
+ throw new
IO
Exception("Cannot retrieve user home path", e);
}
}
}
}
diff --git
a/org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java
b/org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java
index 1e2864d248a8b9d998a34f874a773710f7a63ca0..5e3e8ca213041e7652fdf4c826e7b7c8d9882593 100644
(file)
--- a/
org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java
+++ b/
org.argeo.jcr/src/org/argeo/jcr/fs/JcrFileSystemProvider.java
@@
-42,10
+42,10
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
if (node == null) {
Node parent = toNode(path.getParent());
if (parent == null)
if (node == null) {
Node parent = toNode(path.getParent());
if (parent == null)
- throw new
JcrFs
Exception("No parent directory for " + path);
+ throw new
IO
Exception("No parent directory for " + path);
if (parent.getPrimaryNodeType().isNodeType(NodeType.NT_FILE)
|| parent.getPrimaryNodeType().isNodeType(NodeType.NT_LINKED_FILE))
if (parent.getPrimaryNodeType().isNodeType(NodeType.NT_FILE)
|| parent.getPrimaryNodeType().isNodeType(NodeType.NT_LINKED_FILE))
- throw new
JcrFs
Exception(path + " parent is a file");
+ throw new
IO
Exception(path + " parent is a file");
String fileName = path.getFileName().toString();
fileName = Text.escapeIllegalJcrChars(fileName);
String fileName = path.getFileName().toString();
fileName = Text.escapeIllegalJcrChars(fileName);
@@
-57,7
+57,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
throw new UnsupportedOperationException(node + " must be a file");
return new BinaryChannel(node);
} catch (RepositoryException e) {
throw new UnsupportedOperationException(node + " must be a file");
return new BinaryChannel(node);
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot read file", e);
+ throw new
IO
Exception("Cannot read file", e);
}
}
}
}
@@
-67,7
+67,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
Node base = toNode(dir);
return new NodeDirectoryStream((JcrFileSystem) dir.getFileSystem(), base.getNodes(), filter);
} catch (RepositoryException e) {
Node base = toNode(dir);
return new NodeDirectoryStream((JcrFileSystem) dir.getFileSystem(), base.getNodes(), filter);
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot list directory", e);
+ throw new
IO
Exception("Cannot list directory", e);
}
}
}
}
@@
-81,7
+81,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
throw new IOException("Parent of " + dir + " does not exist");
if (parent.getPrimaryNodeType().isNodeType(NodeType.NT_FILE)
|| parent.getPrimaryNodeType().isNodeType(NodeType.NT_LINKED_FILE))
throw new IOException("Parent of " + dir + " does not exist");
if (parent.getPrimaryNodeType().isNodeType(NodeType.NT_FILE)
|| parent.getPrimaryNodeType().isNodeType(NodeType.NT_LINKED_FILE))
- throw new
JcrFs
Exception(dir + " parent is a file");
+ throw new
IO
Exception(dir + " parent is a file");
String fileName = dir.getFileName().toString();
fileName = Text.escapeIllegalJcrChars(fileName);
node = parent.addNode(fileName, NodeType.NT_FOLDER);
String fileName = dir.getFileName().toString();
fileName = Text.escapeIllegalJcrChars(fileName);
node = parent.addNode(fileName, NodeType.NT_FOLDER);
@@
-93,7
+93,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
throw new FileExistsException(dir + " exists and is not a directory");
}
} catch (RepositoryException e) {
throw new FileExistsException(dir + " exists and is not a directory");
}
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot create directory " + dir, e);
+ throw new
IO
Exception("Cannot create directory " + dir, e);
}
}
}
}
@@
-114,7
+114,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
}
session.save();
} catch (RepositoryException e) {
}
session.save();
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot delete " + path, e);
+ throw new
IO
Exception("Cannot delete " + path, e);
}
}
}
}
@@
-127,7
+127,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
JcrUtils.copy(sourceNode, targetNode);
sourceNode.getSession().save();
} catch (RepositoryException e) {
JcrUtils.copy(sourceNode, targetNode);
sourceNode.getSession().save();
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot copy from " + source + " to " + target, e);
+ throw new
IO
Exception("Cannot copy from " + source + " to " + target, e);
}
}
}
}
@@
-139,7
+139,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
session.move(sourceNode.getPath(), target.toString());
session.save();
} catch (RepositoryException e) {
session.move(sourceNode.getPath(), target.toString());
session.save();
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot move from " + source + " to " + target, e);
+ throw new
IO
Exception("Cannot move from " + source + " to " + target, e);
}
}
}
}
@@
-156,7
+156,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
Node node2 = toNode(path2);
return node.isSame(node2);
} catch (RepositoryException e) {
Node node2 = toNode(path2);
return node.isSame(node2);
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot check whether " + path + " and " + path2 + " are same", e);
+ throw new
IO
Exception("Cannot check whether " + path + " and " + path2 + " are same", e);
}
}
}
}
@@
-181,7
+181,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
throw new NoSuchFileException(path + " does not exist");
// TODO check access via JCR api
} catch (RepositoryException e) {
throw new NoSuchFileException(path + " does not exist");
// TODO check access via JCR api
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot delete " + path, e);
+ throw new
IO
Exception("Cannot delete " + path, e);
}
}
}
}
@@
-197,12
+197,12
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
try {
// TODO check if assignable
Node node = toNode(path);
try {
// TODO check if assignable
Node node = toNode(path);
- if
(node==
null) {
- throw new
JcrFsException("JCR node not found for "+
path);
+ if
(node ==
null) {
+ throw new
IOException("JCR node not found for " +
path);
}
return (A) new JcrBasicfileAttributes(node);
} catch (RepositoryException e) {
}
return (A) new JcrBasicfileAttributes(node);
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot read basic attributes of " + path, e);
+ throw new
IO
Exception("Cannot read basic attributes of " + path, e);
}
}
}
}
@@
-242,7
+242,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
}
return res;
} catch (RepositoryException e) {
}
return res;
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot read attributes of " + path, e);
+ throw new
IO
Exception("Cannot read attributes of " + path, e);
}
}
}
}
@@
-259,7
+259,7
@@
public abstract class JcrFileSystemProvider extends FileSystemProvider {
}
node.getSession().save();
} catch (RepositoryException e) {
}
node.getSession().save();
} catch (RepositoryException e) {
- throw new
JcrFs
Exception("Cannot set attribute " + attribute + " on " + path, e);
+ throw new
IO
Exception("Cannot set attribute " + attribute + " on " + path, e);
}
}
}
}