incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r598596 - in /incubator/sling/trunk/microsling/microsling-core/src: main/java/org/apache/sling/microsling/slingservlets/ main/webapp/microjax/ test/java/org/apache/sling/microsling/integration/
Date Tue, 27 Nov 2007 11:19:26 GMT
Author: bdelacretaz
Date: Tue Nov 27 03:19:14 2007
New Revision: 598596

URL: http://svn.apache.org/viewvc?rev=598596&view=rev
Log:
SLING-112 - static resources were served with wrong Content-Type

Added:
    incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/
    incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js
  (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StaticContentTest.java
  (with props)
Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java?rev=598596&r1=598595&r2=598596&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
Tue Nov 27 03:19:14 2007
@@ -78,16 +78,18 @@
         if (Resource.RESOURCE_TYPE_NON_EXISTING.equals(r.getResourceType())) {
 
             String path = r.getURI();
-            if (!path.startsWith("/WEB-INF") && !path.startsWith("/META-INF")) {
-                URL url = getServletContext().getResource(path);
-                if (url != null) {
-                    spool(url, resp);
-                    return;
-                }
+            if (path.startsWith("/WEB-INF") || path.startsWith("/META-INF")) {
+                throw new HttpStatusCodeException(HttpServletResponse.SC_FORBIDDEN,
+                        "Access to " + path + " denied");
+            }
+            
+            URL url = getServletContext().getResource(path);
+            if (url != null) {
+                spool(url, resp);
+            } else {
+                throw new HttpStatusCodeException(HttpServletResponse.SC_NOT_FOUND,
+                        "Resource not found: " + r.getURI());
             }
-
-            throw new HttpStatusCodeException(HttpServletResponse.SC_NOT_FOUND,
-                "Resource not found: " + r.getURI());
         }
 
         // make sure we have an Item, and render it via one of our renderingServlets
@@ -134,9 +136,8 @@
     protected void spool(URL url, SlingHttpServletResponse res) throws IOException {
         URLConnection conn = url.openConnection();
 
-        if (conn.getContentType() != null) {
-            res.setContentType(conn.getContentType());
-        }
+        // this previously used conn.getContentType(), but see SLING-112
+        res.setContentType(getServletContext().getMimeType(url.getFile()));
         if (conn.getContentLength() > 0 ) {
             res.setContentLength(conn.getContentLength());
         }

Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js?rev=598596&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js
Tue Nov 27 03:19:14 2007
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+/**
+ * 	The microjax javascript client gives access to a JCR repository
+ *	from client-side java code, using microsling as a back-end.	   
+ *	 
+ * @version $Rev: $, $Date: 2007-03-27 16:30:52 +0200 (Tue, 27 Mar 2007) $
+ */

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microjax/microjax.js
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java?rev=598596&r1=598595&r2=598596&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
Tue Nov 27 03:19:14 2007
@@ -52,6 +52,8 @@
     public static final String CONTENT_TYPE_XML = "text/xml";
     public static final String CONTENT_TYPE_PLAIN = "text/plain";
     public static final String CONTENT_TYPE_JSON = "application/json";
+    public static final String CONTENT_TYPE_JS = "application/x-javascript";
+    public static final String CONTENT_TYPE_CSS = "text/css";
     
     protected MicroslingIntegrationTestClient testClient;
     protected HttpClient httpClient;
@@ -128,7 +130,8 @@
             }
         } else {
             assertTrue(
-                "Expected Content-Type '" + expectedContentType + "' for " + url,
+                "Expected Content-Type that starts with '" + expectedContentType 
+                + "' for " + url + ", got '" + h.getValue() + "'",
                 h.getValue().startsWith(expectedContentType)
             );
         }

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StaticContentTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StaticContentTest.java?rev=598596&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StaticContentTest.java
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StaticContentTest.java
Tue Nov 27 03:19:14 2007
@@ -0,0 +1,48 @@
+/*
+ * 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.microsling.integration;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletResponse;
+
+/** Test static content served from the microsling webapp resources */
+public class StaticContentTest extends MicroslingHttpTestBase {
+    public void testContentTypeHtml() throws IOException {
+        getContent(HTTP_BASE_URL + "/index.html", CONTENT_TYPE_HTML);
+    }
+    
+    public void testContentTypeCss() throws IOException {
+        getContent(HTTP_BASE_URL + "/microsling.css", CONTENT_TYPE_CSS);
+    }
+    
+    public void testContentTypeJs() throws IOException {
+        getContent(HTTP_BASE_URL + "/microjax/microjax.js", CONTENT_TYPE_JS);
+    }
+    
+    public void testWebInfForbidden() throws IOException {
+        // if DefaultSlingServlet handled this we'd get an SC_FORBIDDEN, but it looks
+        // like the servlet container blocks it already
+        assertHttpStatus(HTTP_BASE_URL + "/WEB-INF/web.xml", HttpServletResponse.SC_NOT_FOUND);
+    }
+    
+    public void testMetaInfForbidden() throws IOException {
+        // if DefaultSlingServlet handled this we'd get an SC_FORBIDDEN, but it looks
+        // like the servlet container blocks it already
+        assertHttpStatus(HTTP_BASE_URL + "/META-INF/somefile.txt", HttpServletResponse.SC_NOT_FOUND);
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StaticContentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StaticContentTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message