abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r771450 - in /abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server: ResponseContext.java context/AbstractResponseContext.java context/ResponseContextWrapper.java context/SimpleResponseContext.java servlet/AbderaServlet.java
Date Mon, 04 May 2009 21:29:32 GMT
Author: jmsnell
Date: Mon May  4 21:29:31 2009
New Revision: 771450

URL: http://svn.apache.org/viewvc?rev=771450&view=rev
Log:
For https://issues.apache.org/jira/browse/ABDERA-210

ResponseContext needs to be able to support non-Atom binary resources so we cannot assume
that 
AbderaServlet should always use a Writer. This adds a new method to ResponseContext called
isBinary,
which defaults to false.  If true, the AbderaServlet will pass the OutputStream to ResponseContext,
if false, the servlet will pass the Writer to ResponseContext. 

This also fixes a bug in ResponseContextWrapper.

Modified:
    abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/ResponseContext.java
    abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/AbstractResponseContext.java
    abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextWrapper.java
    abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/SimpleResponseContext.java
    abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java

Modified: abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/ResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/ResponseContext.java?rev=771450&r1=771449&r2=771450&view=diff
==============================================================================
--- abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/ResponseContext.java
(original)
+++ abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/ResponseContext.java
Mon May  4 21:29:31 2009
@@ -33,6 +33,22 @@
   extends Response {
 
   /**
+   * True if the response contains a binary entity as opposed to a character
+   * based entity. Default is false.  If true, the AbderaServlet will pass 
+   * in the OutputStream for writing out, if false, the AbderaServlet will pass
+   * in the Writer.
+   */
+  boolean isBinary();
+  
+  /**
+   * True if the response contains a binary entity as opposed to a character
+   * based entity. Default is false.  If true, the AbderaServlet will pass 
+   * in the OutputStream for writing out, if false, the AbderaServlet will pass
+   * in the Writer.
+   */
+  ResponseContext setBinary(boolean binary);
+  
+  /**
    * True if the response contains an entity
    */
   boolean hasEntity();

Modified: abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/AbstractResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/AbstractResponseContext.java?rev=771450&r1=771449&r2=771450&view=diff
==============================================================================
--- abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/AbstractResponseContext.java
(original)
+++ abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/AbstractResponseContext.java
Mon May  4 21:29:31 2009
@@ -44,9 +44,19 @@
   protected int status = 0;
   protected String status_text = null;
   protected Writer writer = null;
+  protected boolean binary = false;
   
   protected Map<String,Object[]> headers = null;
 
+  public ResponseContext setBinary(boolean binary) {
+    this.binary = binary;
+    return this;
+  }
+  
+  public boolean isBinary() {
+    return binary;
+  }
+  
   public ResponseContext removeHeader(String name) {
     Map<String,Object[]> headers = getHeaders();
     headers.remove(name);

Modified: abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextWrapper.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextWrapper.java?rev=771450&r1=771449&r2=771450&view=diff
==============================================================================
--- abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextWrapper.java
(original)
+++ abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/ResponseContextWrapper.java
Mon May  4 21:29:31 2009
@@ -42,22 +42,26 @@
     String name, 
     String charset,
     String value) {
-      return response.addEncodedHeader(name, charset, value);
+      response.addEncodedHeader(name, charset, value);
+      return this;
   }
   
   public ResponseContext addEncodedHeaders(
     String name, 
     String charset,
     String... vals) {
-      return response.addEncodedHeaders(name, charset, vals);
+      response.addEncodedHeaders(name, charset, vals);
+      return this;
   }
   
   public ResponseContext addHeader(String name, Object value) {
-    return response.addHeader(name, value);
+    response.addHeader(name, value);
+    return this;
   }
   
   public ResponseContext addHeaders(String name, Object... vals) {
-    return response.addHeaders(name, vals);
+    response.addHeaders(name, vals);
+    return this;
   }
   
   public boolean hasEntity() {
@@ -65,104 +69,127 @@
   }
   
   public ResponseContext removeHeader(String name) {
-    return response.removeHeader(name);
+    response.removeHeader(name);
+    return this;
   }
   
   public ResponseContext setAge(long age) {
-    return response.setAge(age);
+    response.setAge(age);
+    return this;
   }
   
   public ResponseContext setAllow(String method) {
-    return response.setAllow(method);
+    response.setAllow(method);
+    return this;
   }
   
   public ResponseContext setAllow(String... methods) {
-    return response.setAllow(methods);
+    response.setAllow(methods);
+    return this;
   }
   
   public ResponseContext setContentLanguage(String language) {
-    return response.setContentLanguage(language);
+    response.setContentLanguage(language);
+    return this;
   }
   
   public ResponseContext setContentLength(long length) {
-    return response.setContentLength(length);
+    response.setContentLength(length);
+    return this;
   }
   
   public ResponseContext setContentLocation(String uri) {
-    return response.setContentLocation(uri);
+    response.setContentLocation(uri);
+    return this;
   }
   
   public ResponseContext setContentType(String type) {
-    return response.setContentType(type);
+    response.setContentType(type);
+    return this;
   }
   
   public ResponseContext setContentType(String type, String charset) {
-    return response.setContentType(type, charset);
+    response.setContentType(type, charset);
+    return this;
   }
   
   public ResponseContext setEncodedHeader(
     String name, 
     String charset,
     String value) {
-      return response.setEncodedHeader(name, charset, value);
+      response.setEncodedHeader(name, charset, value);
+      return this;
   }
   
   public ResponseContext setEncodedHeader(
     String name, 
     String charset,
     String... vals) {
-      return response.setEncodedHeader(name, charset, vals);
+      response.setEncodedHeader(name, charset, vals);
+      return this;
   }
   
   public ResponseContext setEntityTag(String etag) {
-    return response.setEntityTag(etag);
+    response.setEntityTag(etag);
+    return this;
   }
   
   public ResponseContext setEntityTag(EntityTag etag) {
-    return response.setEntityTag(etag);
+    response.setEntityTag(etag);
+    return this;
   }
   
   public ResponseContext setEscapedHeader(
     String name, 
     Profile profile,
     String value) {
-      return response.setEscapedHeader(name, profile, value);
+      response.setEscapedHeader(name, profile, value);
+      return this;
   }
   
   public ResponseContext setExpires(Date date) {
-    return response.setExpires(date);
+    response.setExpires(date);
+    return this;
   }
   
   public ResponseContext setHeader(String name, Object value) {
-    return response.setHeader(name, value);
+    response.setHeader(name, value);
+    return this;
   }
   
   public ResponseContext setHeader(String name, Object... vals) {
-    return response.setHeader(name, vals);
+    response.setHeader(name, vals);
+    return this;
   }
   
   public ResponseContext setLastModified(Date date) {
-    return response.setLastModified(date);
+    response.setLastModified(date);
+    return this;
   }
   
   public ResponseContext setLocation(String uri) {
-    return response.setLocation(uri);
+    response.setLocation(uri);
+    return this;
   }
   
   public ResponseContext setSlug(String slug) {
-    return response.setSlug(slug);
+    response.setSlug(slug);
+    return this;
   }
   
   public ResponseContext setStatus(int status) {
-    return response.setStatus(status);
+    response.setStatus(status);
+    return this;
   }
   
   public ResponseContext setStatusText(String text) {
-    return response.setStatusText(text);
+    response.setStatusText(text);
+    return this;
   }
   
   public ResponseContext setWriter(Writer writer) {
-    return response.setWriter(writer);
+    response.setWriter(writer);
+    return this;
   }
   
   public void writeTo(OutputStream out) throws IOException {
@@ -309,5 +336,14 @@
   public boolean isNoTransform() {
     return response.isNoTransform();
   }
+
+  public boolean isBinary() {
+    return response.isBinary();
+  }
+  
+  public ResponseContext setBinary(boolean binary) {
+    response.setBinary(true);
+    return this;
+  }
   
 }

Modified: abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/SimpleResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/SimpleResponseContext.java?rev=771450&r1=771449&r2=771450&view=diff
==============================================================================
--- abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/SimpleResponseContext.java
(original)
+++ abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/context/SimpleResponseContext.java
Mon May  4 21:29:31 2009
@@ -40,13 +40,18 @@
     this(null);
   }
   
-  protected SimpleResponseContext(String encoding) {
-    this.encoding = encoding != null ? encoding : "UTF-8";
+  protected SimpleResponseContext(
+    String encoding) {
+      this.encoding = 
+        encoding != null ? 
+          encoding : 
+          "UTF-8";
   }
   
-  protected SimpleResponseContext setEncoding(String encoding) {
-    this.encoding = encoding;
-    return this;
+  protected SimpleResponseContext setEncoding(
+    String encoding) {
+      this.encoding = encoding;
+      return this;
   }
   
   protected String getEncoding() {
@@ -56,8 +61,13 @@
   public void writeTo(
     OutputStream out) 
       throws IOException {
-    if (hasEntity())
-      writeTo(new OutputStreamWriter(out,encoding));
+    if (hasEntity()) {
+      OutputStreamWriter writer = 
+        new OutputStreamWriter(
+          out,encoding);
+      writeTo(writer);
+      writer.flush();
+    }
   }
   
   public void writeTo(

Modified: abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java?rev=771450&r1=771449&r2=771450&view=diff
==============================================================================
--- abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
(original)
+++ abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
Mon May  4 21:29:31 2009
@@ -124,9 +124,12 @@
             response.setHeader(name, value.toString());
         }
       }
-      
       if (!request.getMethod().equals("HEAD") && context.hasEntity()) {
-        context.writeTo(response.getOutputStream());
+        if (context.isBinary()) {
+          context.writeTo(response.getOutputStream());
+        } else {
+          context.writeTo(response.getWriter());
+        }
       }  
     } else {
       error("Internal Server Error", null, response);



Mime
View raw message