incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r591291 - in /incubator/sling/trunk/microsling/microsling-core/src: main/java/org/apache/sling/microsling/slingservlets/ test/java/org/apache/sling/microsling/integration/
Date Fri, 02 Nov 2007 10:16:41 GMT
Author: bdelacretaz
Date: Fri Nov  2 03:16:40 2007
New Revision: 591291

URL: http://svn.apache.org/viewvc?rev=591291&view=rev
Log:
SLING-93 - preparing for JSON renderer, DefaultSlingServlet selects renderer based on response
content-type, not extension

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/CreateNodeTest.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.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=591291&r1=591290&r2=591291&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
Fri Nov  2 03:16:40 2007
@@ -54,8 +54,8 @@
     private Map<String, Servlet> renderingServlets = new HashMap <String, Servlet>();
 
     public DefaultSlingServlet() {
-        renderingServlets.put("txt", new PlainTextRendererServlet());
-        renderingServlets.put("html", new DefaultHtmlRendererServlet());
+        renderingServlets.put("text/plain", new PlainTextRendererServlet());
+        renderingServlets.put("text/html", new DefaultHtmlRendererServlet());
     }
 
     @Override
@@ -83,17 +83,14 @@
         // make sure we have an Item, and render it via one of our renderingServlets
         final Object data = r.getRawData();
         if(data!=null && (data instanceof Item)) {
-            String ext = req.getRequestPathInfo().getExtension();
-            if (ext == null) {
-                ext = "txt";
-            }
-            final Servlet s = renderingServlets.get(ext);
+            final String contentType = req.getResponseContentType();
+            final Servlet s = renderingServlets.get(contentType);
             if(s!=null) {
                 s.service(req, resp);
             } else {
                 throw new HttpStatusCodeException(
                         HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
-                        "No default renderer found for extension='" + ext + "'"
+                        "No default renderer found for Content-Type='" + contentType + "'"
                         + ", use one of these extensions: " + renderingServlets.keySet()
                 );
             }

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java?rev=591291&r1=591290&r2=591291&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
Fri Nov  2 03:16:40 2007
@@ -53,6 +53,12 @@
         getContent(urlOfNewNode, "text/plain");
         getContent(urlOfNewNode + ".txt", "text/plain");
         getContent(urlOfNewNode + ".html", "text/html");
-        assertHttpStatus(urlOfNewNode + ".noRendererForThisExtension", 500);
+        
+        // funny extensions are rendered as text/plain
+        getContent(urlOfNewNode + ".someWeirdExtension", "text/plain");
+        
+        // but well-known extensions for which we have no renderer fail
+        assertHttpStatus(urlOfNewNode + ".xml", 500);
+        assertHttpStatus(urlOfNewNode + ".pdf", 500);
     }
 }

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java?rev=591291&r1=591290&r2=591291&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
Fri Nov  2 03:16:40 2007
@@ -33,8 +33,8 @@
         // set test values
         testText = "This is a test " + System.currentTimeMillis();
         
-        // create the test node
-        final String url = HTTP_BASE_URL + TEST_PATH + ".sling";
+        // create the test node, under a path that's specific to this class to allow collisions
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "." + System.currentTimeMillis()
+ ".sling";
         final Map<String,String> props = new HashMap<String,String>();
         props.put("text", testText);
         displayUrl = testClient.createNode(url, props);

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java?rev=591291&r1=591290&r2=591291&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
Fri Nov  2 03:16:40 2007
@@ -36,8 +36,8 @@
         slingResourceType = "integration-test/srt." + System.currentTimeMillis();
         testText = "This is a test " + System.currentTimeMillis();
         
-        // create the test node
-        final String url = HTTP_BASE_URL + TEST_PATH + ".sling";
+        // create the test node, under a path that's specific to this class to allow collisions
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "." + System.currentTimeMillis()
+ ".sling";
         final Map<String,String> props = new HashMap<String,String>();
         props.put("slingResourceType", slingResourceType);
         props.put("text", testText);



Mime
View raw message