abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eli...@apache.org
Subject svn commit: r418494 - in /incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server: ResponseContext.java exceptions/AbderaServerException.java exceptions/MethodNotAllowed.java servlet/AbderaServlet.java
Date Sat, 01 Jul 2006 18:04:15 GMT
Author: eliast
Date: Sat Jul  1 11:04:15 2006
New Revision: 418494

URL: http://svn.apache.org/viewvc?rev=418494&view=rev
Log:
- Added ResponseContext setContentLength
- Added implementation of custom headers in AbderaServerException
- Added support for setting Allow headers in MethodNotAllowedException
- Added support in AbderaServlet to set Content-Length

Modified:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ResponseContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/AbderaServerException.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ResponseContext.java?rev=418494&r1=418493&r2=418494&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ResponseContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ResponseContext.java
Sat Jul  1 11:04:15 2006
@@ -39,7 +39,9 @@
   public String getContentLanguage();
   
   public URI getContentLocation();
-   
+  
+  public long getContentLength();
+  
   public MimeType getContentType();
   
   public URI getLocation();

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/AbderaServerException.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/AbderaServerException.java?rev=418494&r1=418493&r2=418494&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/AbderaServerException.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/AbderaServerException.java
Sat Jul  1 11:04:15 2006
@@ -20,7 +20,9 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URI;
+import java.util.Arrays;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -40,8 +42,10 @@
   private String etag = null;
   private String language = null;
   private URI contentLocation = null;
+  private long contentLength = -1;
   private MimeType contentType = null;
   private URI location = null;
+  private Map<String,List<String>> headers = new HashMap<String, List<String>>();
   
   public AbderaServerException(int status, String text) {
     this.status = status;
@@ -75,6 +79,10 @@
   public MimeType getContentType() {
     return contentType;
   }
+  
+  public long getContentLength() {
+    return contentLength;
+  }
 
   public URI getLocation() {
     return location;
@@ -93,19 +101,27 @@
   }
 
   public void addHeader(String name, int value) {
+    addHeader(name, Integer.toString(value));       
   }
 
   public void addHeader(String name, String value) {
+    if(!this.headers.containsKey(name)) {
+      setHeader(name, value);
+    } else {
+      List<String> values = this.headers.get(name);
+      values.add(value);
+    }
+  }
+
+  public Map<String, List<String>> getHeaders() {
+    return this.headers;
   }
 
   public void setHeader(String name, int value) {
+    setHeader(name, Integer.toString(value));    
   }
 
   public void setHeader(String name, String value) {
-    
-  }
-  
-  public Map<String, List<String>> getHeaders() {
-    return null;
+    this.headers.put(name, Arrays.asList(new String[] { value }));    
   }
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java?rev=418494&r1=418493&r2=418494&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
Sat Jul  1 11:04:15 2006
@@ -17,6 +17,8 @@
 */
 package org.apache.abdera.server.exceptions;
 
+import org.apache.abdera.server.RequestContext;
+
 
 public class MethodNotAllowed 
   extends AbderaServerException {
@@ -31,4 +33,20 @@
     super(405, text);
   }
   
+  public void setAllow(RequestContext.Method[] methods) {
+    if(methods == null || methods.length == 0) {
+      throw new IllegalArgumentException("Methods argument must not be empty or null.");
+    }
+    boolean first = true;
+    StringBuffer value = new StringBuffer();
+    for(RequestContext.Method method : methods) {
+      if(first) {
+        value.append(method.toString());
+        first = false;
+        continue;
+      }
+      value.append(", " + method.toString());
+    }
+    setHeader("Allow", value.toString());
+  }
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java?rev=418494&r1=418493&r2=418494&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
Sat Jul  1 11:04:15 2006
@@ -83,6 +83,9 @@
         response.setHeader("ETag", context.getEntityTag());
       if (context.getLocation() != null)
         response.setHeader("Location", context.getLocation().toString());
+      if (context.getContentLength() > -1) {
+        response.setHeader("Content-Length", Long.toString(context.getContentLength()));
+      }
       handleCachePolicy(response, context.getCachePolicy());
       
       // Add any custom headers after we've set the known ones,



Mime
View raw message