abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r437871 - in /incubator/abdera/java/trunk: client/src/main/java/org/apache/abdera/protocol/util/ core/src/main/java/org/apache/abdera/protocol/ core/src/main/java/org/apache/abdera/protocol/util/ core/src/main/java/org/apache/abdera/util/ s...
Date Mon, 28 Aug 2006 22:43:27 GMT
Author: jmsnell
Date: Mon Aug 28 15:43:26 2006
New Revision: 437871

URL: http://svn.apache.org/viewvc?rev=437871&view=rev
Log:
Returning to the server code.

* refactoring the AbderaServerException stuff to eliminate multiple classes that 
  aren't really necessary

* refactor the API of the RequestContext and ResponseContext server apis

* provide an abstract base impl of ResponseContext for use by the AbderaServerException
  and other impls

* refactor the way the Cache-Control response header is handled

* move CacheControlParser to core.. it is used by both the client and server components
  depending on how much shared code we end up with between the client and server
  components, we may want to introduce a new "protocol" component.

* optionally pull the server host and port from the AbderaConfiguration instead of
  the servlet request.  If not specified in the AbderaConfiguration, use the servlet
  request as a fallback.

More to come.

Added:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/protocol/
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/protocol/util/
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/protocol/util/CacheControlParser.java
      - copied unchanged from r434219, incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/util/CacheControlParser.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaDataSource.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ServerConstants.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.java
Removed:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/util/CacheControlParser.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/BadRequestException.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/ExistenceException.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/GoneException.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowedException.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/NotFoundException.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/NotModifiedException.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/RequestException.java
Modified:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/AbderaServer.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/RequestContext.java
    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/impl/BaseRequestHandler.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaDataSource.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaDataSource.java?rev=437871&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaDataSource.java (added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaDataSource.java Mon Aug 28 15:43:26 2006
@@ -0,0 +1,97 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Service;
+
+public class AbderaDataSource 
+  implements DataSource {
+
+  private Base base = null;
+  
+  public AbderaDataSource(Base base) {
+    this.base = base;
+  }
+  
+  public String getContentType() {
+    String type = null;
+    if (base instanceof Document) {
+      Document doc = (Document) base;
+      if (doc.getContentType() != null) {
+        type = doc.getContentType().toString();
+      } else {
+        if (doc.getRoot() instanceof Feed ||
+            doc.getRoot() instanceof Entry) {
+          type = "application/atom+xml";
+        } else if (doc.getRoot() instanceof Service) {
+          type = "application/atomserv+xml";
+        } else {
+          type = "application/xml";
+        }
+      }
+    } else if (base instanceof Feed || base instanceof Entry) {
+      Document doc = ((Element)base).getDocument();
+      if (doc != null && doc.getContentType() != null)
+        type = doc.getContentType().toString();
+      if (type == null)
+        type = "application/atom+xml";
+    } else if (base instanceof Service) {
+      Document doc = ((Element)base).getDocument();
+      if (doc != null)
+        type = doc.getContentType().toString();
+      if (type == null)
+        type = "application/atomserv+xml";      
+    }
+    return (type != null) ? type : "application/xml";
+  }
+
+  public InputStream getInputStream() throws IOException {
+    try {
+      ByteArrayOutputStream out = new ByteArrayOutputStream();
+      base.writeTo(out);
+      ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+      return in;
+    } catch (IOException io) {
+      throw io;
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public String getName() {
+    return "Abdera Data Source::" + base.getClass().getName();
+  }
+
+  public OutputStream getOutputStream() throws IOException {
+    throw new UnsupportedOperationException();
+  }
+
+}

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/AbderaServer.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/AbderaServer.java?rev=437871&r1=437870&r2=437871&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/AbderaServer.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/AbderaServer.java Mon Aug 28 15:43:26 2006
@@ -20,9 +20,7 @@
 import org.apache.abdera.Abdera;
 import org.apache.abdera.util.ServiceUtil;
 
-public class AbderaServer {
-
-  public static final String HANDLER_FACTORY = "org.apache.abdera.server.RequestHandlerFactory";
+public class AbderaServer implements ServerConstants {
   
   private Abdera abdera = null;
   private RequestHandlerFactory handlerFactory = null;

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/RequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/RequestContext.java?rev=437871&r1=437870&r2=437871&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/RequestContext.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/RequestContext.java Mon Aug 28 15:43:26 2006
@@ -20,30 +20,100 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
+import java.util.Date;
 import java.util.List;
 
 public interface RequestContext {
   
-  public String getMethod();
+  /**
+   * Returns the method 
+   */
+  String getMethod();
+  
+  /**
+   * Returns the complete Request URI
+   */
+  URI getUri();
+  
+  /**
+   * Returns the server base URI
+   */
+  URI getBaseUri();
+  
+  /**
+   * Returns the relative URI (without scheme, host, or port)
+   */
+  URI getPathInfo();
+  
+  /**
+   * Returns a request parameter (e.g. query string param)
+   */
+  String getParameter(String name);
+  
+  /**
+   * Returns a list of request parameter values (e.g. query string params)
+   */
+  List<String> getParameters(String name);
+
+  /**
+   * Returns a listing of request parameter names
+   */
+  List<String> getParameterNames();
   
-  public URI getRequestUri();
+  /**
+   * Returns a request header
+   */
+  String getHeader(String name);
   
-  public URI getBaseUri();
+  /**
+   * Returns a list of request header values
+   */
+  List<String> getHeaders(String name);
   
-  public URI getPathInfo();
+  /**
+   * Returns a list of request header names
+   */
+  List<String> getHeaderNames();
   
-  public String getParameter(String name);
+  /**
+   * Returns the input stream for the request
+   */
+  InputStream getInputStream() throws IOException;
   
-  public List<String> getParameters(String name);
-
-  public List<String> getParameterNames();
+  String getAccept();
+  
+  String getAcceptCharset();
+  
+  String getAcceptEncoding();
+  
+  String getAcceptLanguage();
+  
+  String getAuthorization();
+  
+  String getCacheControl();
+  
+  String getContentType();
+  
+  Date getDateHeader(String name);
+  
+  String getIfMatch();
+  
+  Date getIfModifiedSince();
+  
+  String getIfNoneMatch();
+  
+  Date getIfUnmodifiedSince();
+  
+  long getMaxAge();
+  
+  long getMaxStale();
   
-  public String getHeader(String name);
+  long getMinFresh();
   
-  public List<String> getHeaders(String name);
+  boolean getNoCache();
   
-  public List<String> getHeaderNames();
+  boolean getNoStore();
   
-  public InputStream getInputStream() throws IOException;
+  boolean getNoTransform();
   
 }

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=437871&r1=437870&r2=437871&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 Mon Aug 28 15:43:26 2006
@@ -20,13 +20,13 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 import javax.activation.MimeType;
-
-import org.apache.abdera.server.cache.CachePolicy;
+import javax.activation.MimeTypeParseException;
 
 public interface ResponseContext {
 
@@ -40,28 +40,54 @@
   
   public String getContentLanguage();
   
-  public URI getContentLocation();
+  public URI getContentLocation() throws URISyntaxException;
   
   public long getContentLength();
   
-  public MimeType getContentType();
-  
-  public URI getLocation();
+  public MimeType getContentType() throws MimeTypeParseException;
   
-  public CachePolicy getCachePolicy();
+  public String getAllow();
   
-  public void setHeader(String name, String value);
+  public URI getLocation() throws URISyntaxException;
   
-  public void addHeader(String name, String value);
+  public Date getDateHeader(String name);
   
-  public void setHeader(String name, int value);
+  public String getHeader(String name);
   
-  public void addHeader(String name, int value);
+  public List<Object> getHeaders(String name);
   
-  public Map<String, List<String>> getHeaders();
+  public Map<String, List<Object>> getHeaders();
   
   public boolean hasEntity();
   
   public void writeTo(OutputStream out) throws IOException;
+  
+  boolean isPrivate();
+  
+  boolean isPublic();
+  
+  boolean isNoCache();
+  
+  boolean isNoStore();
+  
+  boolean isNoTransform();
+  
+  boolean isMustRevalidate();
+  
+  boolean isProxyRevalidate();
+  
+  long getMaxAge();
+  
+  long getSMaxAge();
+  
+  long getAge();
+  
+  Date getExpires();
+  
+  String[] getNoCacheHeaders();
+  
+  String[] getPrivateHeaders();
+  
+  String getCacheControl();
   
 }

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ServerConstants.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ServerConstants.java?rev=437871&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ServerConstants.java (added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ServerConstants.java Mon Aug 28 15:43:26 2006
@@ -0,0 +1,30 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.server;
+
+public interface ServerConstants {
+
+  public static final String REQUESTCONTEXT = 
+    "org.apache.abdera.server.RequestContext";
+ 
+  public static final String HANDLER_FACTORY = 
+    "org.apache.abdera.server.RequestHandlerFactory";
+  
+  public static final String X_OVERRIDE_HEADER = 
+    "X-HTTP-Method-Override";
+}

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=437871&r1=437870&r2=437871&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 Mon Aug 28 15:43:26 2006
@@ -17,111 +17,315 @@
 */
 package org.apache.abdera.server.exceptions;
 
+import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.PrintStream;
 import java.net.URI;
-import java.util.Arrays;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
 import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
+import javax.activation.URLDataSource;
 
+import org.apache.abdera.model.Base;
 import org.apache.abdera.server.ResponseContext;
-import org.apache.abdera.server.cache.CachePolicy;
+import org.apache.abdera.server.impl.BaseResponseContext;
+import org.apache.abdera.util.AbderaDataSource;
+import org.apache.axiom.attachments.ByteArrayDataSource;
 
-@SuppressWarnings("serial")
 public class AbderaServerException 
   extends Exception 
   implements ResponseContext {
 
-  private int status = 0;
-  private String statusText = null;
-  private Date lastModified = null;
-  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>>();
+  private static final long serialVersionUID = -4477406225965489951L;
+  protected ExceptionResponseContext context = null;
+  protected DataSource ds = null;
+  
+  public static enum Code {
+    MULTIPLECHOICES(300),
+    MOVEDPERMANENTLY(301),
+    FOUND(302),
+    SEEOTHER(303),
+    NOTMODIFIED(304),
+    USEPROXY(305),
+    TEMPORARYREDIRECT(307),
+    BADREQUEST(400),
+    UNAUTHORIZED(401),
+    PAYMENTREQUIRED(402),
+    FORBIDDEN(403),
+    NOTFOUND(404),
+    METHODNOTALLOWED(405),
+    NOTACCEPTABLE(406),
+    REQUESTTIMEOUT(408),
+    CONFLICT(409),
+    GONE(410),
+    LENGTHREQUIRED(411),
+    PRECONDITIONFAILED(412),
+    REQUESTENTITYTOOLARGE(413),
+    UNSUPPORTEDMEDIATYPE(415),
+    EXPECTATIONFAILED(417),
+    INTERNALSERVERERROR(500),
+    NOTIMPLEMENTED(501),
+    SERVICEUNAVAILABLE(503);
+    
+    private int code = 0;
+    private Code(int code) {
+      this.code = code;
+    }
+    
+    public int getCode() {
+      return code;
+    }
+    
+    public static Code getByCode(int status) {
+      for (Code code : Code.values()) {
+        if (code.code == status) return code;
+      }
+      return null;
+    }
+  }
+  
+  public AbderaServerException(Code code) {
+    this(code.getCode(),null);
+  }
+  
+  public AbderaServerException(Code code, String text) {
+    this(code.getCode(), text);
+  }
   
   public AbderaServerException(int status, String text) {
-    this.status = status;
-    this.statusText = text;
+    super();
+    context = new ExceptionResponseContext(this);
+    context.setStatus(status);
+    context.setStatusText(text);
   }
   
-  public int getStatus() {
-    return status;
+  public AbderaServerException(Throwable t) {
+    super(t);
+    context = new ExceptionResponseContext(this);
+    context.setStatus(500);
+    context.setStatusText(getMessage());
+  }
+  
+  public Code getCode() {
+    return Code.getByCode(getStatus());
+  }
+  
+  public void setDataSource(DataSource ds) {
+    this.ds = ds;
+  }
+  
+  public void setDataSource(String text) {
+    this.ds = (text != null) ? 
+      new ByteArrayDataSource(text.getBytes(), "text/plain") : 
+        null;
+  }
+  
+  public <T extends Base>void setDataSource(T base) {
+    this.ds = (base != null) ?
+      new AbderaDataSource(base) : null;
   }
 
-  public String getStatusText() {
-    return statusText;
+  public void setDataSource(URL url) {
+    this.ds = (url != null) ?
+      new URLDataSource(url) : null;
+  }
+  
+  public void setDataSource(File file) {
+    this.ds = (file != null) ?
+      new FileDataSource(file) : null;
+  }
+  
+  public DataSource getDataSource() {
+    return ds;
+  }
+  
+  public boolean hasEntity() {
+    if (ds != null) return true;
+    return context.hasEntity();
   }
 
-  public Date getLastModified() {
-    return lastModified;
+  public void writeTo(OutputStream out) throws IOException {
+    if (ds != null) {
+      InputStream in = ds.getInputStream();
+      int n = -1;
+      while((n = in.read()) != -1) { out.write(n); }
+      out.flush();
+    } else {
+      context.writeTo(out);
+    }
+  }
+  
+  public long getAge() {
+    return context.getAge();
   }
 
-  public String getEntityTag() {
-    return etag;
+  public String getCacheControl() {
+    return context.getCacheControl();
   }
 
   public String getContentLanguage() {
-    return language;
+    return context.getContentLanguage();
   }
 
-  public URI getContentLocation() {
-    return contentLocation;
+  public long getContentLength() {
+    return context.getContentLength();
   }
 
-  public MimeType getContentType() {
-    return contentType;
+  public URI getContentLocation() throws URISyntaxException {
+    return context.getContentLocation();
   }
-  
-  public long getContentLength() {
-    return contentLength;
+
+  public MimeType getContentType() throws MimeTypeParseException {
+    return context.getContentType();
   }
 
-  public URI getLocation() {
-    return location;
+  public Date getDateHeader(String name) {
+    return context.getDateHeader(name);
   }
 
-  public void writeTo(OutputStream out) throws IOException {
-    // TODO
+  public String getEntityTag() {
+    return context.getEntityTag();
   }
 
-  public CachePolicy getCachePolicy() {
-    return null;
+  public Date getExpires() {
+    return context.getExpires();
   }
 
-  public boolean hasEntity() {
-    return false;
+  public String getHeader(String name) {
+    return context.getHeader(name);
   }
 
-  public void addHeader(String name, int value) {
-    addHeader(name, Integer.toString(value));       
+  public List<Object> getHeaders(String name) {
+    return context.getHeaders(name);
   }
 
-  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<Object>> getHeaders() {
+    return context.getHeaders();
   }
 
-  public Map<String, List<String>> getHeaders() {
-    return this.headers;
+  public Date getLastModified() {
+    return context.getLastModified();
   }
 
-  public void setHeader(String name, int value) {
-    setHeader(name, Integer.toString(value));    
+  public URI getLocation() throws URISyntaxException {
+    return context.getLocation();
   }
 
-  public void setHeader(String name, String value) {
-    this.headers.put(name, Arrays.asList(new String[] { value }));    
+  public long getMaxAge() {
+    return context.getMaxAge();
   }
+
+  public String[] getNoCacheHeaders() {
+    return context.getNoCacheHeaders();
+  }
+
+  public String[] getPrivateHeaders() {
+    return context.getPrivateHeaders();
+  }
+
+  public long getSMaxAge() {
+    return context.getSMaxAge();
+  }
+
+  public int getStatus() {
+    return context.getStatus();
+  }
+
+  public String getStatusText() {
+    return context.getStatusText();
+  }
+
+  public boolean isMustRevalidate() {
+    return context.isMustRevalidate();
+  }
+
+  public boolean isNoCache() {
+    return context.isNoCache();
+  }
+
+  public boolean isNoStore() {
+    return context.isNoStore();
+  }
+
+  public boolean isNoTransform() {
+    return context.isNoTransform();
+  }
+
+  public boolean isPrivate() {
+    return context.isPrivate();
+  }
+
+  public boolean isProxyRevalidate() {
+    return context.isProxyRevalidate();
+  }
+
+  public boolean isPublic() {
+    return context.isPublic();
+  }
+
+  public String getAllow() {
+    return context.getAllow();
+  }
+  
+  public void setAllow(String method) {
+    this.context.setAllow(method);
+  }
+  
+  public void setAllow(String... methods) {
+    this.context.setAllow(methods);
+  }
+  
+  protected static class ExceptionResponseContext 
+    extends BaseResponseContext {
+
+    private Throwable t = null;
+    private long len = -1;
+    
+    ExceptionResponseContext(Throwable t) {
+      this.t = t;
+    }
+    
+    
+    
+    public boolean hasEntity() {
+      return true;
+    }
+  
+    public void writeTo(OutputStream out) throws IOException {
+      PrintStream ps = 
+        (out instanceof PrintStream) ? 
+          (PrintStream)out : 
+          new PrintStream(out);
+      t.printStackTrace(ps);
+    }
+  
+    @Override
+    public long getContentLength() {
+      if (len == -1) {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        PrintStream ps = new PrintStream(out);
+        t.printStackTrace(ps);
+        ps.flush();
+        len = out.size();
+      } 
+      return len;
+    }
+  
+    @Override
+    public void setContentLength(long length) {
+      len = length;
+    }
+    
+  }
+
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseRequestHandler.java?rev=437871&r1=437870&r2=437871&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseRequestHandler.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseRequestHandler.java Mon Aug 28 15:43:26 2006
@@ -23,11 +23,6 @@
 import org.apache.abdera.server.cache.Cache;
 import org.apache.abdera.server.cache.CacheEntry;
 import org.apache.abdera.server.exceptions.AbderaServerException;
-import org.apache.abdera.server.exceptions.ExistenceException;
-import org.apache.abdera.server.exceptions.MethodNotAllowedException;
-import org.apache.abdera.server.exceptions.NotFoundException;
-import org.apache.abdera.server.exceptions.NotModifiedException;
-import org.apache.abdera.server.exceptions.RequestException;
 
 public abstract class BaseRequestHandler 
   implements RequestHandler {
@@ -54,7 +49,8 @@
       if (response != null)
         return response;
       else
-        return new NotFoundException();
+        throw new AbderaServerException(
+          AbderaServerException.Code.NOTFOUND);
     } catch (AbderaServerException ase) {
       throw ase;
     } catch (Throwable t) {
@@ -102,14 +98,14 @@
    * MUST throw an appropriate ExistenceException (e.g. not found,
    * gone, moved, etc)
    */
-  protected void checkExists(RequestContext requestContext) throws ExistenceException{}
+  protected void checkExists(RequestContext requestContext) throws AbderaServerException{}
   
   /**
    * Check the request method.  If the method is not supported, 
    * a MethodNotAllowedException MUST be thrown, otherwise the 
    * method should return with no exceptions
    */
-  protected void checkMethod(RequestContext requestContext) throws MethodNotAllowedException {
+  protected void checkMethod(RequestContext requestContext) throws AbderaServerException {
     String method = requestContext.getMethod();
     String[] methods = getAllowedMethods(getResourceType(requestContext));
     java.util.Arrays.sort(methods);
@@ -122,13 +118,13 @@
    * a NotModifiedException MUST be thrown, otherwise the method
    * should return with no exceptions
    */
-  protected void checkModified(RequestContext requestContext) throws NotModifiedException {}
+  protected void checkModified(RequestContext requestContext) {}
   
   /**
    * Check to see if the request is valid. If not, throw an appropriate
    * RequestException
    */
-  protected void checkRequest(RequestContext requestContext) throws RequestException {}
+  protected void checkRequest(RequestContext requestContext) throws AbderaServerException {}
   
   /**
    * Handle the request
@@ -155,9 +151,13 @@
   /**
    * Utility method for reporting MethodNotAllowedExceptions properly
    */
-  protected void notAllowed(RequestContext requestContext) throws MethodNotAllowedException {
-    MethodNotAllowedException notallowed = new MethodNotAllowedException();
-    notallowed.setAllow(getAllowedMethods(getResourceType(requestContext)));
+  protected void notAllowed(RequestContext requestContext) throws AbderaServerException {
+    AbderaServerException notallowed = 
+      new AbderaServerException(
+        AbderaServerException.Code.METHODNOTALLOWED);
+    notallowed.setAllow(
+      getAllowedMethods(
+        getResourceType(requestContext)));
     throw notallowed;
   }
   

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.java?rev=437871&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.java (added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.java Mon Aug 28 15:43:26 2006
@@ -0,0 +1,433 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  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.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.server.impl;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
+
+import org.apache.abdera.server.ResponseContext;
+
+public abstract class BaseResponseContext 
+  implements ResponseContext {
+
+  protected final static byte NOCACHE = 1;
+  protected final static byte NOSTORE = 2;
+  protected final static byte NOTRANSFORM = 4;
+  protected final static byte MUSTREVALIDATE = 8;
+  protected final static byte PROXYREVALIDATE = 16;
+  protected final static byte PUBLIC = 32;
+  protected final static byte PRIVATE = 64;
+  protected static final String[] EMPTY = new String[0];
+  
+  protected int status = 0;
+  protected String status_text = null;
+  
+  protected Map<String,List<Object>> headers = null;
+  protected byte flags = 0;
+  protected long max_age = -1;
+  protected long smax_age = -1;
+  protected List<String> no_cache_headers = null;
+  protected List<String> private_headers = null;
+
+  public void removeHeader(String name) {
+    Map<String,List<Object>> headers = getHeaders();
+    headers.remove(name);
+  }
+  
+  public void setHeader(String name, Object value) {
+    Map<String,List<Object>> headers = getHeaders();
+    List<Object> values = new ArrayList<Object>();
+    values.add(value);
+    headers.put(name, values);
+  }
+  
+  public void setHeader(String name, Object... vals) {
+    Map<String,List<Object>> headers = getHeaders();
+    List<Object> values = new ArrayList<Object>();
+    for (Object value : vals) {
+      values.add(value);
+    }
+    headers.put(name, values);
+  }
+  
+  public void addHeader(String name, Object value) {
+    Map<String,List<Object>> headers = getHeaders();
+    List<Object> values = new ArrayList<Object>();
+    if (values == null) {
+      values = new ArrayList<Object>();
+      headers.put(name, values);
+    } 
+    values.add(value);
+  }
+  
+  public void addHeaders(String name, Object... vals) {
+    Map<String,List<Object>> headers = getHeaders();
+    List<Object> values = new ArrayList<Object>();
+    if (values == null) {
+      values = new ArrayList<Object>();
+      headers.put(name,values);
+    }
+    for (Object value : vals) {
+      values.add(value);
+    }
+  }
+  
+  public Map<String, List<Object>> getHeaders() {
+    if (headers == null)
+      headers = new HashMap<String,List<Object>>();
+    return headers;
+  }
+    
+  public Date getDateHeader(String name) {
+    Map<String,List<Object>> headers = getHeaders();
+    List<Object> values = headers.get(name);
+    if (values != null) {
+      for (Object value : values) {
+        if (value instanceof Date) 
+          return (Date)value;
+      }
+    }
+    return null;
+  }
+  
+  public String getHeader(String name) {
+    Map<String,List<Object>> headers = getHeaders();
+    List<Object> values = headers.get(name);
+    if (values != null && values.size() > 0) 
+      return values.get(0).toString();
+    return null;
+  }
+
+  public List<Object> getHeaders(String name) {
+    Map<String,List<Object>> headers = getHeaders();
+    return headers.get(name);
+  }
+
+  private void append(StringBuffer buf, String value) {
+    if (buf.length() > 0) buf.append(", ");
+    buf.append(value);
+  }
+    
+  public String getCacheControl() {
+    StringBuffer buf = new StringBuffer();
+    if (isPublic()) append(buf,"public");
+    if (isPrivate()) append(buf,"private");
+    if (private_headers != null && private_headers.size() > 0) {
+      buf.append("=\"");
+      for (String header : private_headers) {
+        append(buf,header);
+      }
+      buf.append("\"");
+    }
+    if (isNoCache()) append(buf,"no-cache");
+    if (no_cache_headers != null && no_cache_headers.size() > 0) {
+      buf.append("=\"");
+      for (String header : no_cache_headers) {
+        append(buf,header);
+      }
+      buf.append("\"");
+    }
+    if (isNoStore()) append(buf,"no-store");
+    if (isMustRevalidate()) append(buf,"must-revalidate");
+    if (isNoTransform()) append(buf, "no-transform");
+    if (getMaxAge() != -1) append(buf, "max-age=" + getMaxAge());
+    if (getSMaxAge() != -1) append(buf, "smax-age=" + getMaxAge());
+    return buf.toString();
+  }
+
+  public long getAge() {
+    String value = getHeader("Age");
+    return (value != null) ? Long.parseLong(value) : -1;
+  }
+  
+  public void setAge(long age) {
+    if (age == -1) {
+      removeHeader("Age"); 
+      return;
+    }
+    setHeader("Age", String.valueOf(age));
+  }
+  
+  public String getContentLanguage() {
+    return getHeader("Content-Language");
+  }
+  
+  public void setContentLanguage(String language) {
+    if (language == null) {
+      removeHeader("Content-Language");
+      return;
+    }
+    setHeader("Content-Language", language);
+  }
+
+  public long getContentLength() {
+    String value = getHeader("Content-Length");
+    return (value != null) ? Long.parseLong(value) : -1;
+  }
+  
+  public void setContentLength(long length) {
+    if (length == -1) {
+      removeHeader("Content-Length");
+      return;
+    }
+    setHeader("Content-Length", String.valueOf(length));
+  }
+
+  public URI getContentLocation() throws URISyntaxException {
+    String value = getHeader("Content-Location");
+    return (value != null) ? new URI(value) : null;
+  }
+
+  public void setContentLocation(String uri) {
+    if (uri == null) {
+      removeHeader("Content-Location");
+      return;
+    }
+    setHeader("Content-Location", uri);
+  }
+  
+  public MimeType getContentType() throws MimeTypeParseException {
+    String value = getHeader("Content-Type");
+    return (value != null) ? new MimeType(value) : null;
+  }
+  
+  public void setContentType(String type) {
+    if (type == null) {
+      removeHeader("Content-Type");
+      return;
+    }
+    setHeader("Content-Type", type);
+  }
+
+  public String getEntityTag() {
+    return getHeader("ETag");
+  }
+  
+  public void setEntityTag(String etag) {
+    if (etag == null) {
+      removeHeader("ETag");
+      return;
+    }
+    setHeader("ETag", etag);
+  }
+
+  public Date getExpires() {
+    return getDateHeader("Expires");
+  }
+
+  public void setExpires(Date date) {
+    if (date == null) {
+      removeHeader("Expires");
+      return;
+    }
+    setHeader("Expires", date);
+  }
+  
+  public Date getLastModified() {
+    return getDateHeader("Last-Modified");
+  }
+  
+  public void setLastModified(Date date) {
+    if (date == null) {
+      removeHeader("Last-Modified");
+      return;
+    }
+    setHeader("Last-Modified", date);
+  }
+
+  public URI getLocation() throws URISyntaxException {
+    String value = getHeader("Location");
+    return (value != null) ? new URI(value) : null;
+  }
+
+  public void setLocation(String uri) {
+    if (uri == null) {
+      removeHeader("Location");
+      return;
+    }
+    setHeader("Location", uri);
+  }
+  
+  public int getStatus() {
+    return status;
+  }
+  
+  public void setStatus(int status) {
+    this.status = status;
+  }
+
+  public String getStatusText() {
+    return status_text;
+  }
+  
+  public void setStatusText(String text) {
+    this.status_text = text;
+  }
+
+  public long getMaxAge() {
+    return max_age;
+  }
+  
+  public void setMaxAge(long max_age) {
+    this.max_age = max_age;
+  }
+
+  public String[] getNoCacheHeaders() {
+    if (no_cache_headers == null) return EMPTY;
+    return no_cache_headers.toArray(new String[no_cache_headers.size()]);
+  }
+  
+  public void setNoCacheHeaders(String header) {
+    if (no_cache_headers == null) no_cache_headers = new ArrayList<String>();
+    no_cache_headers.add(header);
+  }
+  
+  public void setNoCacheHeaders(String... headers) {
+    if (no_cache_headers == null) no_cache_headers = new ArrayList<String>();
+    for (String header : headers) {
+      no_cache_headers.add(header);
+    }
+  }
+
+  public String[] getPrivateHeaders() {
+    if (private_headers == null) return EMPTY;
+    return private_headers.toArray(new String[private_headers.size()]);
+  }
+
+  public void setPrivateHeaders(String header) {
+    if (private_headers == null) private_headers = new ArrayList<String>();
+    private_headers.add(header);
+  }
+  
+  public void setPrivateHeaders(String... headers) {
+    if (private_headers == null) private_headers = new ArrayList<String>();
+    for (String header : headers) {
+      private_headers.add(header);
+    }
+  }
+  
+  public long getSMaxAge() {
+    return smax_age;
+  }
+  
+  public void setSMaxAge(long smax_age) {
+    this.smax_age = smax_age;
+  }
+  
+  public boolean isMustRevalidate() {
+    return (flags & MUSTREVALIDATE) == MUSTREVALIDATE;
+  }
+  
+  public void setMustRevalidate(boolean val) {
+    if (isMustRevalidate() && !val)
+      flags ^= MUSTREVALIDATE;
+    else if (!isMustRevalidate() && val)
+      flags |= MUSTREVALIDATE;
+  }
+
+  public boolean isNoCache() {
+    return (flags & NOCACHE) == NOCACHE;
+  }
+
+  public void setNoCache(boolean val) {
+    if (isNoCache() && !val)
+      flags ^= NOCACHE;
+    else if (!isNoCache() && val)
+      flags |= NOCACHE;
+  }
+  
+  public boolean isNoStore() {
+    return (flags & NOSTORE) == NOSTORE;
+  }
+
+  public void setNoStore(boolean val) {
+    if (isNoStore() && !val)
+      flags ^= NOSTORE;
+    else if (!isNoStore() && val)
+      flags |= NOSTORE;
+  }
+  
+  public boolean isNoTransform() {
+    return (flags & NOTRANSFORM) == NOTRANSFORM;
+  }
+
+  public void setNoTransform(boolean val) {
+    if (isNoTransform() && !val)
+      flags ^= NOTRANSFORM;
+    else if (!isNoTransform() && val)
+      flags |= NOTRANSFORM;
+  }
+  
+  public boolean isPrivate() {
+    return (flags & PRIVATE) == PRIVATE;
+  }
+
+  public void setPrivate(boolean val) {
+    if (isPrivate() && !val)
+      flags ^= PRIVATE;
+    else if (!isPrivate() && val)
+      flags |= PRIVATE;
+  }
+  
+  public boolean isProxyRevalidate() {
+    return (flags & PROXYREVALIDATE) == PROXYREVALIDATE;
+  }
+  
+  public void setProxyRevalidate(boolean val) {
+    if (isProxyRevalidate() && !val)
+      flags ^= PROXYREVALIDATE;
+    else if (!isProxyRevalidate() && val)
+      flags |= PROXYREVALIDATE;
+  }
+
+  public boolean isPublic() {
+    return (flags & PUBLIC) == PUBLIC;
+  }
+
+  public void setPublic(boolean val) {
+    if (isPublic() && !val)
+      flags ^= PUBLIC;
+    else if (!isPublic() && val)
+      flags |= PUBLIC;
+  }  
+  
+  public String getAllow() {
+    return getHeader("Allow");
+  }
+  
+  public void setAllow(String method) {
+    setHeader("Allow", method);
+  }
+  
+  public void setAllow(String... methods) {
+    StringBuffer buf = new StringBuffer();
+    for(String method : methods) {
+      if (buf.length() > 0) buf.append(", ");
+      buf.append(method);
+    }
+    setAllow(buf.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=437871&r1=437870&r2=437871&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 Mon Aug 28 15:43:26 2006
@@ -18,6 +18,7 @@
 package org.apache.abdera.server.servlet;
 
 import java.io.IOException;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -26,28 +27,53 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.abdera.Abdera;
 import org.apache.abdera.server.AbderaServer;
 import org.apache.abdera.server.RequestContext;
 import org.apache.abdera.server.RequestHandler;
 import org.apache.abdera.server.RequestHandlerFactory;
 import org.apache.abdera.server.ResponseContext;
-import org.apache.abdera.server.cache.CachePolicy;
+import org.apache.abdera.server.ServerConstants;
 import org.apache.abdera.server.exceptions.AbderaServerException;
-import org.apache.abdera.server.exceptions.MethodNotAllowedException;
 
 public class AbderaServlet 
-  extends HttpServlet {
+  extends HttpServlet 
+  implements ServerConstants {
 
   private static final long serialVersionUID = -4273782501412352619L;
 
-  private AbderaServer abderaServer = new AbderaServer();
+  private Abdera abdera = null;
+  private AbderaServer abderaServer = null;
+  
+  @Override
+  public void init() throws ServletException {
+    synchronized(this) {
+      abdera = new Abdera();
+      abderaServer = new AbderaServer(abdera);
+    }
+  }
+
+  /**
+   * The RequestContext will either be set on the HttpServletRequest by 
+   * some filter or servlet earlier in the invocation chain or will need
+   * to be created and set on the request 
+   */
+  private RequestContext getRequestContext(HttpServletRequest request) {
+    RequestContext context = 
+      (RequestContext) request.getAttribute(REQUESTCONTEXT);
+    if (context == null) {
+      context = new ServletRequestContext(abdera,request);
+      request.setAttribute(REQUESTCONTEXT, context);
+    }
+    return context;
+  }
   
   @Override
   protected void service(
     HttpServletRequest request, 
     HttpServletResponse response) 
       throws ServletException, IOException {
-    RequestContext requestContext = new ServletRequestContext(request);
+    RequestContext requestContext = getRequestContext(request);
     ResponseContext responseContext = null;
     RequestHandler handler = null;
     try {
@@ -57,10 +83,13 @@
       if (handler != null) {
         responseContext = handler.invoke(requestContext);
       } else {
-        throw new MethodNotAllowedException(request.getMethod());
+        throw new AbderaServerException(
+          AbderaServerException.Code.NOTFOUND);
       }
     } catch (AbderaServerException exception) {
       responseContext = exception;
+    } catch (Throwable t) {
+      responseContext = new AbderaServerException(t);
     }
     doOutput(response, responseContext); 
   }
@@ -74,35 +103,21 @@
         response.sendError(context.getStatus(), context.getStatusText());
       else 
         response.setStatus(context.getStatus());
-      if (context.getLastModified() != null)
-        response.setDateHeader("Last-Modified", context.getLastModified().getTime());
-      if (context.getContentLanguage() != null)
-        response.setHeader("Content-Language", context.getContentLanguage());
-      if (context.getContentLocation() != null)
-        response.setHeader("Content-Location", context.getContentLocation().toString());
-      if (context.getContentType() != null)
-        response.setContentType(context.getContentType().toString());
-      if (context.getEntityTag() != null)
-        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,
-      // giving the developer an option to replace or set multiple
-      // headers. If they want to skip the ones above, they simply
-      // don't set them.
-      Map<String, List<String>> headers = context.getHeaders();
+      long cl = context.getContentLength();
+      String cc = context.getCacheControl();
+      if (cl > -1) response.setHeader("Content-Length", Long.toString(cl));
+      if (cc != null) response.setHeader("Cache-Control",cc);      
+      Map<String, List<Object>> headers = context.getHeaders();
       if (headers != null) {
-        for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
-          List<String> values = entry.getValue();
+        for (Map.Entry<String, List<Object>> entry : headers.entrySet()) {
+          List<Object> values = entry.getValue();
           if (values == null) 
             continue;          
-          for (String value : values) {
-            response.setHeader(entry.getKey(), value);
+          for (Object value : values) {
+            if (value instanceof Date)
+              response.setDateHeader(entry.getKey(), ((Date)value).getTime());
+            else
+              response.setHeader(entry.getKey(), value.toString());
           }
         }
       }
@@ -114,10 +129,4 @@
     }
   }
   
-  private void handleCachePolicy(
-    HttpServletResponse response, 
-    CachePolicy cachePolicy) {
-      if (cachePolicy == null) return;
-      //TODO
-  }
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java?rev=437871&r1=437870&r2=437871&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java Mon Aug 28 15:43:26 2006
@@ -23,29 +23,46 @@
 import java.net.URISyntaxException;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.abdera.Abdera;
+import org.apache.abdera.protocol.util.CacheControlParser;
 import org.apache.abdera.server.RequestContext;
+import org.apache.abdera.server.ServerConstants;
 
 public class ServletRequestContext 
-  implements RequestContext {
-
-  public static final String X_OVERRIDE_HEADER = "X-Method-Override";
+  implements RequestContext, ServerConstants {
   
+  private Abdera abdera = null;
   private HttpServletRequest servletRequest = null;
-  
+  private long maxage = -1;
+  private long maxstale = -1;
+  private long minfresh = -1;
+  private boolean nocache = false;
+  private boolean nostore = false;
+  private boolean notransform = false;
+  private String method = null;
+    
   public ServletRequestContext(
+    Abdera abdera,
     HttpServletRequest request) {
+      this.abdera = abdera;
       this.servletRequest = request;
+      get_ccp();
   }
   
   public String getMethod() {
-    return servletRequest.getMethod();
+    if (method == null) {
+      String o = getHeader(X_OVERRIDE_HEADER);
+      method = (o == null) ? servletRequest.getMethod() : o;
+    }
+    return method;
   }
   
-  public URI getRequestUri() {
+  public URI getUri() {
     URI uri = null;
     try {
       StringBuffer buf = 
@@ -58,13 +75,32 @@
     return uri;
   }
   
+  private String getHost() {
+    String host = abdera.getConfiguration().getConfigurationOption(
+      "org.apache.abdera.protocol.server.Host");
+    return (host != null) ? 
+      host : 
+      servletRequest.getServerName();
+  }
+  
+  private int getPort() {
+    String port = abdera.getConfiguration().getConfigurationOption(
+      "org.apache.abdera.protocol.server.Port");
+    return (port != null) ? 
+      Integer.parseInt(port) : 
+      servletRequest.getLocalPort();
+  }
+  
   public URI getBaseUri() {
-    // TODO: this should be done from properties
-    StringBuffer buffer = new StringBuffer("http://");
-    buffer.append(servletRequest.getServerName());
-    if (servletRequest.getLocalPort() != 80) {
+    StringBuffer buffer = 
+      new StringBuffer(
+        (servletRequest.isSecure())?
+          "https":"http");
+    buffer.append(getHost());
+    int port = getPort();
+    if (port != 80) {
       buffer.append(":");
-      buffer.append(servletRequest.getLocalPort());
+      buffer.append(port);
     }
     buffer.append(servletRequest.getServletPath());
     
@@ -118,6 +154,102 @@
         
   public InputStream getInputStream() throws IOException {
     return servletRequest.getInputStream();
+  }
+
+  public String getAccept() {
+    return servletRequest.getHeader("Accept");
+  }
+
+  public String getAcceptCharset() {
+    return servletRequest.getHeader("Accept-Charset");
+  }
+
+  public String getAcceptEncoding() {
+    return servletRequest.getHeader("Accept-Encoding");
+  }
+
+  public String getAcceptLanguage() {
+    return servletRequest.getHeader("Accept-Language");
+  }
+
+  public String getAuthorization() {
+    return servletRequest.getHeader("Authorization");
+  }
+
+  public String getCacheControl() {
+    return servletRequest.getHeader("Cache-Control");
+  }
+
+  public String getContentType() {
+    return servletRequest.getHeader("Content-Type");
+  }
+
+  public Date getDateHeader(String name) {
+    return new Date(servletRequest.getDateHeader(name));
+  }
+
+  public String getIfMatch() {
+    return servletRequest.getHeader("If-Match");
+  }
+
+  public Date getIfModifiedSince() {
+    return getDateHeader("If-Modified-Since");
+  }
+
+  public String getIfNoneMatch() {
+    return servletRequest.getHeader("If-None-Match");
+  }
+
+  public Date getIfUnmodifiedSince() {
+    return getDateHeader("If-Unmodified-Since");
+  }
+
+  private void get_ccp() {
+    String cc = getCacheControl();
+    if (cc != null) {
+      CacheControlParser ccparser = 
+        new CacheControlParser(getCacheControl());
+      for(String directive : ccparser) {
+        directive = directive.toLowerCase();
+        if (directive.equals("max-age")) {
+          maxage = Long.parseLong(ccparser.getValue(directive));
+        } else if (directive.equals("max-stale")) {
+          maxstale = Long.parseLong(ccparser.getValue(directive));
+        } else if (directive.equals("min-fresh")) {
+          minfresh = Long.parseLong(ccparser.getValue(directive));
+        } else if (directive.equals("no-cache")) {
+          nocache = true;
+        } else if (directive.equals("no-store")) {
+          nostore = true;
+        } else if (directive.equals("no-transform")) {
+          notransform = true;
+        }
+      }
+    }
+  }
+  
+  public long getMaxAge() {
+    return maxage;
+  }
+
+  public long getMaxStale() {
+    return maxstale;
+  }
+
+  public long getMinFresh() {
+    return minfresh;
+  }
+
+  public boolean getNoCache() {
+    return nocache;
+  }
+
+  public boolean getNoStore() {
+    return nostore;
+  }
+
+  public boolean getNoTransform() {
+    return notransform;
   }
 
 }



Mime
View raw message