Author: bdelacretaz
Date: Mon Jun 16 05:22:39 2008
New Revision: 668136
URL: http://svn.apache.org/viewvc?rev=668136&view=rev
Log:
SLING-537 - disable WebDAV iohandlers for zip and XML files
Added:
incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavUploadTest.java
(with props)
incubator/sling/trunk/launchpad/webapp/src/test/resources/integration-test/testfile.xml
(with props)
incubator/sling/trunk/launchpad/webapp/src/test/resources/integration-test/testfile.zip
(with props)
Modified:
incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
incubator/sling/trunk/jcr/webdav/src/main/resources/webdav-resource-config.xml
Modified:
incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java?rev=668136&r1=668135&r2=668136&view=diff
==============================================================================
---
incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
(original)
+++
incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
Mon Jun 16 05:22:39 2008
@@ -64,6 +64,9 @@
protected HttpClient httpClient;
private static Boolean slingStartupOk;
+
+ /** Means "don't care about Content-Type" in getContent(...) methods */
+ public static final String CONTENT_TYPE_DONTCARE = "*";
/** URLs stored here are deleted in tearDown */
protected final List<String> urlsToDelete = new LinkedList<String>();
@@ -279,6 +282,7 @@
}
/** retrieve the contents of given URL and assert its content type
+ * @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be
checked
* @throws IOException
* @throws HttpException */
protected String getContent(String url, String expectedContentType,
List<NameValuePair> params) throws IOException {
@@ -295,6 +299,8 @@
if(h!=null) {
fail("Expected null Content-Type, got " + h.getValue());
}
+ } else if(CONTENT_TYPE_DONTCARE.equals(expectedContentType)) {
+ // no check
} else if(h==null) {
fail(
"Expected Content-Type that starts with '" +
expectedContentType
Modified:
incubator/sling/trunk/jcr/webdav/src/main/resources/webdav-resource-config.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/webdav/src/main/resources/webdav-resource-config.xml?rev=668136&r1=668135&r2=668136&view=diff
==============================================================================
---
incubator/sling/trunk/jcr/webdav/src/main/resources/webdav-resource-config.xml
(original)
+++
incubator/sling/trunk/jcr/webdav/src/main/resources/webdav-resource-config.xml
Mon Jun 16 05:22:39 2008
@@ -56,12 +56,6 @@
-->
<class name="org.apache.jackrabbit.server.io.IOManagerImpl" />
<iohandler>
- <class name="org.apache.jackrabbit.server.io.ZipHandler" />
- </iohandler>
- <iohandler>
- <class name="org.apache.jackrabbit.server.io.XmlHandler" />
- </iohandler>
- <iohandler>
<class
name="org.apache.jackrabbit.server.io.DirListingExportHandler" />
</iohandler>
<iohandler>
Added:
incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavUploadTest.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavUploadTest.java?rev=668136&view=auto
==============================================================================
---
incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavUploadTest.java
(added)
+++
incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavUploadTest.java
Mon Jun 16 05:22:39 2008
@@ -0,0 +1,113 @@
+/*
+ * 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.sling.launchpad.webapp.integrationtest;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+
+/** Test WebDAV upload of various file types */
+public class WebdavUploadTest extends HttpTestBase {
+
+ private final String testDir = "/sling-test/" + getClass().getSimpleName()
+ System.currentTimeMillis();
+ private final String testDirUrl = WEBDAV_BASE_URL + testDir;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ testClient.mkdirs(WEBDAV_BASE_URL, testDir);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ testClient.delete(testDirUrl);
+ }
+
+ protected byte [] readStream(InputStream is) throws IOException {
+ if(is == null) {
+ fail("Null InputStream");
+ }
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try {
+ final byte [] buffer = new byte[4096];
+ int n = 0;
+ while( (n = is.read(buffer, 0, buffer.length)) > 0) {
+ bos.write(buffer, 0, n);
+ }
+ } finally {
+ is.close();
+ bos.flush();
+ bos.close();
+ }
+ return bos.toByteArray();
+ }
+
+ protected void compareData(String slingDataUrl, String localResourcePath)
throws IOException {
+
+ // Get Sling content as a binary stream
+ final GetMethod m = new GetMethod(slingDataUrl);
+ final int httpStatus = httpClient.executeMethod(m);
+ assertEquals("GET " + slingDataUrl + " must return status 200", 200,
httpStatus);
+ final byte [] local =
readStream(getClass().getResourceAsStream(localResourcePath));
+ final byte [] remote = readStream(m.getResponseBodyAsStream());
+
+ assertEquals("Local and remote files have the same length",
local.length, remote.length);
+
+ for(int i=0 ; i < local.length; i++) {
+ assertEquals("Content must match at index " + i, local[i],
remote[i]);
+ }
+ }
+
+ protected void uploadAndCheck(String localResourcePath) throws IOException
{
+ final InputStream data =
getClass().getResourceAsStream(localResourcePath);
+ if(data==null) {
+ fail("Local resource not found: " + localResourcePath);
+ }
+
+ try {
+ final String url = testDirUrl + "/" + new
File(localResourcePath).getName();
+ testClient.upload(url, data);
+ compareData(url, localResourcePath);
+ } finally {
+ if(data!=null) {
+ data.close();
+ }
+ }
+
+ }
+
+ public void testTextUpload() throws IOException {
+ uploadAndCheck("/integration-test/testfile.txt");
+ }
+
+ public void testXmlUpload() throws IOException {
+ uploadAndCheck("/integration-test/testfile.xml");
+ }
+
+ public void testZipUpload() throws IOException {
+ uploadAndCheck("/integration-test/testfile.zip");
+ }
+
+ public void testPngUpload() throws IOException {
+ uploadAndCheck("/integration-test/sling-logo.png");
+ }
+}
Propchange:
incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavUploadTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavUploadTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
incubator/sling/trunk/launchpad/webapp/src/test/resources/integration-test/testfile.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/webapp/src/test/resources/integration-test/testfile.xml?rev=668136&view=auto
==============================================================================
---
incubator/sling/trunk/launchpad/webapp/src/test/resources/integration-test/testfile.xml
(added)
+++
incubator/sling/trunk/launchpad/webapp/src/test/resources/integration-test/testfile.xml
Mon Jun 16 05:22:39 2008
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+/*
+ * 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.
+ */
+ -->
+
+<testfile id="42">
+ <some-element>
+ <child-element id="1"/>
+ <child-element id="2"/>
+ </some-element>
+</testfile>
Propchange:
incubator/sling/trunk/launchpad/webapp/src/test/resources/integration-test/testfile.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/sling/trunk/launchpad/webapp/src/test/resources/integration-test/testfile.zip
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/webapp/src/test/resources/integration-test/testfile.zip?rev=668136&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
incubator/sling/trunk/launchpad/webapp/src/test/resources/integration-test/testfile.zip
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream