use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class XATest method testAddNodeCommit.
/**
* Add a node inside a transaction and commit changes. Make sure
* node exists for other sessions only after commit.
* @throws Exception
*/
public void testAddNodeCommit() throws Exception {
// get user transaction object
UserTransaction utx = new UserTransactionImpl(superuser);
// start transaction
utx.begin();
// add node and save
Node n = testRootNode.addNode(nodeName1, testNodeType);
n.addMixin(mixReferenceable);
testRootNode.save();
// assertion: node exists in this session
try {
superuser.getNodeByUUID(n.getUUID());
} catch (ItemNotFoundException e) {
fail("New node not visible after save()");
}
// assertion: node does not exist in other session
Session otherSuperuser = getHelper().getSuperuserSession();
try {
otherSuperuser.getNodeByUUID(n.getUUID());
fail("Uncommitted node visible for other session");
} catch (ItemNotFoundException e) {
/* expected */
}
// commit
utx.commit();
// assertion: node exists in this session
try {
superuser.getNodeByUUID(n.getUUID());
} catch (ItemNotFoundException e) {
fail("Committed node not visible in this session");
}
// assertion: node also exists in other session
try {
otherSuperuser.getNodeByUUID(n.getUUID());
} catch (ItemNotFoundException e) {
fail("Committed node not visible in other session");
}
// logout
otherSuperuser.logout();
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class XATest method testDistributedThreadAccess.
/**
* Tests two different Threads for prepare and commit in a Transaction
*/
public void testDistributedThreadAccess() throws Exception {
// get user transaction object
UserTransaction utx = new UserTransactionImpl(superuser, true);
//utx.setTransactionTimeout(50);
// start transaction
utx.begin();
// add node and save
Node n = testRootNode.addNode(nodeName1, testNodeType);
n.addMixin(mixReferenceable);
testRootNode.save();
// assertion: node exists in this session
try {
superuser.getNodeByUUID(n.getUUID());
} catch (ItemNotFoundException e) {
fail("New node not visible after save()");
}
// commit
utx.commit();
// assertion: node exists in this session
try {
superuser.getNodeByUUID(n.getUUID());
} catch (ItemNotFoundException e) {
fail("Committed node not visible in this session");
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class JcrRemotingServlet method doGet.
@Override
protected void doGet(WebdavRequest webdavRequest, WebdavResponse webdavResponse, DavResource davResource) throws IOException, DavException {
if (canHandle(DavMethods.DAV_GET, webdavRequest, davResource)) {
// return json representation of the requested resource
DavResourceLocator locator = davResource.getLocator();
String path = locator.getRepositoryPath();
Session session = getRepositorySession(webdavRequest);
try {
Node node = session.getNode(path);
int depth = ((WrappingLocator) locator).getDepth();
webdavResponse.setContentType("text/plain;charset=utf-8");
webdavResponse.setStatus(DavServletResponse.SC_OK);
JsonWriter writer = new JsonWriter(webdavResponse.getWriter());
String[] includes = webdavRequest.getParameterValues(PARAM_INCLUDE);
if (includes == null) {
if (depth < BatchReadConfig.DEPTH_INFINITE) {
NodeType type = node.getPrimaryNodeType();
depth = brConfig.getDepth(type.getName());
}
writer.write(node, depth);
} else {
writeMultiple(writer, node, includes, depth);
}
} catch (PathNotFoundException e) {
// properties cannot be requested as json object.
throw new JcrDavException(new ItemNotFoundException("No node at " + path), DavServletResponse.SC_NOT_FOUND);
} catch (RepositoryException e) {
// should only get here if the item does not exist.
log.debug(e.getMessage());
throw new JcrDavException(e);
}
} else {
super.doGet(webdavRequest, webdavResponse, davResource);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit-oak by apache.
the class NodeDelegate method unlock.
public void unlock() throws RepositoryException {
String path = getPath();
Root root = sessionDelegate.getContentSession().getLatestRoot();
Tree tree = root.getTree(path);
if (!tree.exists()) {
throw new ItemNotFoundException("Node " + path + " does not exist");
} else if (!isNodeType(tree, MIX_LOCKABLE, root)) {
throw new LockException("Node " + path + " is not lockable");
} else if (!tree.hasProperty(JCR_LOCKISDEEP)) {
throw new LockException("Node " + path + " is not locked");
}
try {
tree.removeProperty(JCR_LOCKISDEEP);
tree.removeProperty(JCR_LOCKOWNER);
sessionDelegate.commit(root);
} catch (CommitFailedException e) {
if (e.isAccessViolation()) {
throw new AccessControlException("Access denied to unlock node " + path, e);
} else {
throw new RepositoryException("Unable to unlock node " + path, e);
}
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit-oak by apache.
the class NodeDelegate method lock.
public void lock(boolean isDeep) throws RepositoryException {
String path = getPath();
Root root = sessionDelegate.getContentSession().getLatestRoot();
Tree tree = root.getTree(path);
if (!tree.exists()) {
throw new ItemNotFoundException("Node " + path + " does not exist");
} else if (!isNodeType(tree, MIX_LOCKABLE, root)) {
throw new LockException("Node " + path + " is not lockable");
} else if (tree.hasProperty(JCR_LOCKISDEEP)) {
throw new LockException("Node " + path + " is already locked");
}
// look for locked ancestor
Tree inheritedLock = findLock(tree, true);
if (inheritedLock != null) {
throw new LockException("Node already indirectly locked by " + inheritedLock.getPath());
}
// scan for locked descendant
if (isDeep) {
Tree descendantLock = findDescendantLock(tree);
if (descendantLock != null) {
throw new LockException("Lock conflicts with lock hold by " + descendantLock.getPath());
}
}
try {
String owner = sessionDelegate.getAuthInfo().getUserID();
if (owner == null) {
owner = "";
}
tree.setProperty(JCR_LOCKISDEEP, isDeep);
tree.setProperty(JCR_LOCKOWNER, owner);
sessionDelegate.commit(root);
} catch (CommitFailedException e) {
if (e.isAccessViolation()) {
throw new AccessControlException("Access denied to lock node " + path, e);
} else {
throw new RepositoryException("Unable to lock node " + path, e);
}
}
}
Aggregations