incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r591318 - in /incubator/sling/trunk/microsling/microsling-core/src: main/java/org/apache/sling/microsling/contenttype/ main/java/org/apache/sling/microsling/helpers/json/ main/java/org/apache/sling/microsling/slingservlets/ main/java/org/ap...
Date Fri, 02 Nov 2007 12:52:44 GMT
Author: bdelacretaz
Date: Fri Nov  2 05:52:41 2007
New Revision: 591318

URL: http://svn.apache.org/viewvc?rev=591318&view=rev
Log:
SLING-93 - work in progress, simple JSON dump based on existing prototype

Added:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/json/
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/json/JsonItemWriter.java
  (with props)
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/JsonRendererServlet.java
  (with props)
Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/DefaultHtmlRendererServlet.java
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/PlainTextRendererServlet.java
    incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml
    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/MicroslingHttpTestBase.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java?rev=591318&r1=591317&r2=591318&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
Fri Nov  2 05:52:41 2007
@@ -1,3 +1,19 @@
+/*
+ * 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.contenttype;
 
 import java.io.IOException;
@@ -14,6 +30,9 @@
 import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;
 import org.apache.sling.microsling.request.helpers.AbstractFilter;
 
+/** A Filter that sets the desired Response Content-Type based
+ *  on the Request attributes.
+ */
 public class ResponseContentTypeResolverFilter extends AbstractFilter {
 
     // TODO: Is text/plain ok or should this rather be text/html ??

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/json/JsonItemWriter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/json/JsonItemWriter.java?rev=591318&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/json/JsonItemWriter.java
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/json/JsonItemWriter.java
Fri Nov  2 05:52:41 2007
@@ -0,0 +1,305 @@
+/*
+ * 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.helpers.json;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+/** Dumps JCR Items as JSON data */
+public class JsonItemWriter {
+    final Set<String> propertyNamesToIgnore;
+
+    /** Create a JsonItemWriter
+     *  @param propertyNamesToIgnore if not null, a property having a name from this
+     *  set of values is ignored
+     */ 
+    public JsonItemWriter(Set<String> propertyNamesToIgnore) {
+        this.propertyNamesToIgnore = propertyNamesToIgnore;
+    }
+
+    /** Dump all Nodes of given NodeIterator in JSON */
+    public void dump(NodeIterator it, PrintWriter out)
+            throws RepositoryException {
+        boolean first = true;
+        out.println("[");
+        while (it.hasNext()) {
+            dumpSingleNode(it.nextNode(), out, 1, 0, first);
+            first = false;
+        }
+        out.println("]");
+    }
+
+    /** Dump given node in JSON, optionally recursing into its child nodes */
+    public void dump(Node node, PrintWriter out, int currentRecursionLevel,
+            int maxRecursionLevels) throws RepositoryException {
+        PropertyIterator props = node.getProperties();
+
+        boolean first = true;
+
+        // the node's actual properties
+        while (props.hasNext()) {
+            Property prop = props.nextProperty();
+
+            if (propertyNamesToIgnore!=null && propertyNamesToIgnore.contains(prop.getName()))
{
+                continue;
+            }
+
+            if (!prop.getDefinition().isMultiple()) {
+                if (!(prop.getType() == PropertyType.BINARY)) {
+                    writeProperty(out, currentRecursionLevel, prop.getName(),
+                            stringValue(prop, prop.getValue()), first);
+                    first = false;
+                }
+            } else {
+                if (!(prop.getType() == PropertyType.BINARY)) {
+                    out.print(first ? "" : ",\r\n");
+                    first = false;
+                    indent(out, currentRecursionLevel);
+                    Value[] vals = prop.getValues();
+                    int i = 0;
+                    boolean firstval = true;
+                    out.print("\"" + prop.getName() + "\":[");
+                    while (i < vals.length) {
+                        if (!firstval) {
+                            out.print(",");
+                        }
+                        firstval = false;
+                        out.print("\"" + escape(stringValue(prop, vals[i]))
+                                + "\"");
+                        i++;
+                    }
+                    out.print("]");
+                }
+            }
+        }
+        NodeIterator nodes = node.getNodes();
+        while (nodes.hasNext()) {
+            Node childnode = nodes.nextNode();
+            out.print(first ? "" : ",\r\n");
+            first = false;
+            dumpSingleNode(childnode, out, currentRecursionLevel, maxRecursionLevels, first);
+        }
+    }
+
+    /** Dump a single node */
+    private void dumpSingleNode(Node n, PrintWriter out,
+            int currentRecursionLevel, int maxRecursionLevels, boolean first)
+            throws RepositoryException {
+        indent(out, currentRecursionLevel);
+        out.print("\"" + n.getName() + "\":");
+        out.println("{");
+        if (maxRecursionLevels == 0
+                || currentRecursionLevel + 1 < maxRecursionLevels) {
+            dump(n, out, currentRecursionLevel + 1, maxRecursionLevels);
+        }
+        out.println("");
+        indent(out, currentRecursionLevel + 1);
+        out.println("}");
+    }
+
+    /**
+     * <p/> escape Java Style.
+     * </p>
+     * 
+     * @param str
+     *            String to escape values in, may be null
+     * @param escapeSingleQuotes
+     *            escapes single quotes if <code>true</code>
+     * @return the escaped string
+     */
+    private String escapeJavaStyleString(String str, boolean escapeSingleQuotes) {
+        if (str == null) {
+            return null;
+        }
+        try {
+            StringWriter writer = new StringWriter(str.length() * 2);
+            escapeJavaStyleString(writer, str, escapeSingleQuotes);
+            return writer.toString();
+        } catch (IOException ioe) {
+            // this should never ever happen while writing to a StringWriter
+            ioe.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * <p/> escape Java Style.
+     * </p>
+     * 
+     * @param out
+     *            write to receieve the escaped string
+     * @param str
+     *            String to escape values in, may be null
+     * @param escapeSingleQuote
+     *            escapes single quotes if <code>true</code>
+     * @throws IOException
+     *             if an IOException occurs
+     */
+    private void escapeJavaStyleString(Writer out, String str,
+            boolean escapeSingleQuote) throws IOException {
+        if (out == null) {
+            throw new IllegalArgumentException("The Writer must not be null");
+        }
+        if (str == null) {
+            return;
+        }
+        int sz;
+        sz = str.length();
+        for (int i = 0; i < sz; i++) {
+            char ch = str.charAt(i);
+
+            // handle unicode
+            if (ch > 0xfff) {
+                out.write("\\u" + hex(ch));
+            } else if (ch > 0xff) {
+                out.write("\\u0" + hex(ch));
+            } else if (ch > 0x7f) {
+                out.write("\\u00" + hex(ch));
+            } else if (ch < 32) {
+                switch (ch) {
+                case '\b':
+                    out.write('\\');
+                    out.write('b');
+                    break;
+                case '\n':
+                    out.write('\\');
+                    out.write('n');
+                    break;
+                case '\t':
+                    out.write('\\');
+                    out.write('t');
+                    break;
+                case '\f':
+                    out.write('\\');
+                    out.write('f');
+                    break;
+                case '\r':
+                    out.write('\\');
+                    out.write('r');
+                    break;
+                default:
+                    if (ch > 0xf) {
+                        out.write("\\u00" + hex(ch));
+                    } else {
+                        out.write("\\u000" + hex(ch));
+                    }
+                    break;
+                }
+            } else {
+                switch (ch) {
+                case '\'':
+                    if (escapeSingleQuote) {
+                        out.write('\\');
+                    }
+                    out.write('\'');
+                    break;
+                case '"':
+                    out.write('\\');
+                    out.write('"');
+                    break;
+                case '\\':
+                    out.write('\\');
+                    out.write('\\');
+                    break;
+                default:
+                    out.write(ch);
+                    break;
+                }
+            }
+        }
+    }
+
+    /**
+     * <p/> Returns an upper case hexadecimal <code>String</code> for the
+     * given character.
+     * </p>
+     * 
+     * @param ch
+     *            The character to convert.
+     * @return An upper case hexadecimal <code>String</code>
+     */
+    private String hex(char ch) {
+        return Integer.toHexString(ch).toUpperCase();
+    }
+
+    /**
+     * outputs spaces per currentRecursionLevel
+     * 
+     * @param out
+     *            printwriter for indentation
+     * @param currentRecursionLevel
+     *            indentation currentRecursionLevel
+     */
+    private void indent(PrintWriter out, int currentRecursionLevel) {
+        int i = 0;
+        while (i++ < currentRecursionLevel) {
+            out.print("  ");
+        }
+    }
+
+    /**
+     * escape String for JSON format
+     */
+    private String escape(String orig) {
+        return escapeJavaStyleString(orig, false);
+    }
+
+    /**
+     * write a single property
+     */
+    private void writeProperty(PrintWriter out, int indent, String name,
+            String value, boolean first) {
+        if (!first) {
+            out.println(",");
+        }
+        if (indent > 0) {
+            indent(out, indent);
+        }
+        out.print("\"" + name + "\":\"" + escape(value) + "\"");
+    }
+
+    /** Convert given Value to a String */
+    private String stringValue(Property prop, Value value)
+            throws RepositoryException {
+        String result = null;
+
+        if (prop.getType() == PropertyType.DATE) {
+            // TODO more flexible format?
+            final DateFormat fmt = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'Z",
Locale.US);
+            result = fmt.format(value.getDate().getTime());
+        } else {
+            result = value.getString();
+        }
+
+        return result;
+    }
+
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/json/JsonItemWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/helpers/json/JsonItemWriter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

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=591318&r1=591317&r2=591318&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 05:52:41 2007
@@ -42,6 +42,7 @@
 import org.apache.sling.api.servlets.HttpConstants;
 import org.apache.sling.api.servlets.SlingAllMethodsServlet;
 import org.apache.sling.microsling.slingservlets.renderers.DefaultHtmlRendererServlet;
+import org.apache.sling.microsling.slingservlets.renderers.JsonRendererServlet;
 import org.apache.sling.microsling.slingservlets.renderers.PlainTextRendererServlet;
 
 /**
@@ -53,9 +54,19 @@
 
     private Map<String, Servlet> renderingServlets = new HashMap <String, Servlet>();
 
-    public DefaultSlingServlet() {
-        renderingServlets.put("text/plain", new PlainTextRendererServlet());
-        renderingServlets.put("text/html", new DefaultHtmlRendererServlet());
+    @Override
+    public void init() throws ServletException {
+        String contentType = null;
+        final String ctSuffix = "; charset=UTF-8";
+        
+        contentType = getServletContext().getMimeType("dummy.txt");
+        renderingServlets.put(contentType, new PlainTextRendererServlet(contentType + ctSuffix));
+        
+        contentType = getServletContext().getMimeType("dummy.html");
+        renderingServlets.put(contentType, new DefaultHtmlRendererServlet(contentType + ctSuffix));
+        
+        contentType = getServletContext().getMimeType("dummy.json");
+        renderingServlets.put(contentType, new JsonRendererServlet(contentType + ctSuffix));
     }
 
     @Override
@@ -91,7 +102,7 @@
                 throw new HttpStatusCodeException(
                         HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                         "No default renderer found for Content-Type='" + contentType + "'"
-                        + ", use one of these extensions: " + renderingServlets.keySet()
+                        + ", use one of these Content-types: " + renderingServlets.keySet()
                 );
             }
 

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/DefaultHtmlRendererServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/DefaultHtmlRendererServlet.java?rev=591318&r1=591317&r2=591318&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/DefaultHtmlRendererServlet.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/DefaultHtmlRendererServlet.java
Fri Nov  2 05:52:41 2007
@@ -37,14 +37,19 @@
 public class DefaultHtmlRendererServlet extends SlingSafeMethodsServlet {
 
     private static final long serialVersionUID = -5815904221043005085L;
+    private final String responseContentType;
 
+    public DefaultHtmlRendererServlet(String responseContentTypeHeaderValue) {
+        this.responseContentType = responseContentTypeHeaderValue;
+    }
+    
     @Override
     protected void doGet(SlingHttpServletRequest req,SlingHttpServletResponse resp) 
     throws ServletException,IOException 
     {
         final Resource  r = req.getResource();
         final Object data = r.getRawData();
-        resp.setContentType("text/html; charset=UTF-8");
+        resp.setContentType(responseContentType);
         final PrintWriter pw = resp.getWriter();
         try {
             pw.println("<html><body>");

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/JsonRendererServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/JsonRendererServlet.java?rev=591318&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/JsonRendererServlet.java
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/JsonRendererServlet.java
Fri Nov  2 05:52:41 2007
@@ -0,0 +1,99 @@
+/*
+ * 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.slingservlets.renderers;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.api.HttpStatusCodeException;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+import org.apache.sling.microsling.helpers.json.JsonItemWriter;
+
+/** A SlingSafeMethodsServlet that renders the current Resource
+ *  as simple HTML
+ */
+public class JsonRendererServlet extends SlingSafeMethodsServlet {
+
+    private static final long serialVersionUID = 5577121546674133317L;
+    private final String responseContentType;
+    private final JsonItemWriter itemWriter;
+    
+    /** This optional request parameter sets the recursion level 
+     *  (into chldren) when dumping a node */
+    public static final String PARAM_RECURSION_LEVEL = "slingItemDumpRecursionLevel";
+
+    public JsonRendererServlet(String responseContentTypeHeaderValue) {
+        this.responseContentType = responseContentTypeHeaderValue;
+        itemWriter = new JsonItemWriter(null);
+    }
+    
+    @Override
+    protected void doGet(SlingHttpServletRequest req,SlingHttpServletResponse resp) 
+    throws ServletException,IOException 
+    {
+        // Access and check our data
+        final Resource  r = req.getResource();
+        final Object data = r.getRawData();
+        if(data == null) {
+            throw new HttpStatusCodeException(HttpServletResponse.SC_NOT_FOUND, "No data
to dump");
+        }
+        if(!(data instanceof Node)) {
+            throw new HttpStatusCodeException(
+                    HttpServletResponse.SC_NOT_IMPLEMENTED, 
+                    "Don't know how to dump a " + data.getClass().getName()
+            );
+        }
+        final Node n = (Node)data;
+        
+        // how many levels deep?
+        int maxRecursionLevels = 0;
+        final String depth = req.getParameter(PARAM_RECURSION_LEVEL);
+        if (depth != null) {
+          try {
+            maxRecursionLevels = Integer.parseInt(depth);
+          } catch(Exception e) {
+            throw new HttpStatusCodeException(HttpServletResponse.SC_BAD_REQUEST, 
+                    "Invalid value '" + depth + "' for request parameter '" + PARAM_RECURSION_LEVEL
+ "'"
+            );
+          }
+        }
+
+        // do the dump
+        resp.setContentType(responseContentType);
+        final PrintWriter pw = resp.getWriter();
+        
+        try {
+            itemWriter.dump(n,pw,0,maxRecursionLevels);
+        } catch(RepositoryException re) {
+            throw new HttpStatusCodeException(
+                    HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+                    re.toString(),
+                    re
+            );
+        } finally {
+            pw.flush();
+        }
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/JsonRendererServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/JsonRendererServlet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/PlainTextRendererServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/PlainTextRendererServlet.java?rev=591318&r1=591317&r2=591318&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/PlainTextRendererServlet.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/renderers/PlainTextRendererServlet.java
Fri Nov  2 05:52:41 2007
@@ -37,14 +37,19 @@
 public class PlainTextRendererServlet extends SlingSafeMethodsServlet {
 
     private static final long serialVersionUID = -5815904221043005085L;
+    private final String responseContentType;
 
+    public PlainTextRendererServlet(String responseContentTypeHeaderValue) {
+        this.responseContentType = responseContentTypeHeaderValue;
+    }
+    
     @Override
     protected void doGet(SlingHttpServletRequest req,SlingHttpServletResponse resp) 
     throws ServletException,IOException 
     {
         final Resource  r = req.getResource();
         final Object data = r.getRawData();
-        resp.setContentType("text/plain; charset=UTF-8");
+        resp.setContentType(responseContentType);
         final PrintWriter pw = resp.getWriter();
         try {
             if (data instanceof Node) {

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml?rev=591318&r1=591317&r2=591318&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml Fri Nov
 2 05:52:41 2007
@@ -264,4 +264,9 @@
     <extension>htm</extension>
     <mime-type>text/html</mime-type>
   </mime-mapping>
+  <mime-mapping>
+    <!-- JSON, as specified by RFC 4627 -->
+    <extension>json</extension>
+    <mime-type>application/json</mime-type>
+  </mime-mapping>
 </web-app>

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=591318&r1=591317&r2=591318&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 05:52:41 2007
@@ -50,9 +50,10 @@
         assertTrue(responseBodyStr.contains("value2"));
         
         // test default txt and html renderings
-        getContent(urlOfNewNode, "text/plain");
-        getContent(urlOfNewNode + ".txt", "text/plain");
-        getContent(urlOfNewNode + ".html", "text/html");
+        getContent(urlOfNewNode, CONTENT_TYPE_PLAIN);
+        getContent(urlOfNewNode + ".txt", CONTENT_TYPE_PLAIN);
+        getContent(urlOfNewNode + ".html", CONTENT_TYPE_HTML);
+        getContent(urlOfNewNode + ".json", CONTENT_TYPE_JSON);
         
         // funny extensions are rendered as text/plain
         getContent(urlOfNewNode + ".someWeirdExtension", "text/plain");

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=591318&r1=591317&r2=591318&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
Fri Nov  2 05:52:41 2007
@@ -41,6 +41,7 @@
     public static final String CONTENT_TYPE_HTML = "text/html";
     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";
     
     protected MicroslingIntegrationTestClient testClient;
     protected HttpClient httpClient;



Mime
View raw message