use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class NodeSetPrimaryTypeTest method testLocked.
/**
* Tests if <code>Node.setPrimaryType(String)</code> throws a
* <code>LockException</code> if <code>Node</code> is locked.
*/
public void testLocked() throws NotExecutableException, RepositoryException {
Session session = testRootNode.getSession();
if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
throw new NotExecutableException("Locking is not supported.");
}
// create a node that is lockable
Node node = testRootNode.addNode(nodeName1, testNodeType);
// or try to make it lockable if it is not
ensureMixinType(node, mixLockable);
testRootNode.getSession().save();
String primaryTypeName = getPrimaryTypeName(session, node);
if (primaryTypeName == null) {
throw new NotExecutableException("No testable node type found");
}
// remove first slash of path to get rel path to root
String pathRelToRoot = node.getPath().substring(1);
// access node through another session to lock it
Session session2 = getHelper().getSuperuserSession();
try {
Node node2 = session2.getRootNode().getNode(pathRelToRoot);
node2.lock(true, true);
try {
// implementation specific: either throw LockException upon
// addMixin or upon save.
node.setPrimaryType(primaryTypeName);
node.save();
fail("Node.setPrimaryType(String) must throw a LockException if the node is locked.");
} catch (LockException e) {
// success
}
// unlock to remove node at tearDown()
node2.unlock();
} finally {
session2.logout();
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class ExceptionConverter method generate.
public static RepositoryException generate(DavException davExc, int methodCode, String name) {
String msg = davExc.getMessage();
if (davExc.hasErrorCondition()) {
try {
Element error = davExc.toXml(DomUtil.createDocument());
if (DomUtil.matches(error, DavException.XML_ERROR, DavConstants.NAMESPACE)) {
if (DomUtil.hasChildElement(error, "exception", null)) {
Element exc = DomUtil.getChildElement(error, "exception", null);
if (DomUtil.hasChildElement(exc, "message", null)) {
msg = DomUtil.getChildText(exc, "message", null);
}
if (DomUtil.hasChildElement(exc, "class", null)) {
Class<?> cl = Class.forName(DomUtil.getChildText(exc, "class", null));
Constructor<?> excConstr = cl.getConstructor(String.class);
if (excConstr != null) {
Object o = excConstr.newInstance(msg);
if (o instanceof PathNotFoundException && methodCode == DavMethods.DAV_POST) {
// see JCR-2536
return new InvalidItemStateException(msg);
} else if (o instanceof RepositoryException) {
return (RepositoryException) o;
} else if (o instanceof Exception) {
return new RepositoryException(msg, (Exception) o);
}
}
}
}
}
} catch (Exception e) {
return new RepositoryException(e);
}
}
// make sure an exception is generated
switch(davExc.getErrorCode()) {
// TODO: mapping DAV_error to jcr-exception is ambiguous. to be improved
case DavServletResponse.SC_NOT_FOUND:
switch(methodCode) {
case DavMethods.DAV_DELETE:
case DavMethods.DAV_MKCOL:
case DavMethods.DAV_PUT:
case DavMethods.DAV_POST:
// been made.
return new InvalidItemStateException(msg, davExc);
default:
return new ItemNotFoundException(msg, davExc);
}
case DavServletResponse.SC_LOCKED:
return new LockException(msg, davExc);
case DavServletResponse.SC_METHOD_NOT_ALLOWED:
return new ConstraintViolationException(msg, davExc);
case DavServletResponse.SC_CONFLICT:
return new InvalidItemStateException(msg, davExc);
case DavServletResponse.SC_PRECONDITION_FAILED:
return new LockException(msg, davExc);
case DavServletResponse.SC_NOT_IMPLEMENTED:
if (methodCode > 0 && name != null) {
return new UnsupportedRepositoryOperationException("Missing implementation: Method " + name + " could not be executed", davExc);
} else {
return new UnsupportedRepositoryOperationException("Missing implementation", davExc);
}
default:
return new RepositoryException(msg, davExc);
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class LockedWrapperTest method testTimeout.
public void testTimeout() throws RepositoryException, InterruptedException {
final Node lockable = testRootNode.addNode("testTimeout" + System.currentTimeMillis());
lockable.addMixin(mixLockable);
superuser.save();
ExecutorService e = Executors.newFixedThreadPool(2);
Future<?> lockMaster = e.submit(buildNewTimeoutCallable(lockable.getPath(), true));
Future<?> lockSlave = e.submit(buildNewTimeoutCallable(lockable.getPath(), false));
e.shutdown();
try {
lockMaster.get();
lockSlave.get();
} catch (ExecutionException ex) {
if (ex.getCause().getClass().isAssignableFrom(LockException.class)) {
return;
}
fail(ex.getMessage());
}
fail("was expecting a LockException");
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class VersionTest method testLockJcr2.
/**
* Tests if <code>Version.lock(boolean, boolean)</code> throws a {@link
* LockException}
*/
public void testLockJcr2() throws Exception {
LockManager lockManager = version.getSession().getWorkspace().getLockManager();
String path = version.getPath();
try {
lockManager.lock(path, true, true, 60, "");
fail("Version should not be lockable: Version.lock(true,true) did not throw a LockException");
} catch (LockException success) {
}
try {
lockManager.lock(path, true, false, 60, "");
fail("Version should not be lockable: Version.lock(true,false) did not throw a LockException");
} catch (LockException success) {
}
try {
lockManager.lock(path, false, true, 60, "");
fail("Version should not be lockable: Version.lock(false,true) did not throw a LockException");
} catch (LockException success) {
}
try {
lockManager.lock(path, false, false, 60, "");
fail("Version should not be lockable: Version.lock(false,false) did not throw a LockException");
} catch (LockException success) {
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class RetentionPolicyTest method testSetRetentionPolicyOnLockedNode.
public void testSetRetentionPolicyOnLockedNode() throws NotExecutableException, RepositoryException {
String childPath = getLockedChildNode().getPath();
// get another session.
Session otherS = getHelper().getSuperuserSession();
try {
RetentionManager rmgr = getRetentionManager(otherS);
rmgr.setRetentionPolicy(childPath, getApplicableRetentionPolicy());
otherS.save();
fail("Setting a retention policy on a locked node must throw LockException.");
} catch (LockException e) {
// success
} finally {
otherS.logout();
if (retentionMgr.getRetentionPolicy(childPath) != null) {
retentionMgr.removeRetentionPolicy(childPath);
}
superuser.save();
}
}
Aggregations