abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r438533 - in /incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server: ./ exceptions/ impl/ servlet/ target/ util/
Date Wed, 30 Aug 2006 16:27:03 GMT
Author: jmsnell
Date: Wed Aug 30 09:26:59 2006
New Revision: 438533

URL: http://svn.apache.org/viewvc?rev=438533&view=rev
Log:
Continued work on the server implementation.

 * Refactor the new Target to be a bit more flexible.  TargetResolver and Target
   are now interfaces in the org.apache.abdera.server.target package.  Specific
   deployments of the AbderaServlet can specify a TargetResolver implementation.
 
 * RegexTargetResolver and RegexTarget implementation for specifying targets 
   based on regular expression matching
   
 * RequestHandlerFactory ... pass in AbderaServer when creating a RequestHandler
 
 * RequestContext ... Method to get the resolved Target for this request
 
 * AbderaServerException ... Constructors and methods for setting the content of
   the error response from a string, URL or other DataSource
   
 * Rename the old BaseRequestHandler and BaseResponseContext to 
   AbstractRequestHandler and AbstractResponseContext
   
 * Create a new BaseResponseContext that extends AbstractResponseContext and 
   handles the details of returning Feed Object Model objects (e.g. entry, feed,
   and service documents)
   
 * Create a new EmptyResponseContext for returning empty responses
 
 * Abdera Servlet... resolve the TargetResolver from the Servlet init params
   or abderaconfiguration... pull the RequestHandlerFactory from the init
   params or abderaconfiguration.  Store both the TargetResolver and
   RequestHandlerFactory in the servlet context once resolved. Don't return
   a customized status text message (for now). 
   
 * ResourceType... rename "INTROSPECTION" to "SERVICE" per a change in the 
   APP spec.  "Introspection docs" are now referred to as "Service docs"

More to come

Added:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/AbstractRequestHandler.java
      - copied, changed from r438108, 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/impl/AbstractResponseContext.java
      - copied, changed from r438108, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/EmptyResponseContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/Target.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/TargetResolver.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/RegexTargetResolver.java
      - copied, changed from r438108, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/Target.java
Removed:
    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/util/Target.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/RequestHandlerFactory.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/exceptions/AbderaServerException.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.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
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/ResourceType.java

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=438533&r1=438532&r2=438533&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
Wed Aug 30 09:26:59 2006
@@ -18,12 +18,14 @@
 package org.apache.abdera.server;
 
 import org.apache.abdera.Abdera;
+import org.apache.abdera.server.target.TargetResolver;
 import org.apache.abdera.util.ServiceUtil;
 
 public class AbderaServer implements ServerConstants {
   
   private Abdera abdera = null;
   private RequestHandlerFactory handlerFactory = null;
+  private TargetResolver targetResolver = null;
   
   public AbderaServer() {
     abdera = new Abdera();
@@ -33,15 +35,29 @@
     this.abdera = abdera;
   }
   
-  public RequestHandlerFactory newRequestHandlerFactory() {
+  public Abdera getAbdera() {
+    return abdera;
+  }
+  
+  public RequestHandlerFactory newRequestHandlerFactory(String _default) {
     return (RequestHandlerFactory) ServiceUtil.newInstance(
-      HANDLER_FACTORY, "", abdera);
+      HANDLER_FACTORY, (_default != null) ? _default : "", abdera);
   }
   
-  public RequestHandlerFactory getRequestHandlerFactory() {
+  public RequestHandlerFactory getRequestHandlerFactory(String _default) {
     if (handlerFactory == null)
-      handlerFactory = newRequestHandlerFactory();
+      handlerFactory = newRequestHandlerFactory(_default);
     return handlerFactory;
   }
   
+  public TargetResolver newTargetResolver(String _default) {
+    return (TargetResolver) ServiceUtil.newInstance(
+      TARGET_RESOLVER, (_default != null) ? _default : "", abdera);
+  }
+  
+  public TargetResolver getTargetResolver(String _default) {
+    if (targetResolver == null)
+      targetResolver = newTargetResolver(_default);
+    return targetResolver;
+  }
 }

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=438533&r1=438532&r2=438533&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
Wed Aug 30 09:26:59 2006
@@ -23,7 +23,11 @@
 import java.util.Date;
 import java.util.List;
 
+import org.apache.abdera.server.target.Target;
+
 public interface RequestContext {
+  
+  Target getTarget();
   
   /**
    * Returns the method 

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/RequestHandlerFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/RequestHandlerFactory.java?rev=438533&r1=438532&r2=438533&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/RequestHandlerFactory.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/RequestHandlerFactory.java
Wed Aug 30 09:26:59 2006
@@ -22,6 +22,7 @@
 public interface RequestHandlerFactory {
   
   RequestHandler newRequestHandler(
+    AbderaServer abderaServer,
     RequestContext requestContext) 
       throws AbderaServerException;
   

Modified: 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=438533&r1=438532&r2=438533&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ServerConstants.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/ServerConstants.java
Wed Aug 30 09:26:59 2006
@@ -25,6 +25,11 @@
   public static final String HANDLER_FACTORY = 
     "org.apache.abdera.server.RequestHandlerFactory";
   
+  public static final String TARGET_RESOLVER = 
+    "org.apache.abdera.server.target.TargetResolver";
+  
   public static final String X_OVERRIDE_HEADER = 
     "X-HTTP-Method-Override";
+  
+  public static final String[] EMPTY = new String[0];
 }

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=438533&r1=438532&r2=438533&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
Wed Aug 30 09:26:59 2006
@@ -38,7 +38,7 @@
 
 import org.apache.abdera.model.Base;
 import org.apache.abdera.server.ResponseContext;
-import org.apache.abdera.server.impl.BaseResponseContext;
+import org.apache.abdera.server.impl.AbstractResponseContext;
 import org.apache.abdera.util.AbderaDataSource;
 import org.apache.axiom.attachments.ByteArrayDataSource;
 
@@ -98,6 +98,26 @@
     this(code.getCode(),null);
   }
   
+  public AbderaServerException(Code code, String text, String body) {
+    this(code, text);
+    setDataSource(body);
+  }
+  
+  public AbderaServerException(Code code, String text, URL body) {
+    this(code, text);
+    setDataSource(body);
+  }
+  
+  public <T extends Base>AbderaServerException(Code code, String text, T body) {
+    this(code, text);
+    setDataSource(body);
+  }
+  
+  public AbderaServerException(Code code, String text, DataSource body) {
+    this(code,text);
+    setDataSource(body);
+  }
+  
   public AbderaServerException(Code code, String text) {
     this(code.getCode(), text);
   }
@@ -286,7 +306,7 @@
   }
   
   protected static class ExceptionResponseContext 
-    extends BaseResponseContext {
+    extends AbstractResponseContext {
 
     private Throwable t = null;
     private long len = -1;

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/AbstractRequestHandler.java
(from r438108, 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/AbstractRequestHandler.java?p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/AbstractRequestHandler.java&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseRequestHandler.java&r1=438108&r2=438533&rev=438533&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/AbstractRequestHandler.java
Wed Aug 30 09:26:59 2006
@@ -20,17 +20,18 @@
 import org.apache.abdera.server.RequestContext;
 import org.apache.abdera.server.RequestHandler;
 import org.apache.abdera.server.ResponseContext;
+import org.apache.abdera.server.ServerConstants;
 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.util.ResourceType;
 
-public abstract class BaseRequestHandler 
-  implements RequestHandler {
+public abstract class AbstractRequestHandler 
+  implements RequestHandler, ServerConstants {
 
   protected ResourceType resourceType = ResourceType.UNKNOWN;
   
-  public BaseRequestHandler() {}
+  public AbstractRequestHandler() {}
   
   public ResponseContext invoke(
     RequestContext requestContext)
@@ -42,7 +43,7 @@
       checkModified(requestContext);
       checkRequest(requestContext);
       checkCache(requestContext,response,getCacheKey());
-      internalInvoke(requestContext, response);
+      response = internalInvoke(requestContext, response);
       if (response != null)
         return response;
       else
@@ -51,6 +52,7 @@
     } catch (AbderaServerException ase) {
       throw ase;
     } catch (Throwable t) {
+      t.printStackTrace();
       String message = t.getMessage();
       if (message == null || message.length() == 0)
         message = "Unknown Server Exception";
@@ -136,12 +138,13 @@
    * allowable methods on a particular type of resource
    */
   protected String[] getAllowedMethods(ResourceType type) {
+    if (type == null) return EMPTY;
     switch (type) {
       case COLLECTION:    return new String[] { "GET", "POST", "HEAD", "OPTIONS" };
       case ENTRY:         return new String[] { "GET", "HEAD", "OPTIONS" };
       case ENTRY_EDIT:    return new String[] { "GET", "DELETE", "PUT", "HEAD", "OPTIONS"
};
       case MEDIA_EDIT:    return new String[] { "GET", "DELETE", "PUT", "HEAD", "OPTIONS"
};
-      case INTROSPECTION: return new String[] { "GET", "HEAD", "OPTIONS" };
+      case SERVICE: return new String[] { "GET", "HEAD", "OPTIONS" };
       default:            return new String[] { "GET", "HEAD", "OPTIONS" };
     }
   }

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/AbstractResponseContext.java
(from r438108, 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/AbstractResponseContext.java?p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/AbstractResponseContext.java&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.java&r1=438108&r2=438533&rev=438533&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/AbstractResponseContext.java
Wed Aug 30 09:26:59 2006
@@ -30,7 +30,7 @@
 
 import org.apache.abdera.server.ResponseContext;
 
-public abstract class BaseResponseContext 
+public abstract class AbstractResponseContext 
   implements ResponseContext {
 
   protected final static byte NOCACHE = 1;

Modified: 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=438533&r1=438532&r2=438533&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/BaseResponseContext.java
Wed Aug 30 09:26:59 2006
@@ -17,417 +17,74 @@
 */
 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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
 
 import javax.activation.MimeType;
 import javax.activation.MimeTypeParseException;
 
-import org.apache.abdera.server.ResponseContext;
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
 
-public abstract class BaseResponseContext 
-  implements ResponseContext {
+public class BaseResponseContext<T extends Base> 
+  extends AbstractResponseContext {
 
-  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];
+  private T base = null;
+  private boolean chunked = true;
   
-  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 BaseResponseContext(T base) {
+    this.base = base;
+    setStatus(200);
+    setStatusText("OK");
   }
   
-  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 BaseResponseContext(T base, boolean chunked) {
+    this(base);
+    this.chunked = chunked;
   }
   
-  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 T getBase() {
+    return base;
   }
   
-  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 boolean hasEntity() {
+    return (base != null);
   }
 
-  public List<Object> getHeaders(String name) {
-    Map<String,List<Object>> headers = getHeaders();
-    return headers.get(name);
+  public void writeTo(OutputStream out) throws IOException {
+    if (hasEntity()) base.writeTo(out);
   }
 
-  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);
+  @Override
+  public MimeType getContentType() 
+    throws MimeTypeParseException {
+      MimeType t = super.getContentType();
+      if (t == null) {
+        Document doc = null;
+        if (base instanceof Document) {
+          doc = (Document) base;
+        } else if (base instanceof Element) {
+          Element el = (Element) base;
+          doc = el.getDocument();
+        }
+        t = (doc != null) ? doc.getContentType() : null;
       }
-      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);
+      return t;
   }
 
+  @Override
   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);
+    long len = super.getContentLength();
+    if (hasEntity() && len == -1 && !chunked) {
+      try {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        base.writeTo(out);
+        len = out.size();
+        super.setContentLength(len);
+      } catch (Exception e) {}
     }
-    setAllow(buf.toString());
+    return len;
   }
 }

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/EmptyResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/EmptyResponseContext.java?rev=438533&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/EmptyResponseContext.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/impl/EmptyResponseContext.java
Wed Aug 30 09:26:59 2006
@@ -0,0 +1,36 @@
+/*
+* 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.io.IOException;
+import java.io.OutputStream;
+
+public class EmptyResponseContext extends AbstractResponseContext {
+
+  public EmptyResponseContext(int status) {
+    setStatus(status);
+  }
+  
+  public boolean hasEntity() {
+    return false;
+  }
+
+  public void writeTo(OutputStream out) throws IOException {
+  }
+
+}

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=438533&r1=438532&r2=438533&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
Wed Aug 30 09:26:59 2006
@@ -22,6 +22,7 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -35,6 +36,7 @@
 import org.apache.abdera.server.ResponseContext;
 import org.apache.abdera.server.ServerConstants;
 import org.apache.abdera.server.exceptions.AbderaServerException;
+import org.apache.abdera.server.target.TargetResolver;
 
 public class AbderaServlet 
   extends HttpServlet 
@@ -61,13 +63,45 @@
   private RequestContext getRequestContext(HttpServletRequest request) {
     RequestContext context = 
       (RequestContext) request.getAttribute(REQUESTCONTEXT);
+    TargetResolver resolver = getTargetResolver();
     if (context == null) {
-      context = new ServletRequestContext(abdera,request);
+      context = new ServletRequestContext(abdera,resolver,request);
       request.setAttribute(REQUESTCONTEXT, context);
     }
     return context;
   }
   
+  
+  private RequestHandlerFactory getRequestHandlerFactory() {
+    ServletContext context = getServletContext();
+    synchronized(context) {
+      RequestHandlerFactory factory = 
+        (RequestHandlerFactory) context.getAttribute(
+        HANDLER_FACTORY);
+      if (factory == null) {
+        String s = getServletConfig().getInitParameter(HANDLER_FACTORY);
+        factory = abderaServer.newRequestHandlerFactory(s);
+        context.setAttribute(HANDLER_FACTORY, factory);
+      }
+      return factory;
+    }
+  }
+  
+  private TargetResolver getTargetResolver() {
+    ServletContext context = getServletContext();
+    synchronized(context) {
+      TargetResolver resolver = 
+        (TargetResolver) context.getAttribute(
+          TARGET_RESOLVER);
+      if (resolver == null) {
+        String s = getServletConfig().getInitParameter(TARGET_RESOLVER);
+        resolver = abderaServer.newTargetResolver(s);
+        context.setAttribute(TARGET_RESOLVER, resolver);
+      }
+      return resolver;
+    }
+  }
+  
   @Override
   protected void service(
     HttpServletRequest request, 
@@ -77,14 +111,15 @@
     ResponseContext responseContext = null;
     RequestHandler handler = null;
     try {
-      RequestHandlerFactory factory = abderaServer.newRequestHandlerFactory();
+      RequestHandlerFactory factory = getRequestHandlerFactory();
       if (factory != null)
-        handler = factory.newRequestHandler(requestContext);
+        handler = factory.newRequestHandler(abderaServer,requestContext);
       if (handler != null) {
         responseContext = handler.invoke(requestContext);
       } else {
         throw new AbderaServerException(
-          AbderaServerException.Code.NOTFOUND);
+          AbderaServerException.Code.NOTFOUND, 
+          "Handler Not Found", "");
       }
     } catch (AbderaServerException exception) {
       responseContext = exception;
@@ -99,10 +134,7 @@
     ResponseContext context) 
       throws IOException, ServletException {
     if (context != null) {
-      if (context.getStatusText() != null)
-        response.sendError(context.getStatus(), context.getStatusText());
-      else 
-        response.setStatus(context.getStatus());
+      response.setStatus(context.getStatus());
       long cl = context.getContentLength();
       String cc = context.getCacheControl();
       if (cl > -1) response.setHeader("Content-Length", Long.toString(cl));

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=438533&r1=438532&r2=438533&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
Wed Aug 30 09:26:59 2006
@@ -32,10 +32,13 @@
 import org.apache.abdera.protocol.util.CacheControlParser;
 import org.apache.abdera.server.RequestContext;
 import org.apache.abdera.server.ServerConstants;
+import org.apache.abdera.server.target.Target;
+import org.apache.abdera.server.target.TargetResolver;
 
 public class ServletRequestContext 
   implements RequestContext, ServerConstants {
   
+  private Target target = null;
   private Abdera abdera = null;
   private HttpServletRequest servletRequest = null;
   private long maxage = -1;
@@ -48,10 +51,16 @@
     
   public ServletRequestContext(
     Abdera abdera,
+    TargetResolver resolver,
     HttpServletRequest request) {
       this.abdera = abdera;
       this.servletRequest = request;
       get_ccp();
+      target = resolver.resolve(getUri().toString());
+  }
+  
+  public Target getTarget() {
+    return target;
   }
   
   public String getMethod() {
@@ -68,7 +77,8 @@
       StringBuffer buf = 
         new StringBuffer(
           servletRequest.getRequestURI());
-      if (servletRequest.getQueryString() != null)
+      String qs = servletRequest.getQueryString();
+      if (qs != null && qs.length() != 0)
         buf.append("?" + servletRequest.getQueryString());
       uri = new URI(buf.toString());
     } catch (URISyntaxException e) {}

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/Target.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/Target.java?rev=438533&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/Target.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/Target.java
Wed Aug 30 09:26:59 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.target;
+
+import org.apache.abdera.server.util.ResourceType;
+
+public interface Target {
+
+  ResourceType getResourceType();
+  
+  String getValue(int index);
+  
+  boolean hasValue(int index);
+  
+}

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/TargetResolver.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/TargetResolver.java?rev=438533&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/TargetResolver.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/target/TargetResolver.java
Wed Aug 30 09:26:59 2006
@@ -0,0 +1,24 @@
+/*
+* 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.target;
+
+public interface TargetResolver {
+
+  Target resolve(String uri);
+  
+}

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/RegexTargetResolver.java
(from r438108, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/Target.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/RegexTargetResolver.java?p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/RegexTargetResolver.java&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/Target.java&r1=438108&r2=438533&rev=438533&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/Target.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/RegexTargetResolver.java
Wed Aug 30 09:26:59 2006
@@ -22,6 +22,9 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.abdera.server.target.Target;
+import org.apache.abdera.server.target.TargetResolver;
+
 /**
  * <p>Provides a utility class helpful for determining which type of resource
  * the client is requesting.  Each resource type (e.g. service doc, collection,
@@ -32,29 +35,29 @@
  * also specifies the Resource Type.</p>
  * 
  * <pre>
- *  Target target = new Target();
- *  target.addPattern(ResourceType.INTROSPECTION, "/atom");
- *  target.addPattern(ResourceType.COLLECTION, "/atom/([^/#?]+)");
- *  target.addPattern(ResourceType.ENTRY, "/atom/([^/#?]+)/([^/#?]+)");
- *  target.addPattern(ResourceType.ENTRY_EDIT, "/atom/([^/#?]+)/([^/#?]+)\\?edit");
- *  target.addPattern(ResourceType.MEDIA,"/atom/([^/#?]+)/([^/#?]+)\\?media");
- *  target.addPattern(ResourceType.MEDIA_EDIT,"/atom/([^/#?]+)/([^/#?]+)\\?edit-media");
+ *  RegexTargetResolver tr = new RegexTargetResolver();
+ *  tr.addPattern(ResourceType.INTROSPECTION, "/atom");
+ *  tr.addPattern(ResourceType.COLLECTION, "/atom/([^/#?]+)");
+ *  tr.addPattern(ResourceType.ENTRY, "/atom/([^/#?]+)/([^/#?]+)");
+ *  tr.addPattern(ResourceType.ENTRY_EDIT, "/atom/([^/#?]+)/([^/#?]+)\\?edit");
+ *  tr.addPattern(ResourceType.MEDIA,"/atom/([^/#?]+)/([^/#?]+)\\?media");
+ *  tr.addPattern(ResourceType.MEDIA_EDIT,"/atom/([^/#?]+)/([^/#?]+)\\?edit-media");
  *  
- *  TargetMatcher tm = target.getTargetMatcher("/atom/foo");
- *  System.out.println(tm.getType());
- *  System.out.println(tm.getToken(1));  // foo
+ *  Target target = tr.resolve("/atom/foo");
+ *  System.out.println(target.getResourceType());
+ *  System.out.println(targer.getValue(1));  // foo
  * </pre>
  *  
  */
-public class Target {
+public class RegexTargetResolver implements TargetResolver {
 
   private Map<ResourceType,Pattern> patterns = null;
   
-  public Target() {
+  public RegexTargetResolver() {
     this.patterns = new HashMap<ResourceType,Pattern>();
   }
   
-  public Target(Map<ResourceType,String> patterns) {
+  public RegexTargetResolver(Map<ResourceType,String> patterns) {
     this.patterns = new HashMap<ResourceType,Pattern>();
     for (ResourceType type : patterns.keySet()) {
       String p = patterns.get(type);
@@ -68,31 +71,31 @@
     this.patterns.put(type, p);
   }
   
-  public TargetMatcher getTargetMatcher(String path_info) {
+  public Target resolve(String path_info) {
     if (patterns == null) return null;
     for (ResourceType type : patterns.keySet()) {
       Pattern pattern = patterns.get(type);
       Matcher matcher = pattern.matcher(path_info);
-      if (matcher.matches()) return new TargetMatcher(type, matcher);
+      if (matcher.matches()) return new RegexTarget(type, matcher);
     }
     return null;
   }
   
-  public static class TargetMatcher {
+  public static class RegexTarget implements Target {
     
     Matcher matcher = null;
     ResourceType type = ResourceType.UNKNOWN;
     
-    TargetMatcher(ResourceType type, Matcher matcher) {
+    RegexTarget(ResourceType type, Matcher matcher) {
       this.type = type;
       this.matcher = matcher;
     }
     
-    public ResourceType getType() {
+    public ResourceType getResourceType() {
       return this.type;
     }
     
-    public String getToken(int token) {
+    public String getValue(int token) {
       try {
         return this.matcher.group(token);
       } catch (IndexOutOfBoundsException e) {
@@ -100,8 +103,8 @@
       }
     }
     
-    public boolean hasToken(int token) {
-      return getToken(token) != null;
+    public boolean hasValue(int token) {
+      return getValue(token) != null;
     }
   }
   

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/ResourceType.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/ResourceType.java?rev=438533&r1=438532&r2=438533&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/ResourceType.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/util/ResourceType.java
Wed Aug 30 09:26:59 2006
@@ -20,7 +20,7 @@
 public enum ResourceType {
 
   UNKNOWN, 
-  INTROSPECTION, 
+  SERVICE, 
   COLLECTION, 
   ENTRY, 
   ENTRY_EDIT, 



Mime
View raw message