You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2012/01/24 18:47:44 UTC
svn commit: r1235375 - in /jackrabbit/trunk:
jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/
jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/
jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/
Author: reschke
Date: Tue Jan 24 17:47:44 2012
New Revision: 1235375
URL: http://svn.apache.org/viewvc?rev=1235375&view=rev
Log:
JCR-3214: fix weird representation of infinite locks in the WebDAV timeout element
Added:
jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/LockTimeOutFormatTest.java (with props)
Modified:
jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/JcrActiveLock.java
jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java
Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/JcrActiveLock.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/JcrActiveLock.java?rev=1235375&r1=1235374&r2=1235375&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/JcrActiveLock.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/lock/JcrActiveLock.java Tue Jan 24 17:47:44 2012
@@ -121,15 +121,27 @@ public class JcrActiveLock extends Abstr
* Calculates the milliseconds of the timeout from
* {@link javax.jcr.lock.Lock#getSecondsRemaining()}. If the timeout of
* jcr lock is undefined or infinite {@link #INFINITE_TIMEOUT} is
- * returned. A missing timeout causes problems with Microsoft clients.
+ * returned.
*
- * @return Always returns {@link #INFINITE_TIMEOUT}
* @see ActiveLock#getTimeout()
*/
public long getTimeout() {
try {
long to = lock.getSecondsRemaining();
- return (to == Long.MAX_VALUE) ? INFINITE_TIMEOUT : to*1000;
+ long reportAs;
+
+ if (to == Long.MAX_VALUE) {
+ reportAs = INFINITE_TIMEOUT;
+ }
+ else if (to / 1000 <= Long.MAX_VALUE / 1000) {
+ // expressible as long?
+ reportAs = to * 1000;
+ }
+ else {
+ reportAs = INFINITE_TIMEOUT;
+ }
+
+ return reportAs;
} catch (RepositoryException e) {
return INFINITE_TIMEOUT;
}
Added: jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/LockTimeOutFormatTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/LockTimeOutFormatTest.java?rev=1235375&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/LockTimeOutFormatTest.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/LockTimeOutFormatTest.java Tue Jan 24 17:47:44 2012
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.webdav.jcr;
+
+import java.net.URISyntaxException;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
+import javax.xml.parsers.ParserConfigurationException;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * <code>LockTimeOutFormatTest</code>...
+ */
+public class LockTimeOutFormatTest extends TestCase {
+
+ public void testOneSec() throws RepositoryException, URISyntaxException, ParserConfigurationException {
+ testfmt(1, "Second-1");
+ }
+
+ public void testInf() throws RepositoryException, URISyntaxException, ParserConfigurationException {
+ testfmt(Long.MAX_VALUE, "Infinite");
+ }
+
+ public void testTooLong() throws RepositoryException, URISyntaxException, ParserConfigurationException {
+ testfmt(Integer.MAX_VALUE + 100000L, "Infinite");
+ }
+
+ public void testNeg() throws RepositoryException, URISyntaxException, ParserConfigurationException {
+ // expired
+ testfmt(-1, null);
+ }
+
+ private void testfmt(long jcrtimeout, String expectedString) throws RepositoryException, URISyntaxException, ParserConfigurationException {
+
+ Lock l = new TestLock(jcrtimeout);
+ JcrActiveLock al = new JcrActiveLock(l);
+
+ Document d = DomUtil.createDocument();
+ Element activeLock = al.toXml(d);
+ assertEquals("activelock", activeLock.getLocalName());
+ NodeList nl = activeLock.getElementsByTagNameNS("DAV:", "timeout");
+
+ if (expectedString == null) {
+ assertEquals(0, nl.getLength());
+ }
+ else {
+ assertEquals(1, nl.getLength());
+ Element timeout = (Element)nl.item(0);
+ String t = DomUtil.getText(timeout);
+ assertEquals(expectedString, t);
+ }
+ }
+
+ /**
+ * Minimal Lock impl for tests above
+ */
+ private static class TestLock implements Lock {
+
+ private final long timeout;
+
+ public TestLock(long timeout) {
+ this.timeout = timeout;
+ }
+
+ public String getLockOwner() {
+ return null;
+ }
+
+ public boolean isDeep() {
+ return false;
+ }
+
+ public Node getNode() {
+ return null;
+ }
+
+ public String getLockToken() {
+ return "foo";
+ }
+
+ public long getSecondsRemaining() throws RepositoryException {
+ return timeout;
+ }
+
+ public boolean isLive() throws RepositoryException {
+ return timeout >= 0;
+ }
+
+ public boolean isSessionScoped() {
+ return false;
+ }
+
+ public boolean isLockOwningSession() {
+ return false;
+ }
+
+ public void refresh() throws LockException, RepositoryException {
+ }
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/LockTimeOutFormatTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java?rev=1235375&r1=1235374&r2=1235375&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java (original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DomUtil.java Tue Jan 24 17:47:44 2012
@@ -685,17 +685,14 @@ public class DomUtil {
/**
* Converts the given timeout (long value defining the number of milli-
* second until timeout is reached) to its Xml representation as defined
- * by RTF 2518.<br>
- * Note, that {@link DavConstants#INFINITE_TIMEOUT} is not represented by the String
- * {@link DavConstants#TIMEOUT_INFINITE 'Infinite'} defined by RFC 2518, due to a known
- * issue with Microsoft Office that opens the document "read only" and
- * never unlocks the resource if the timeout is missing or 'Infinite'.
+ * by RFC 4918.<br>
*
* @param timeout number of milli-seconds until timeout is reached.
* @return 'timeout' Xml element
*/
public static Element timeoutToXml(long timeout, Document factory) {
- String expString = "Second-"+ timeout/1000;
+ boolean infinite = timeout / 1000 > Integer.MAX_VALUE || timeout == DavConstants.INFINITE_TIMEOUT;
+ String expString = infinite ? DavConstants.TIMEOUT_INFINITE : "Second-" + timeout / 1000;
return createElement(factory, DavConstants.XML_TIMEOUT, DavConstants.NAMESPACE, expString);
}