MCPcopy Create free account
hub / github.com/apache/tomcat / doLock

Method doLock

java/org/apache/catalina/servlets/WebdavServlet.java:1408–1822  ·  view source on GitHub ↗

LOCK Method. @param req The Servlet request @param resp The Servlet response @throws ServletException If an error occurs @throws IOException If an IO error occurs

(HttpServletRequest req, HttpServletResponse resp)

Source from the content-addressed store, hash-verified

1406 * @throws IOException If an IO error occurs
1407 */
1408 protected void doLock(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
1409
1410 if (isReadOnly()) {
1411 resp.sendError(WebdavStatus.SC_FORBIDDEN);
1412 return;
1413 }
1414
1415 String path = getRelativePath(req);
1416
1417 WebResource resource = resources.getResource(path);
1418 if (!checkIfHeaders(req, resp, resource)) {
1419 resp.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
1420 return;
1421 }
1422
1423 LockInfo lock = new LockInfo(maxDepth);
1424 lock.principal = req.getRemoteUser();
1425
1426 // Parsing lock request
1427
1428 // Parsing depth header
1429
1430 String depthStr = req.getHeader("Depth");
1431
1432 if (depthStr == null) {
1433 lock.depth = maxDepth;
1434 } else {
1435 if (depthStr.equals("0")) {
1436 lock.depth = 0;
1437 } else if (depthStr.equals("infinity")) {
1438 lock.depth = maxDepth;
1439 } else {
1440 resp.sendError(WebdavStatus.SC_BAD_REQUEST);
1441 return;
1442 }
1443 }
1444
1445 // Parsing timeout header (RFC 4918: comma-separated list, pick first acceptable)
1446
1447 int lockDuration = DEFAULT_TIMEOUT;
1448 String lockDurationStr = req.getHeader("Timeout");
1449 if (lockDurationStr != null) {
1450 String[] timeoutValues = lockDurationStr.split(",");
1451 for (String tv : timeoutValues) {
1452 tv = tv.trim();
1453 if (tv.startsWith("Second-")) {
1454 try {
1455 int value = Integer.parseInt(tv.substring("Second-".length()));
1456 if (value > 0) {
1457 lockDuration = value;
1458 break;
1459 }
1460 } catch (NumberFormatException e) {
1461 // Try the next value if any
1462 }
1463 } else if (tv.equals("Infinite")) {
1464 lockDuration = MAX_TIMEOUT;
1465 break;

Callers 1

serviceMethod · 0.95

Calls 15

getRelativePathMethod · 0.95
checkIfHeadersMethod · 0.95
readRequestBodyMethod · 0.95
getDocumentBuilderMethod · 0.95
getDAVNodeMethod · 0.95
printMethod · 0.95
hasExpiredMethod · 0.95
isExclusiveMethod · 0.95
isDirectoryMethod · 0.95
writeXMLHeaderMethod · 0.95
writeElementMethod · 0.95
writeTextMethod · 0.95

Tested by

no test coverage detected