jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1169787 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server: BoundaryInputStream.java MicroKernelServlet.java Request.java Response.java
Date Mon, 12 Sep 2011 15:02:56 GMT
Author: dpfister
Date: Mon Sep 12 15:02:55 2011
New Revision: 1169787

URL: http://svn.apache.org/viewvc?rev=1169787&view=rev
Log:
HTTP interface to microkernel
- minor changes

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/BoundaryInputStream.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Request.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/BoundaryInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/BoundaryInputStream.java?rev=1169787&r1=1169786&r2=1169787&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/BoundaryInputStream.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/BoundaryInputStream.java
Mon Sep 12 15:02:55 2011
@@ -20,7 +20,8 @@ import java.io.InputStream;
 import java.io.IOException;
 
 /**
- * Stream that reads bytes until a given string boundary.
+ * Stream that reads bytes until a given string boundary, preceded
+ * by CR+LF, as used in multipart/form-data.
  */
 public class BoundaryInputStream extends InputStream {
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java?rev=1169787&r1=1169786&r2=1169787&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
Mon Sep 12 15:02:55 2011
@@ -26,6 +26,8 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.apache.jackrabbit.mk.util.MicroKernelInputStream;
+import org.apache.jackrabbit.mk.util.IOUtils;
 
 /**
  * Servlet handling requests directed at a <code>MicroKernel</code> instance.

@@ -52,9 +54,11 @@ class MicroKernelServlet implements Serv
                     command.execute(mk, request, response);
                 } catch (MicroKernelException e) {
                     response.setStatusCode(500);
+                    response.setContentType("text/plain");
                     e.printStackTrace(new PrintStream(response.getOutputStream()));
                 } catch (Throwable e) {
                     response.setStatusCode(500);
+                    response.setContentType("text/plain");
                     e.printStackTrace(new PrintStream(response.getOutputStream()));
                 }
                 return;
@@ -89,7 +93,8 @@ class MicroKernelServlet implements Serv
         
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
-            
+
+            response.setContentType("text/plain");
             response.getOutputStream().write(mk.getHeadRevision().getBytes());
         }        
     }
@@ -102,6 +107,7 @@ class MicroKernelServlet implements Serv
             long since = request.getParameter("since", 0L);
             int maxEntries = request.getParameter("max_entries", 10);
 
+            response.setContentType("text/plain");
             response.getOutputStream().write(mk.getRevisions(since, maxEntries).getBytes());
         }        
     }
@@ -123,6 +129,8 @@ class MicroKernelServlet implements Serv
             } catch (InterruptedException e) {
                 throw new MicroKernelException(e);
             }
+
+            response.setContentType("text/plain");
             response.getOutputStream().write(currentHead.getBytes());
         }
     }
@@ -137,6 +145,7 @@ class MicroKernelServlet implements Serv
             String fromRevisionId = request.getParameter("from_revision_id", headRevision);
             String toRevisionId = request.getParameter("to_revision_id", headRevision);
 
+            response.setContentType("text/plain");
             response.getOutputStream().write(mk.getJournal(fromRevisionId, toRevisionId).getBytes());
         }        
     }
@@ -151,6 +160,7 @@ class MicroKernelServlet implements Serv
             String path = request.getParameter("path", "/");
             String revisionId = request.getParameter("revision_id", headRevision);
 
+            response.setContentType("text/plain");
             response.getOutputStream().write(Boolean.toString(mk.nodeExists(path, revisionId)).getBytes());
         }
     }
@@ -168,6 +178,7 @@ class MicroKernelServlet implements Serv
             long offset = request.getParameter("offset", 0L);
             int count = request.getParameter("count", -1);
             
+            response.setContentType("text/plain");
             response.getOutputStream().write(mk.getNodes(path, revisionId, depth, offset,
count).getBytes());
         }        
     }
@@ -185,6 +196,8 @@ class MicroKernelServlet implements Serv
             String message = request.getParameter("message");
             
             String newRevision = mk.commit(path, jsonDiff, revisionId, message);
+
+            response.setContentType("text/plain");
             response.getOutputStream().write(newRevision.getBytes());
         }        
     }
@@ -196,6 +209,8 @@ class MicroKernelServlet implements Serv
 
             String blobId = request.getParameter("blob_id");
             long length = mk.getLength(blobId);
+
+            response.setContentType("text/plain");
             response.getOutputStream().write(Long.toString(length).getBytes());
         }
     }
@@ -206,17 +221,11 @@ class MicroKernelServlet implements Serv
                 throws IOException, MicroKernelException {
 
             String blobId = request.getParameter("blob_id");
-            OutputStream out = response.getOutputStream();
-            byte[] buf = new byte[8192];
-            long pos = 0;
-
-            for (;;) {
-                int count = mk.read(blobId, pos, buf, 0, buf.length);
-                if (count == -1) {
-                    break;
-                }
-                out.write(buf, 0, count);
-                pos += count;
+            if (blobId != null) {
+                InputStream in = new MicroKernelInputStream(mk, blobId);
+                OutputStream out = response.getOutputStream();
+
+                IOUtils.copy(in, out);
             }
         }
     }
@@ -228,7 +237,10 @@ class MicroKernelServlet implements Serv
 
             InputStream in = request.getFileParameter("file");
             if (in != null) {
-                response.getOutputStream().write(mk.write(in).getBytes());
+                String blobId = mk.write(in);
+
+                response.setContentType("text/plain");
+                response.getOutputStream().write(blobId.getBytes());
             }
         }        
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Request.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Request.java?rev=1169787&r1=1169786&r2=1169787&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Request.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Request.java
Mon Sep 12 15:02:55 2011
@@ -114,11 +114,11 @@ class Request {
         return file;
     }
     
-    public String getContentType() {
+    private String getContentType() {
         return headers.get("Content-Type");
     }
     
-    public int getContentLength() {
+    private int getContentLength() {
         String s = headers.get("Content-Length");
         if (s != null) {
             try {
@@ -215,7 +215,7 @@ class Request {
     
     public InputStream getInputStream() throws IOException {
         if (reqIn == null) {
-            // TODO: handle chunked
+            // TODO: handle chunked input
             int contentLength = getContentLength();
             if (contentLength == -1) {
                 contentLength = 0;
@@ -230,7 +230,7 @@ class Request {
             return -1;
         }
         if (chunked) {
-            // TODO: handle chunked
+            // TODO: handle chunked input
             return -1;
         } else {
             return in.read(b, off, len);

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java?rev=1169787&r1=1169786&r2=1169787&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
Mon Sep 12 15:02:55 2011
@@ -33,7 +33,7 @@ class Response {
     private boolean chunked;
     private int statusCode;
     private String contentType;
-    private OutputStreamImpl respOut;
+    private BodyOutputStream respOut;
     
     public Response(OutputStream out) {
         this.out = out;
@@ -65,12 +65,12 @@ class Response {
         
         headersSent = true;
         
-        int sc = this.statusCode;
-        if (sc == 0) {
-            sc = 200;
+        int statusCode = this.statusCode;
+        if (statusCode == 0) {
+            statusCode = 200;
         }
-        String msg = getStatusMsg(sc);
-        if (sc != 200 && respOut == null) {
+        String msg = getStatusMsg(statusCode);
+        if (statusCode != 200 && respOut == null) {
             /* Generate standard message for errors */
             String body = String.format(
                     "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">" +
@@ -78,12 +78,12 @@ class Response {
                     "<title>%d %s</title>" +
                     "</head><body>" +
                     "<h1>%s</h1>" +
-                    "</body></html>", sc, msg, msg);
+                    "</body></html>", statusCode, msg, msg);
             setContentType("text/html");
             getOutputStream().write(body.getBytes());
         }
         
-        writeLine(String.format("HTTP/1.1 %d %s", sc, msg));
+        writeLine(String.format("HTTP/1.1 %d %s", statusCode, msg));
         
         if (respOut != null) {
             if (committed) {
@@ -157,19 +157,19 @@ class Response {
     
     public OutputStream getOutputStream() {
         if (respOut == null) {
-            respOut = new OutputStreamImpl();
+            respOut = new BodyOutputStream();
         }
         return respOut;
     }
 
-    public void setStatusCode(int sc) {
-        this.statusCode = sc;
+    public void setStatusCode(int statusCode) {
+        this.statusCode = statusCode;
     }
     
     /**
      * Internal <code>OutputStream</code> passed to servlet handlers.
      */
-    private class OutputStreamImpl extends OutputStream {
+    private class BodyOutputStream extends OutputStream {
         
         private final byte[] buf = new byte[8192];
         private int count;



Mime
View raw message