jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r656685 - in /jackrabbit/trunk/jackrabbit-webdav: ./ src/main/java/org/apache/jackrabbit/webdav/client/methods/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/jackrabbit/ src/test/java/org/apa...
Date Thu, 15 May 2008 14:44:28 GMT
Author: angela
Date: Thu May 15 07:44:27 2008
New Revision: 656685

URL: http://svn.apache.org/viewvc?rev=656685&view=rev
Log:
JCR-1571: DavMethodBase#getResponseException fails if the body is not (valid) XML

Added:
    jackrabbit/trunk/jackrabbit-webdav/src/test/
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/client/
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/client/methods/
    jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/client/methods/DavMethodTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-webdav/src/test/resources/
    jackrabbit/trunk/jackrabbit-webdav/src/test/resources/log4j.properties   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-webdav/pom.xml
    jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java

Modified: jackrabbit/trunk/jackrabbit-webdav/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/pom.xml?rev=656685&r1=656684&r2=656685&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-webdav/pom.xml Thu May 15 07:44:27 2008
@@ -54,6 +54,18 @@
         </includes>
       </resource>
     </resources>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/*Test.java</include>
+          </includes>
+          <forkMode>once</forkMode>
+          <argLine>-Xmx128m -enableassertions</argLine>
+        </configuration>
+      </plugin>
+    </plugins>
   </build>
 
   <dependencies>

Modified: jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java?rev=656685&r1=656684&r2=656685&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java
(original)
+++ jackrabbit/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java
Thu May 15 07:44:27 2008
@@ -34,6 +34,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -55,7 +56,7 @@
     private MultiStatus multiStatus;
 
     public DavMethodBase(String uri) {
-	super(uri);
+        super(uri);
     }
 
     //---------------------------------------------------------< HttpMethod >---
@@ -107,14 +108,14 @@
         if (responseDocument != null) {
             // response has already been read
             return responseDocument;
-        } else {
+        }
+
+        InputStream in = getResponseBodyAsStream();
+        if (in != null) {
             // read response and try to build a xml document
-            InputStream in = getResponseBodyAsStream();
-            if (in == null) {
-                return null;
-            }
             try {
                 DocumentBuilder docBuilder = BUILDER_FACTORY.newDocumentBuilder();
+                docBuilder.setErrorHandler(new DefaultHandler());
                 responseDocument = docBuilder.parse(in);
                 return responseDocument;
             } catch (ParserConfigurationException e) {
@@ -125,6 +126,8 @@
                 in.close();
             }
         }
+        // no body or no parseable.
+        return null;
     }
 
     /**
@@ -144,14 +147,19 @@
      * @see DavMethod#getResponseException()
      */
     public DavException getResponseException() throws IOException {
-	checkUsed();
-	if (success) {
+        checkUsed();
+        if (success) {
             String msg = "Cannot retrieve exception from successful response.";
-	    log.warn(msg);
-	    throw new IllegalStateException(msg);
-	}
+            log.warn(msg);
+            throw new IllegalStateException(msg);
+        }
 
-        Element responseRoot = getRootElement();
+        Element responseRoot = null;
+        try  {
+            responseRoot = getRootElement();
+        } catch (IOException e) {
+            // unparsable body -> use null element
+        }
         if (responseRoot != null) {
             return new DavException(getStatusCode(), getStatusText(), null, responseRoot);
         } else {
@@ -205,7 +213,8 @@
     /**
      *
      * @param statusCode
-     * @return
+     * @return true if the specified status code corresponds to a successfully
+     * completed request.
      */
     abstract protected boolean isSuccess(int statusCode);
 
@@ -218,8 +227,7 @@
     }
 
     /**
-     *
-     * @return
+     * @return true if this method was successfully executed; false otherwise.
      */
     protected boolean getSuccess() {
         return success;

Added: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/client/methods/DavMethodTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/client/methods/DavMethodTest.java?rev=656685&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/client/methods/DavMethodTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/client/methods/DavMethodTest.java
Thu May 15 07:44:27 2008
@@ -0,0 +1,78 @@
+/*
+ * 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.client.methods;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.webdav.DavException;
+import org.w3c.dom.Document;
+import junit.framework.TestCase;
+
+import java.io.IOException;
+
+/** <code>DavMethodTest</code>... */
+public class DavMethodTest extends TestCase {
+
+    private static Logger log = LoggerFactory.getLogger(DavMethodTest.class);
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testGetReponseException() throws IOException {
+        DavMethod m = new TestDavMethod();
+        DavException e = m.getResponseException();
+
+        assertFalse(e.hasErrorCondition());
+    }
+
+
+    private class TestDavMethod extends DavMethodBase {
+        private TestDavMethod() {
+            super("test");
+        }
+        public String getName() {
+            return "test";
+        }
+        public int getStatusCode() {
+            return 404;
+        }
+        public String getStatusText() {
+            return "404";
+        }
+        public Document getResponseBodyAsDocument() throws IOException {
+            throw new IOException();
+        }
+        public void checkSuccess() throws DavException, IOException {
+            throw new DavException(404);
+        }
+        public boolean succeeded() {
+            return false;
+        }
+        protected void checkUsed() {}
+        protected boolean isSuccess(int statusCode) {
+            return false;
+        }
+        protected boolean getSuccess() {
+            return false;
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/client/methods/DavMethodTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-webdav/src/test/java/org/apache/jackrabbit/webdav/client/methods/DavMethodTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-webdav/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webdav/src/test/resources/log4j.properties?rev=656685&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-webdav/src/test/resources/log4j.properties (added)
+++ jackrabbit/trunk/jackrabbit-webdav/src/test/resources/log4j.properties Thu May 15 07:44:27
2008
@@ -0,0 +1,34 @@
+#  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.
+
+# Set root logger level to INFO and its only appender to file.
+log4j.rootLogger=INFO, file
+#log4j.rootLogger=DEBUG, stdout, file
+#log4j.rootLogger=ERROR, stdout, file
+
+# 'stdout' is set to be a ConsoleAppender.
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+
+# 'stdout' uses PatternLayout
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}:
%m (%F, line %L)\n
+
+# 'file' is set to be a FileAppender.
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.File=target/jcr.log
+
+# 'file' uses PatternLayout.
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m
(%F, line %L)\n

Propchange: jackrabbit/trunk/jackrabbit-webdav/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn = 

Propchange: jackrabbit/trunk/jackrabbit-webdav/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message