use of org.apache.jackrabbit.webdav.lock.LockDiscovery in project nuxeo-filesystem-connectors by nuxeo.
the class WebDavClientTest method testPropFindOnLockedFile.
@Test
public void testPropFindOnLockedFile() throws Exception {
String fileUri = ROOT_URI + "quality.jpg";
HttpLock request = new HttpLock(fileUri, new LockInfo(Scope.EXCLUSIVE, Type.WRITE, USERNAME, 10000L, false));
try (CloseableHttpResponse response = client.execute(request, context)) {
request.checkSuccess(response);
}
HttpPropfind request2 = new HttpPropfind(fileUri, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1);
try (CloseableHttpResponse response = client.execute(request2, context)) {
MultiStatus multiStatus = request2.getResponseBodyAsMultiStatus(response);
MultiStatusResponse[] responses = multiStatus.getResponses();
assertEquals(1L, responses.length);
MultiStatusResponse resp = responses[0];
DavProperty<?> pLockDiscovery = resp.getProperties(200).get(DavConstants.PROPERTY_LOCKDISCOVERY);
Element eLockDiscovery = (Element) ((Element) pLockDiscovery.getValue()).getParentNode();
LockDiscovery lockDiscovery = LockDiscovery.createFromXml(eLockDiscovery);
assertEquals(USERNAME, lockDiscovery.getValue().get(0).getOwner());
}
}
use of org.apache.jackrabbit.webdav.lock.LockDiscovery in project jackrabbit by apache.
the class DavResourceImpl method initProperties.
/**
* Fill the set of properties
*/
protected void initProperties() {
if (!exists() || propsInitialized) {
return;
}
try {
config.getPropertyManager().exportProperties(getPropertyExportContext(), isCollection());
} catch (RepositoryException e) {
log.warn("Error while accessing resource properties", e);
}
// set (or reset) fundamental properties
if (getDisplayName() != null) {
properties.add(new DefaultDavProperty<String>(DavPropertyName.DISPLAYNAME, getDisplayName()));
}
if (isCollection()) {
properties.add(new ResourceType(ResourceType.COLLECTION));
// Windows XP support
properties.add(new DefaultDavProperty<String>(DavPropertyName.ISCOLLECTION, "1"));
} else {
properties.add(new ResourceType(ResourceType.DEFAULT_RESOURCE));
// Windows XP support
properties.add(new DefaultDavProperty<String>(DavPropertyName.ISCOLLECTION, "0"));
}
if (rfc4122Uri != null) {
properties.add(new HrefProperty(BindConstants.RESOURCEID, rfc4122Uri, true));
}
Set<ParentElement> parentElements = getParentElements();
if (!parentElements.isEmpty()) {
properties.add(new ParentSet(parentElements));
}
/* set current lock information. If no lock is set to this resource,
an empty lock discovery will be returned in the response. */
properties.add(new LockDiscovery(getLock(Type.WRITE, Scope.EXCLUSIVE)));
/* lock support information: all locks are lockable. */
SupportedLock supportedLock = new SupportedLock();
supportedLock.addEntry(Type.WRITE, Scope.EXCLUSIVE);
properties.add(supportedLock);
propsInitialized = true;
}
use of org.apache.jackrabbit.webdav.lock.LockDiscovery in project jackrabbit by apache.
the class AbstractWebdavServlet method doLock.
/**
* The LOCK method
*
* @param request
* @param response
* @param resource
* @throws IOException
* @throws DavException
*/
protected void doLock(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
LockInfo lockInfo = request.getLockInfo();
if (lockInfo.isRefreshLock()) {
// refresh any matching existing locks
ActiveLock[] activeLocks = resource.getLocks();
List<ActiveLock> lList = new ArrayList<ActiveLock>();
for (ActiveLock activeLock : activeLocks) {
// adjust lockinfo with type/scope retrieved from the lock.
lockInfo.setType(activeLock.getType());
lockInfo.setScope(activeLock.getScope());
DavProperty<?> etagProp = resource.getProperty(DavPropertyName.GETETAG);
String etag = etagProp != null ? String.valueOf(etagProp.getValue()) : "";
if (request.matchesIfHeader(resource.getHref(), activeLock.getToken(), etag)) {
lList.add(resource.refreshLock(lockInfo, activeLock.getToken()));
}
}
if (lList.isEmpty()) {
throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
}
ActiveLock[] refreshedLocks = lList.toArray(new ActiveLock[lList.size()]);
response.sendRefreshLockResponse(refreshedLocks);
} else {
int status = HttpServletResponse.SC_OK;
if (!resource.exists()) {
// lock-empty requires status code 201 (Created)
status = HttpServletResponse.SC_CREATED;
}
// create a new lock
ActiveLock lock = resource.lock(lockInfo);
CodedUrlHeader header = new CodedUrlHeader(DavConstants.HEADER_LOCK_TOKEN, lock.getToken());
response.setHeader(header.getHeaderName(), header.getHeaderValue());
DavPropertySet propSet = new DavPropertySet();
propSet.add(new LockDiscovery(lock));
response.sendXmlResponse(propSet, status);
}
}
use of org.apache.jackrabbit.webdav.lock.LockDiscovery in project jackrabbit by apache.
the class RepositoryServiceImpl method getLockInfo.
@Override
public LockInfo getLockInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
// set of Dav-properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(DavPropertyName.LOCKDISCOVERY);
nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
HttpPropfind request = null;
try {
String uri = getItemUri(nodeId, sessionInfo);
request = new HttpPropfind(uri, nameSet, DEPTH_0);
initMethod(request, sessionInfo, false);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length != 1) {
throw new ItemNotFoundException("Unable to retrieve the LockInfo. No such node " + saveGetIdString(nodeId, sessionInfo));
}
DavPropertySet ps = mresponses[0].getProperties(DavServletResponse.SC_OK);
if (ps.contains(DavPropertyName.LOCKDISCOVERY)) {
DavProperty<?> p = ps.get(DavPropertyName.LOCKDISCOVERY);
LockDiscovery ld = LockDiscovery.createFromXml(p.toXml(DomUtil.createDocument()));
NodeId parentId = getParentId(uri, ps, sessionInfo);
return retrieveLockInfo(ld, sessionInfo, nodeId, parentId);
} else {
// no lock present
log.debug("No Lock present on node with id " + saveGetIdString(nodeId, sessionInfo));
return null;
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (ParserConfigurationException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.webdav.lock.LockDiscovery in project jackrabbit by apache.
the class WebdavResponseImpl method sendRefreshLockResponse.
/**
* Send response body for a lock request that was intended to refresh one
* or several locks.
*
* @param locks
* @throws java.io.IOException
* @see DavServletResponse#sendRefreshLockResponse(org.apache.jackrabbit.webdav.lock.ActiveLock[])
*/
public void sendRefreshLockResponse(ActiveLock[] locks) throws IOException {
DavPropertySet propSet = new DavPropertySet();
propSet.add(new LockDiscovery(locks));
sendXmlResponse(propSet, SC_OK);
}
Aggregations