abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r555349 [2/2] - in /incubator/abdera/java/trunk: build/ examples/src/main/java/org/apache/abdera/examples/appserver/ protocol/src/main/java/org/apache/abdera/protocol/ protocol/src/main/java/org/apache/abdera/protocol/util/ security/ securi...
Date Wed, 11 Jul 2007 18:07:45 GMT
Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java (from r553708, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractProvider.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractProvider.java&r1=553708&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractProvider.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractProvider.java Wed Jul 11 11:07:36 2007
@@ -15,10 +15,8 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.provider;
+package org.apache.abdera.protocol.server.impl;
 
-import java.io.CharArrayWriter;
-import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -27,27 +25,40 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Categories;
 import org.apache.abdera.model.Content;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.ExtensibleElement;
+import org.apache.abdera.protocol.server.Provider;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.util.EncodingUtil;
 import org.apache.abdera.util.MimeTypeHelper;
 import org.apache.abdera.i18n.iri.IRI;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public abstract class AbstractProvider 
   implements Provider {
 
+  private final static Log log = LogFactory.getLog(AbstractProvider.class);
+  
   private static final String NS        = "http://incubator.apache.org/abdera";
   private static final String PFX       = "a";
   private static final QName ERROR         = new QName(NS, "error", PFX);
   private static final QName CODE          = new QName(NS, "code", PFX);
   private static final QName MESSAGE       = new QName(NS, "message", PFX);
-  private static final QName TRACE         = new QName(NS, "trace", PFX);
+
+  
+  protected int defaultpagesize = 10;
   
-  protected boolean isDebug() {
-    return false;
+  protected AbstractProvider() {}
+  
+  protected AbstractProvider(int defaultpagesize) {
+    this.defaultpagesize = defaultpagesize;
   }
   
   protected Document createErrorDocument(
@@ -55,18 +66,13 @@
     int code, 
     String message, 
     Throwable e) {
+      if (e != null) log.debug("Creating error document - " + code + ", " + message, e);
+      else log.debug("Creating error document - " + code + ", " + message);
       Document doc = abdera.getFactory().newDocument();
       ExtensibleElement root = 
         (ExtensibleElement) abdera.getFactory().newElement(ERROR, doc);
       root.addSimpleExtension(CODE, (code != -1) ? String.valueOf(code) : "");
       root.addSimpleExtension(MESSAGE, (message != null) ? message : "");
-      if (isDebug()) {
-        if (e != null) {
-          CharArrayWriter out = new CharArrayWriter();
-          e.printStackTrace(new PrintWriter(out));
-          root.addSimpleExtension(TRACE, out.toString());
-        }
-      }
       return doc;
   }
 
@@ -78,6 +84,7 @@
     RequestContext request,
     String reason,
     Throwable t) {
+      log.debug("Server error");
       return returnBase(
         createErrorDocument(
           abdera, 500, 
@@ -92,6 +99,7 @@
     Abdera abdera,
     RequestContext request,
     String reason) {
+      log.debug("Unauthorized");
       return returnBase(
         createErrorDocument(
           abdera, 401, 
@@ -106,6 +114,7 @@
     Abdera abdera,
     RequestContext request,
     String reason) {
+      log.debug("Forbidden");
       return returnBase(
         createErrorDocument(
           abdera, 403, 
@@ -120,6 +129,7 @@
     Abdera abdera,
     RequestContext request,
     String reason) {
+    log.debug("Unknown");
     return returnBase(
       createErrorDocument(
         abdera, 404, 
@@ -135,6 +145,7 @@
     RequestContext request,
     String reason,
     String... methods) {
+      log.debug("Not Allowed"); 
       BaseResponseContext resp = 
         (BaseResponseContext)returnBase(
           createErrorDocument(
@@ -152,6 +163,7 @@
     Abdera abdera,
     RequestContext request,
     String reason) {
+      log.debug("Bad Request");
       return returnBase(
         createErrorDocument(
           abdera, 400, 
@@ -166,6 +178,7 @@
     Abdera abdera,
     RequestContext request,
     String reason) {
+    log.debug("Conflict");
       return returnBase(
         createErrorDocument(
           abdera, 409, 
@@ -180,6 +193,7 @@
     Abdera abdera,
     RequestContext request,
     String reason) {
+      log.debug("Unavailable");
       return returnBase(
         createErrorDocument(
           abdera, 503, 
@@ -191,6 +205,7 @@
     Abdera abdera, 
     RequestContext request,
     String reason) {
+      log.debug("Not modified");
       EmptyResponseContext rc = new EmptyResponseContext(304);
       rc.setStatusText(reason);
       return rc;
@@ -200,6 +215,7 @@
     Abdera abdera, 
     RequestContext request,
     String reason) {
+      log.debug("Precondition failed");
       return returnBase(
         createErrorDocument(
           abdera, 412, 
@@ -214,6 +230,7 @@
     Abdera abdera,
     RequestContext request,
     String reason) {
+      log.debug("Not supported");
       return returnBase(
         createErrorDocument(
           abdera, 415, 
@@ -228,6 +245,7 @@
     Abdera abdera,
     RequestContext request,
     String reason) {
+      log.debug("Locked");
       return returnBase(
         createErrorDocument(
           abdera, 423,
@@ -243,18 +261,17 @@
     Base base, 
     int status,
     Date lastModified) {
+      log.debug("Returning Abdera document");
       BaseResponseContext response = new BaseResponseContext(base);
       response.setStatus(status);
       if (lastModified != null) response.setLastModified(lastModified);
       response.setContentType(MimeTypeHelper.getMimeType(base));
-      
       Document doc = base instanceof Document ? (Document)base : ((Element)base).getDocument();
       if (doc.getEntityTag() != null) {
         response.setEntityTag(doc.getEntityTag());
       } else if (doc.getLastModified() != null) {
         response.setLastModified(doc.getLastModified());
       }
-      
       return response;
   }
 
@@ -264,37 +281,44 @@
    */
   protected String sanitizeSlug(String slug) {
     if (slug == null) throw new IllegalArgumentException("Slug cannot be null");
-    return EncodingUtil.sanitize(slug);
+    String sanitized = EncodingUtil.sanitize(slug);
+    log.debug("Sanitized slug '" + slug + "' to '" + sanitized + "'");
+    return sanitized;
   }
 
-  protected abstract int getDefaultPageSize();
+  protected int getDefaultPageSize() {
+    log.debug("Getting default page size: " + defaultpagesize);
+    return defaultpagesize;
+  }
   
 
   protected int getPageSize(
     RequestContext request, 
     String pagesizeparam) {
       int max = getDefaultPageSize();
+      int size = max;
       try {
         String _ps = request.getParameter(pagesizeparam);
-        return (_ps != null) ? 
+        size = (_ps != null) ? 
           Math.min(Math.max(Integer.parseInt(_ps),0),max) : max;
-      } catch (Exception e) {
-        return max;
-      }
+      } catch (Exception e) {}
+      log.debug("Getting page size: " + size);
+      return size;
   }
   
   protected int getOffset(
     RequestContext request, 
     String pageparam, 
     int pageSize) {
+      int offset = 0;
       try {
         String _page = request.getParameter(pageparam);
         int page =(_page != null) ? Integer.parseInt(_page) : 1;
         page = Math.max(page, 1) - 1;
-        return pageSize * page;
-      } catch (Exception e) {
-        return 0;
-      }
+        offset = pageSize * page;
+      } catch (Exception e) {}
+      log.debug("Getting offset: " + offset);
+      return offset;
   }
   
   /**
@@ -319,12 +343,15 @@
             content.getContentType() == Content.Type.MEDIA || 
             content.getContentType() == Content.Type.XML) &&
             entry.getSummary() == null) {
+          log.debug("Checking valid entry: " + false);
           return false;
         }
       }
     } catch (Exception e) {
+      log.debug("Checking valid entry: " + false);
       return false;
     }
+    log.debug("Checking valid entry: " + true);
     return true;
   }
   
@@ -347,7 +374,9 @@
       ignore.add(org.apache.abdera.util.Constants.XHTML_NS);
       ignore.add(org.apache.abdera.util.Constants.XML_NS);
       checkEntryAddAdditionalNamespaces(ignore);
-      return (checkElement(entry,ignore));
+      boolean answer = checkElement(entry,ignore);
+      log.debug("Checking entry namespaces: " + answer);
+      return answer;
   }
   
   /**
@@ -383,5 +412,145 @@
   
   protected IRI resolveBase(RequestContext request) {
     return request.getBaseUri().resolve(request.getUri());
+  }
+
+  public ResponseContext request(RequestContext request) {
+    TargetType type = request.getTarget().getType();
+    String method = request.getMethod();
+    log.debug("Target type: " + type);
+    log.debug("Target id: " + request.getTarget().getIdentity());
+    log.debug("Method: " + method);
+    if (method.equals("GET")) {
+      if (type == TargetType.TYPE_SERVICE) {
+        return getService(request);
+      }
+      if (type == TargetType.TYPE_COLLECTION) {
+        return getFeed(request);
+      }
+      if (type == TargetType.TYPE_ENTRY) {
+        return getEntry(request);
+      }
+      if (type == TargetType.TYPE_MEDIA) {
+        return getMedia(request);
+      }
+      if (type == TargetType.TYPE_CATEGORIES) {
+        return getCategories(request);
+      }
+    }
+    else if (method.equals("HEAD")) {
+      if (type == TargetType.TYPE_SERVICE) {
+        return getService(request);
+      }
+      if (type == TargetType.TYPE_COLLECTION) {
+        return getFeed(request);
+      }
+      if (type == TargetType.TYPE_ENTRY) {
+        return getEntry(request);
+      }
+      if (type == TargetType.TYPE_MEDIA) {
+        return getMedia(request);
+      }
+      if (type == TargetType.TYPE_CATEGORIES) {
+        return getCategories(request);
+      }
+    }
+    else if (method.equals("POST")) {
+      if (type == TargetType.TYPE_COLLECTION) {
+        return createEntry(request);
+      }
+      if (type == TargetType.TYPE_ENTRY) {
+        return entryPost(request);
+      }
+      if (type == TargetType.TYPE_MEDIA) {
+        return mediaPost(request);
+      }
+    }
+    else if (method.equals("PUT")) {
+      if (type == TargetType.TYPE_ENTRY) {
+        return updateEntry(request);
+      }
+      if (type == TargetType.TYPE_MEDIA) {
+        return updateMedia(request);
+      }
+    }
+    else if (method.equals("DELETE")) {
+      if (type == TargetType.TYPE_ENTRY) {
+        return deleteEntry(request);
+      }
+      if (type == TargetType.TYPE_MEDIA) {
+        return deleteMedia(request);
+      }
+    } 
+    else if (method.equals("OPTIONS")) {
+      AbstractResponseContext rc = new EmptyResponseContext(200);
+      rc.addHeader("Allow", combine(getAllowedMethods(type)));
+      return rc;
+    }
+    return notallowed(
+      request.getAbdera(), 
+      request, 
+      "Not Allowed", 
+      getAllowedMethods(
+        request.getTarget().getType()));
+  }
+  
+  public String[] getAllowedMethods(TargetType type) {
+    if (type == null)                       return new String[0];
+    if (type == TargetType.TYPE_COLLECTION) return new String[] { "GET", "POST", "HEAD", "OPTIONS" };
+    if (type == TargetType.TYPE_CATEGORIES) return new String[] { "GET", "HEAD", "OPTIONS" };
+    if (type == TargetType.TYPE_ENTRY)      return new String[] { "GET", "DELETE", "PUT", "POST", "HEAD", "OPTIONS" };
+    if (type == TargetType.TYPE_MEDIA)      return new String[] { "GET", "DELETE", "PUT", "POST", "HEAD", "OPTIONS" };
+    if (type == TargetType.TYPE_SERVICE)    return new String[] { "GET", "HEAD", "OPTIONS" };
+    return new String[] { "GET", "HEAD", "OPTIONS" };
+  }
+  
+  protected String combine(String... vals) {
+    StringBuffer buf = new StringBuffer();
+    for(String val : vals) {
+      if (buf.length() > 0) buf.append(", ");
+      buf.append(val);
+    }
+    return buf.toString();
+  }
+  
+  public ResponseContext entryPost(
+    RequestContext request) {
+      return notallowed(
+        request.getAbdera(), 
+        request, 
+        "Not Allowed", 
+        getAllowedMethods(
+          request.getTarget().getType()));
+  }
+    
+  public ResponseContext mediaPost(
+    RequestContext request) {
+      return notallowed(
+        request.getAbdera(), 
+        request, 
+        "Not Allowed", 
+        getAllowedMethods(
+          request.getTarget().getType()));
+  } 
+
+  public ResponseContext getCategories(
+    RequestContext request) {
+      Categories cats = request.getAbdera().newCategories();
+      return returnBase(cats.getDocument(), 200, new Date());
+  }
+  
+  public ResponseContext deleteMedia(
+    RequestContext request) {
+      throw new UnsupportedOperationException();
+  }
+    
+  public ResponseContext getMedia(
+    RequestContext request) {
+      throw new UnsupportedOperationException();
+  }
+  
+  public ResponseContext updateMedia(
+    RequestContext request) {
+      throw new UnsupportedOperationException();
   }
 }

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java (from r541117, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractRequestContext.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractRequestContext.java&r1=541117&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractRequestContext.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java Wed Jul 11 11:07:36 2007
@@ -15,9 +15,10 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.provider;
+package org.apache.abdera.protocol.server.impl;
 
 import java.io.IOException;
+import java.security.Principal;
 
 import javax.security.auth.Subject;
 
@@ -27,16 +28,23 @@
 import org.apache.abdera.parser.ParseException;
 import org.apache.abdera.parser.Parser;
 import org.apache.abdera.parser.ParserOptions;
+import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ServiceContext;
+import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.protocol.util.AbstractRequest;
 import org.apache.abdera.i18n.iri.IRI;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public abstract class AbstractRequestContext 
   extends AbstractRequest
   implements RequestContext {
 
+  private final static Log log = LogFactory.getLog(AbstractRequestContext.class);
+  
   protected final ServiceContext context;
   protected Subject subject;
+  protected Principal principal;
   protected Target target;
   protected final String method;
   protected final IRI requestUri;
@@ -53,16 +61,20 @@
       this.baseUri = baseUri;
       this.requestUri = requestUri;
   }
+  
+  public Abdera getAbdera() {
+    return context.getAbdera();
+  }
     
   @SuppressWarnings("unchecked")
   public synchronized <T extends Element>Document<T> getDocument()
     throws ParseException, 
            IOException {
+    log.debug("Parsing request document");
     if (document == null) {
       Abdera abdera = context.getAbdera();
       Parser parser = abdera.getParser();
-      ParserOptions options = parser.getDefaultParserOptions();
-      document = getDocument(parser, options);
+      document = getDocument(parser);
     } 
     return document;
   }
@@ -72,6 +84,7 @@
     Parser parser)
       throws ParseException, 
              IOException {
+    log.debug("Parsing request document");
     if (document == null) {
       ParserOptions options = parser.getDefaultParserOptions();
       document = getDocument(parser, options);
@@ -84,6 +97,7 @@
     ParserOptions options)
      throws ParseException, 
             IOException  {
+    log.debug("Parsing request document");
     if (document == null) {
       Abdera abdera = context.getAbdera();
       Parser parser = abdera.getParser();
@@ -98,6 +112,7 @@
     ParserOptions options) 
       throws ParseException, 
              IOException {
+    log.debug("Parsing request document");
     if (document == null) {
       return parser.parse(
         getInputStream(), 
@@ -124,6 +139,10 @@
   
   public Subject getSubject() {
     return subject;
+  }
+  
+  public Principal getPrincipal() {
+    return principal;
   }
 
   public Target getTarget() {

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java (from r547103, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbstractRequestHandler.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbstractRequestHandler.java&r1=547103&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbstractRequestHandler.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java Wed Jul 11 11:07:36 2007
@@ -15,7 +15,7 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.servlet;
+package org.apache.abdera.protocol.server.impl;
 
 import java.io.IOException;
 import java.io.OutputStream;
@@ -25,49 +25,48 @@
 
 import javax.activation.MimeType;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.server.Provider;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.RequestHandler;
+import org.apache.abdera.protocol.server.ResponseContext;
 import org.apache.abdera.protocol.server.ServiceContext;
-import org.apache.abdera.protocol.server.provider.EmptyResponseContext;
-import org.apache.abdera.protocol.server.provider.Provider;
-import org.apache.abdera.protocol.server.provider.ProviderManager;
-import org.apache.abdera.protocol.server.provider.RequestContext;
-import org.apache.abdera.protocol.server.provider.ResponseContext;
-import org.apache.abdera.protocol.server.provider.Target;
-import org.apache.abdera.protocol.server.provider.TargetType;
+import org.apache.abdera.protocol.server.Target;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 public abstract class AbstractRequestHandler 
   implements RequestHandler {
 
-  private static final Log logger = LogFactory.getLog(AbstractRequestHandler.class);
+  private static final Log log = LogFactory.getLog(AbstractRequestHandler.class);
   
   public void process(
     ServiceContext context, 
-    HttpServletRequest request,
+    RequestContext request,
     HttpServletResponse response) 
       throws IOException {
     
-    ProviderManager manager = context.getProviderManager();
-    RequestContext requestContext = getRequestContext(context,request);
-    Provider provider = manager.getProvider(requestContext);
-    
+    log.debug("Processing the request");
+    ItemManager<Provider> manager = context.getProviderManager();
+    Provider provider = manager.get(request);
+    log.debug("Using provider - " + provider);
     try {
-      if (preconditions(provider, requestContext, response)) {
-        output(response,process(provider, requestContext));
+      if (preconditions(provider, request, response)) {
+        output(response,provider.request(request));
       }
     } catch (Throwable e) {
-      logger.error("Error producing output", e);
+      log.error("Error producing output", e);
       try {
         output(response,new EmptyResponseContext(500));
       } catch (Exception ex) {
-        logger.error("Error outputting error", ex);
+        log.error("Error outputting error", ex);
         response.sendError(500);
       }
     } finally {
-      manager.release(provider);
+      log.debug("Releasing provider - " + provider);
+      if (provider != null) manager.release(provider);
     }
   }
   
@@ -88,20 +87,16 @@
       return false;
     }
     // Check The Method
-    if (!checkMethod(request)) {
+    if (!checkMethod(provider,request)) {
       notallowed(
         response, 
         request.getMethod(), 
-        getAllowedMethods(target.getType()));
+        provider.getAllowedMethods(target.getType()));
       return false;
     }
     return true;
   }
   
-  protected abstract ResponseContext process(
-    Provider provider, 
-    RequestContext request);
-  
   protected void output(
     HttpServletResponse response, 
     ResponseContext context) 
@@ -141,23 +136,16 @@
   }
   
   protected boolean checkMethod(
+    Provider provider,
     RequestContext context) 
       throws IOException {
     String method = context.getMethod();
     Target target = context.getTarget();
-    String[] methods = getAllowedMethods(target.getType());
+    String[] methods = provider.getAllowedMethods(target.getType());
     java.util.Arrays.sort(methods);
     return (java.util.Arrays.binarySearch(methods, method) >= 0);
   }
-
-  protected abstract String[] getAllowedMethods(TargetType type);
-  
-  protected RequestContext getRequestContext(
-    ServiceContext context, 
-    HttpServletRequest request) {
-      return new HttpServletRequestContext(context, request);
-  }
-  
+    
   protected void noprovider(HttpServletResponse response) throws IOException {
     response.sendError(500, "No Provider");
   }

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractResponseContext.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractResponseContext.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractResponseContext.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java Wed Jul 11 11:07:36 2007
@@ -15,9 +15,10 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.provider;
+package org.apache.abdera.protocol.server.impl;
 
 import java.util.ArrayList;
+import java.util.BitSet;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -25,7 +26,7 @@
 
 import org.apache.abdera.i18n.iri.Constants;
 import org.apache.abdera.i18n.iri.Escaping;
-import org.apache.abdera.protocol.server.provider.ResponseContext;
+import org.apache.abdera.protocol.server.ResponseContext;
 import org.apache.abdera.protocol.util.AbstractResponse;
 import org.apache.abdera.protocol.util.EncodingUtil;
 import org.apache.abdera.util.EntityTag;
@@ -61,6 +62,10 @@
     headers.put(name, values);
   }
   
+  public void setEscapedHeader(String name, BitSet mask, String value) {
+    setHeader(name,Escaping.encode(value, mask));
+  }
+  
   public void setHeader(String name, Object value) {
     Map<String,List<Object>> headers = getHeaders();
     List<Object> values = new ArrayList<Object>();
@@ -224,7 +229,7 @@
         slug.indexOf((char)13) > -1)
       throw new IllegalArgumentException(
         "The slug must not contain ASCII carriage return or linefeed characters");
-    setHeader("Slug", Escaping.encode(slug, Constants.ASCIISANSCRLF));
+    setEscapedHeader("Slug", Constants.ASCIISANSCRLF, slug);
   }
   
   public void setContentType(String type) {

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/AbstractServiceContext.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/AbstractServiceContext.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/AbstractServiceContext.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractServiceContext.java Wed Jul 11 11:07:36 2007
@@ -15,26 +15,30 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server;
+package org.apache.abdera.protocol.server.impl;
 
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.security.auth.Subject;
+
 import org.apache.abdera.Abdera;
-import org.apache.abdera.protocol.server.auth.SubjectResolver;
-import org.apache.abdera.protocol.server.provider.ProviderManager;
-import org.apache.abdera.protocol.server.provider.TargetResolver;
-import org.apache.abdera.protocol.server.servlet.RequestHandlerManager;
+import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.Provider;
+import org.apache.abdera.protocol.server.RequestHandler;
+import org.apache.abdera.protocol.server.ServiceContext;
+import org.apache.abdera.protocol.server.Target;
 
 public abstract class AbstractServiceContext 
   implements ServiceContext {
 
   protected Abdera abdera;
   protected Map<String,String> config;
-  protected ProviderManager providerManager;
-  protected RequestHandlerManager handlerManager;
-  protected SubjectResolver subjectResolver;
-  protected TargetResolver targetResolver;
+  protected ItemManager<Provider> providerManager;
+  protected ItemManager<RequestHandler> handlerManager;
+  protected Resolver<Subject> subjectResolver;
+  protected Resolver<Target> targetResolver;
   
   public synchronized void init(
     Abdera abdera, 

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonProviderManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonProviderManager.java?view=auto&rev=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonProviderManager.java (added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonProviderManager.java Wed Jul 11 11:07:36 2007
@@ -0,0 +1,45 @@
+/*
+* 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.protocol.server.impl;
+
+import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.server.Provider;
+
+public abstract class AbstractSingletonProviderManager 
+  implements ItemManager<Provider> {
+
+  protected Provider provider;
+  
+  public Provider get(Request request) {
+    if (provider == null) {
+      synchronized(this) {
+        provider = initProvider();
+      }
+    }
+    return provider;
+  }
+
+  protected abstract Provider initProvider();
+  
+  public void release(Provider provider) {
+    // nothing to release. subclasses could choose to do reference counting
+    // if they want
+  }
+
+}

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonRequestHandlerManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonRequestHandlerManager.java?view=auto&rev=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonRequestHandlerManager.java (added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractSingletonRequestHandlerManager.java Wed Jul 11 11:07:36 2007
@@ -0,0 +1,45 @@
+/*
+* 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.protocol.server.impl;
+
+import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.server.RequestHandler;
+
+public abstract class AbstractSingletonRequestHandlerManager 
+  implements ItemManager<RequestHandler> {
+
+  protected RequestHandler handler;
+  
+  public RequestHandler get(Request request) {
+    if (handler == null) {
+      synchronized(this) {
+        handler = initHandler();
+      }
+    }
+    return handler;
+  }
+
+  protected abstract RequestHandler initHandler();
+  
+  public void release(RequestHandler item) {
+    // nothing to release. subclasses could choose to do reference counting
+    // if they want
+  }
+
+}

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractTarget.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractTarget.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/AbstractTarget.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractTarget.java Wed Jul 11 11:07:36 2007
@@ -15,7 +15,11 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.provider;
+package org.apache.abdera.protocol.server.impl;
+
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.TargetType;
 
 public abstract class AbstractTarget 
   implements Target {
@@ -45,6 +49,10 @@
 
   public TargetType getType() {
     return type;
+  }
+  
+  public String toString() {
+    return getType() + " - " + getIdentity();
   }
 
   @Override

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/BaseResponseContext.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/BaseResponseContext.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/BaseResponseContext.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/BaseResponseContext.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/BaseResponseContext.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/BaseResponseContext.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/BaseResponseContext.java Wed Jul 11 11:07:36 2007
@@ -15,7 +15,7 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.provider;
+package org.apache.abdera.protocol.server.impl;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandler.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/DefaultRequestHandler.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandler.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/DefaultRequestHandler.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandler.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/DefaultRequestHandler.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandler.java Wed Jul 11 11:07:36 2007
@@ -15,103 +15,14 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.servlet;
+package org.apache.abdera.protocol.server.impl;
 
-import org.apache.abdera.protocol.server.provider.AbstractResponseContext;
-import org.apache.abdera.protocol.server.provider.EmptyResponseContext;
-import org.apache.abdera.protocol.server.provider.Provider;
-import org.apache.abdera.protocol.server.provider.RequestContext;
-import org.apache.abdera.protocol.server.provider.ResponseContext;
-import org.apache.abdera.protocol.server.provider.TargetType;
+import org.apache.abdera.protocol.server.RequestHandler;
 
 public class DefaultRequestHandler 
   extends AbstractRequestHandler
   implements RequestHandler {
 
-  protected ResponseContext process(
-    Provider provider, 
-    RequestContext request) {
-      
-      TargetType type = request.getTarget().getType();    
-      String method = request.getMethod();
-        
-      if (method.equals("GET")) {
-        if (type == TargetType.TYPE_SERVICE) {
-          return provider.getService(request);
-        }
-        if (type == TargetType.TYPE_COLLECTION) {
-          return provider.getFeed(request);
-        }
-        if (type == TargetType.TYPE_ENTRY) {
-          return provider.getEntry(request);
-        }
-        if (type == TargetType.TYPE_MEDIA) {
-          return provider.getMedia(request);
-        }
-        if (type == TargetType.TYPE_CATEGORIES) {
-          return provider.getCategories(request);
-        }
-      }
-      else if (method.equals("HEAD")) {
-        if (type == TargetType.TYPE_SERVICE) {
-          return provider.getService(request);
-        }
-        if (type == TargetType.TYPE_COLLECTION) {
-          return provider.getFeed(request);
-        }
-        if (type == TargetType.TYPE_ENTRY) {
-          return provider.getEntry(request);
-        }
-        if (type == TargetType.TYPE_MEDIA) {
-          return provider.getMedia(request);
-        }
-        if (type == TargetType.TYPE_CATEGORIES) {
-          return provider.getCategories(request);
-        }
-      }
-      else if (method.equals("POST")) {
-        if (type == TargetType.TYPE_COLLECTION) {
-          return provider.createEntry(request);
-        }
-        if (type == TargetType.TYPE_ENTRY) {
-          return provider.entryPost(request);
-        }
-        if (type == TargetType.TYPE_MEDIA) {
-          return provider.mediaPost(request);
-        }
-      }
-      else if (method.equals("PUT")) {
-        if (type == TargetType.TYPE_ENTRY) {
-          return provider.updateEntry(request);
-        }
-        if (type == TargetType.TYPE_MEDIA) {
-          return provider.updateMedia(request);
-        }
-      }
-      else if (method.equals("DELETE")) {
-        if (type == TargetType.TYPE_ENTRY) {
-          return provider.deleteEntry(request);
-        }
-        if (type == TargetType.TYPE_MEDIA) {
-          return provider.deleteMedia(request);
-        }
-      } 
-      else if (method.equals("OPTIONS")) {
-        AbstractResponseContext rc = new EmptyResponseContext(200);
-        rc.addHeader("Allow", combine(getAllowedMethods(type)));
-        return rc;
-      }
-      return null;
-  }
-  
-  protected String[] getAllowedMethods(TargetType type) {
-    if (type == null)                       return new String[0];
-    if (type == TargetType.TYPE_COLLECTION) return new String[] { "GET", "POST", "HEAD", "OPTIONS" };
-    if (type == TargetType.TYPE_CATEGORIES) return new String[] { "GET", "HEAD", "OPTIONS" };
-    if (type == TargetType.TYPE_ENTRY)      return new String[] { "GET", "DELETE", "PUT", "POST", "HEAD", "OPTIONS" };
-    if (type == TargetType.TYPE_MEDIA)      return new String[] { "GET", "DELETE", "PUT", "POST", "HEAD", "OPTIONS" };
-    if (type == TargetType.TYPE_SERVICE)    return new String[] { "GET", "HEAD", "OPTIONS" };
-    return new String[] { "GET", "HEAD", "OPTIONS" };
-  }
+ 
   
 }

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandlerManager.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/DefaultRequestHandlerManager.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandlerManager.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/DefaultRequestHandlerManager.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandlerManager.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/DefaultRequestHandlerManager.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultRequestHandlerManager.java Wed Jul 11 11:07:36 2007
@@ -15,10 +15,12 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.servlet;
+package org.apache.abdera.protocol.server.impl;
+
+import org.apache.abdera.protocol.server.RequestHandler;
 
 public class DefaultRequestHandlerManager 
-  extends AbstractRequestHandlerManager {
+  extends AbstractItemManager<RequestHandler> {
 
   @Override
   protected RequestHandler internalNewInstance() {

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/DefaultServiceContext.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/DefaultServiceContext.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/DefaultServiceContext.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java Wed Jul 11 11:07:36 2007
@@ -15,16 +15,16 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server;
+package org.apache.abdera.protocol.server.impl;
 
-import org.apache.abdera.protocol.server.auth.SubjectResolver;
-import org.apache.abdera.protocol.server.provider.ProviderManager;
-import org.apache.abdera.protocol.server.provider.TargetResolver;
-import org.apache.abdera.protocol.server.servlet.DefaultRequestHandlerManager;
-import org.apache.abdera.protocol.server.servlet.RequestHandlerManager;
-import org.apache.abdera.protocol.server.util.RegexTargetResolver;
+import javax.security.auth.Subject;
+
+import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.Provider;
+import org.apache.abdera.protocol.server.RequestHandler;
+import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.protocol.server.util.ServerConstants;
-import org.apache.abdera.protocol.server.util.SimpleSubjectResolver;
 import org.apache.abdera.util.ServiceUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -35,63 +35,70 @@
 
   private static final Log logger = LogFactory.getLog(DefaultServiceContext.class);
   
+  protected String defaultrequesthandlermanager = DefaultRequestHandlerManager.class.getName();
+  protected String defaultsubjectresolver = SimpleSubjectResolver.class.getName();
+  protected String defaulttargetresolver = RegexTargetResolver.class.getName();
+  protected String defaultprovidermanager = null;
+  
+  protected DefaultServiceContext() {}
+  
   private Object instance(String id, String _default) {
     String instance = getProperty(id);
     Object obj =  ServiceUtil.newInstance( id, (instance!=null)?instance:_default, abdera);
-    if (logger.isDebugEnabled()) {
-      logger.debug("Returning " + obj + " as instance of '" + id + "'.");
-    }
+    logger.debug("Returning " + obj + " as instance of '" + id + "'.");
     return obj;
   }
   
   private Object instance(String id, String _default, Object... args) {
     String instance = getProperty(id);
     Object obj =  ServiceUtil.newInstance( id, (instance!=null)?instance:_default, abdera, args);
-    if (logger.isDebugEnabled()) {
-      logger.debug("Returning " + obj + " as instance of '" + id + "'.");
-    }
+    logger.debug("Returning " + obj + " as instance of '" + id + "'.");
     return obj;
   }
   
-  public synchronized ProviderManager getProviderManager() {
+  @SuppressWarnings("unchecked")
+  public synchronized ItemManager<Provider> getProviderManager() {
     if (providerManager == null) {
-      providerManager = (ProviderManager) instance(
+      providerManager = (ItemManager<Provider>) instance(
         PROVIDER_MANAGER, getDefaultProviderManager());
     }
     return providerManager;
   }
   
   protected String getDefaultProviderManager() {
-    return null;
+    return defaultprovidermanager;
   }
 
-  public synchronized RequestHandlerManager getRequestHandlerManager() {
+  @SuppressWarnings("unchecked")
+  public synchronized ItemManager<RequestHandler> getRequestHandlerManager() {
     if (handlerManager == null) {
-      handlerManager = (RequestHandlerManager) instance(
+      handlerManager = (ItemManager<RequestHandler>) instance(
         REQUEST_HANDLER_MANAGER, getDefaultRequestHandlerManager());
     }
     return handlerManager;
   }
   
   protected String getDefaultRequestHandlerManager() {
-    return DefaultRequestHandlerManager.class.getName();
+    return defaultrequesthandlermanager;
   }
 
-  public SubjectResolver getSubjectResolver() {
+  @SuppressWarnings("unchecked")
+  public Resolver<Subject> getSubjectResolver() {
     if (subjectResolver == null) {
-      subjectResolver = (SubjectResolver) instance(
+      subjectResolver = (Resolver<Subject>) instance(
         SUBJECT_RESOLVER, getDefaultSubjectResolver());
     }
     return subjectResolver;
   }
   
   protected String getDefaultSubjectResolver() {
-    return SimpleSubjectResolver.class.getName();
+    return defaultsubjectresolver;
   }
 
-  public TargetResolver getTargetResolver(String contextPath) {
+  @SuppressWarnings("unchecked")
+  public Resolver<Target> getTargetResolver(String contextPath) {
     if (targetResolver == null) {
-      targetResolver = (TargetResolver) instance(
+      targetResolver = (Resolver<Target>) instance(
         TARGET_RESOLVER, getDefaultTargetResolver(), 
         contextPath);
     }
@@ -99,7 +106,7 @@
   }
   
   protected String getDefaultTargetResolver() {
-    return RegexTargetResolver.class.getName();
+    return defaulttargetresolver;
   }
 
 }

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/EmptyResponseContext.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/EmptyResponseContext.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/EmptyResponseContext.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/EmptyResponseContext.java Wed Jul 11 11:07:36 2007
@@ -15,7 +15,7 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.provider;
+package org.apache.abdera.protocol.server.impl;
 
 import java.io.IOException;
 import java.io.OutputStream;

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java (from r550706, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/HttpServletRequestContext.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/HttpServletRequestContext.java&r1=550706&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/HttpServletRequestContext.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java Wed Jul 11 11:07:36 2007
@@ -15,12 +15,11 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.servlet;
+package org.apache.abdera.protocol.server.impl;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
-import java.security.Principal;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.List;
@@ -30,11 +29,10 @@
 import javax.servlet.http.HttpSession;
 
 import org.apache.abdera.Abdera;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ServiceContext;
-import org.apache.abdera.protocol.server.auth.SubjectResolver;
-import org.apache.abdera.protocol.server.provider.AbstractRequestContext;
-import org.apache.abdera.protocol.server.provider.RequestContext;
-import org.apache.abdera.protocol.server.provider.TargetResolver;
+import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.i18n.iri.IRI;
 
 public class HttpServletRequestContext 
@@ -55,11 +53,12 @@
       this.request = request;
       this.session = request.getSession(false);
       
-      SubjectResolver subjectResolver = context.getSubjectResolver();
+      Resolver<Subject> subjectResolver = context.getSubjectResolver();
+      principal = request.getUserPrincipal();
       subject = (subjectResolver != null)? 
-        subjectResolver.resolve((Principal)getProperty(Property.PRINCIPAL)) : null;
+        subjectResolver.resolve(this) : null;
       
-      TargetResolver targetResolver = 
+      Resolver<Target> targetResolver = 
         context.getTargetResolver(
           request.getContextPath());
       target = (targetResolver != null) ? 
@@ -80,6 +79,14 @@
       case REMOTEUSER:        return request.getRemoteUser();
       case SCHEME:            return request.getScheme();
       case PRINCIPAL:         return request.getUserPrincipal();
+      case AUTHTYPE:          return request.getAuthType();
+      case CONTENTLENGTH:     return request.getContentLength();
+      case CONTENTTYPE:       return request.getContentType();
+      case CONTEXTPATH:       return request.getContextPath();
+      case LOCALADDR:         return request.getLocalAddr();
+      case LOCALNAME:         return request.getLocalName();
+      case SERVERNAME:        return request.getServerName();
+      case SERVERPORT:        return request.getServerPort();
       default:
         throw new UnsupportedOperationException("Property not supported"); 
     }

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/MediaResponseContext.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/MediaResponseContext.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/MediaResponseContext.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/MediaResponseContext.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/MediaResponseContext.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/provider/MediaResponseContext.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/MediaResponseContext.java Wed Jul 11 11:07:36 2007
@@ -15,7 +15,7 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.provider;
+package org.apache.abdera.protocol.server.impl;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -23,6 +23,7 @@
 import java.io.OutputStream;
 import java.io.Writer;
 import java.util.Date;
+
 
 /**
  * ResponseContext implementation for arbitrary media resources

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/RegexTargetResolver.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/RegexTargetResolver.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/RegexTargetResolver.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java Wed Jul 11 11:07:36 2007
@@ -15,18 +15,18 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.util;
+package org.apache.abdera.protocol.server.impl;
 
 import java.util.HashMap;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.abdera.protocol.server.provider.AbstractTarget;
-import org.apache.abdera.protocol.server.provider.RequestContext;
-import org.apache.abdera.protocol.server.provider.Target;
-import org.apache.abdera.protocol.server.provider.TargetResolver;
-import org.apache.abdera.protocol.server.provider.TargetType;
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.TargetType;
 
 /**
  * <p>Provides a utility class helpful for determining which type of resource
@@ -54,7 +54,7 @@
  *  
  */
 public class RegexTargetResolver 
-  implements TargetResolver {
+  implements Resolver<Target> {
 
   private final Map<Pattern, TargetType> patterns;
   private String contextPath;
@@ -78,13 +78,14 @@
     this.patterns.put(p,type);
   }
   
-  public Target resolve(RequestContext request) {
-    String uri = request.getUri().toString();
+  public Target resolve(Request request) {
+    RequestContext context = (RequestContext) request;
+    String uri = context.getUri().toString();
     for (Pattern pattern : patterns.keySet()) {
       Matcher matcher = pattern.matcher(uri);
       if (matcher.matches()) {
         TargetType type = patterns.get(pattern);
-        return getTarget(type, request, matcher);
+        return getTarget(type, context, matcher);
       }
     }
     return null;

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleSubjectResolver.java (from r541096, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/SimpleSubjectResolver.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleSubjectResolver.java?view=diff&rev=555349&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/SimpleSubjectResolver.java&r1=541096&p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleSubjectResolver.java&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/SimpleSubjectResolver.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/SimpleSubjectResolver.java Wed Jul 11 11:07:36 2007
@@ -15,19 +15,26 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.util;
+package org.apache.abdera.protocol.server.impl;
 
 import java.io.Serializable;
 import java.security.Principal;
 
 import javax.security.auth.Subject;
 
-import org.apache.abdera.protocol.server.auth.SubjectResolver;
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.RequestContext;
 
 public class SimpleSubjectResolver 
-  implements SubjectResolver {
+  implements Resolver<Subject> {
 
   public static final Principal ANONYMOUS = new AnonymousPrincipal();
+  
+  public Subject resolve(Request request) {
+    RequestContext context = (RequestContext) request;
+    return resolve(context.getPrincipal());
+  }
   
   public Subject resolve(Principal principal) {
     Subject subject = new Subject();

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaFilter.java?view=auto&rev=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaFilter.java (added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaFilter.java Wed Jul 11 11:07:36 2007
@@ -0,0 +1,60 @@
+/*
+* 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.protocol.server.servlet;
+
+import java.io.IOException;
+import java.io.Reader;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.parser.Parser;
+
+public abstract class AbderaFilter 
+  extends AbstractFilter {
+
+  protected final Abdera abdera;
+  
+  protected AbderaFilter() {
+    this.abdera = new Abdera();
+  }
+  
+  protected Abdera getAbdera() {
+    return abdera;
+  }
+  
+  protected Document<Element> getDocument(
+    BufferingResponseWrapper wrapper) 
+      throws IOException {
+    Reader rdr = wrapper.getReader();
+    Parser parser = abdera.getParser();
+    try {
+      if (rdr != null) return parser.parse(rdr);
+    } catch (Exception e) {}
+    return null;
+  }
+
+  protected Document<Element> getDocument(
+    BufferedRequestWrapper wrapper)
+      throws IOException {
+    try {
+      return abdera.getParser().parse(wrapper.getReader());
+    } catch (Exception e) {}
+    return null;
+  }
+}

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java?view=diff&rev=555349&r1=555348&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java Wed Jul 11 11:07:36 2007
@@ -18,7 +18,6 @@
 package org.apache.abdera.protocol.server.servlet;
 
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
@@ -29,13 +28,17 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.abdera.protocol.ItemManager;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.RequestHandler;
 import org.apache.abdera.protocol.server.ServiceContext;
 import org.apache.abdera.protocol.server.ServiceManager;
+import org.apache.abdera.protocol.server.impl.HttpServletRequestContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
- * Sample APP servlet.
+ * Simple APP servlet.
  * 
  * @version $Id$
  */
@@ -44,12 +47,22 @@
 
   private static final long serialVersionUID = 2393643907128535158L;
   
-  private final static Log logger = LogFactory.getLog(AbderaServlet.class);
+  private final static Log log = LogFactory.getLog(AbderaServlet.class);
   
-  protected ServiceManager serviceManager;
+  protected ServiceManager manager;
+  protected ServiceContext context;
   
   public void init() throws ServletException {
-    serviceManager = ServiceManager.getInstance();
+    log.debug("Initialing Abdera Servlet");
+    manager = ServiceManager.getInstance();
+    context = 
+      manager.newServiceContext(
+        getProperties(
+          getServletConfig()));
+    if (context == null) {
+      log.debug("Cannot create service context");
+      throw new ServletException("Cannot create service context");
+    }
   }
   
   @Override
@@ -57,23 +70,32 @@
     HttpServletRequest request, 
     HttpServletResponse response) 
       throws ServletException, IOException {
-    ServiceContext context = 
-      serviceManager.newServiceContext(
-        getProperties(getServletConfig()));
-    RequestHandlerManager manager = context.getRequestHandlerManager();
-    RequestHandler handler = manager.getRequestHandler();
+    RequestContext reqcontext = new HttpServletRequestContext(context, request);
+    ItemManager<RequestHandler> manager = context.getRequestHandlerManager();
+    log.debug("Processing request");
+    RequestHandler handler = manager.get(reqcontext);
+    log.debug("Handler - " + handler);
     try {
-      handler.process(context, request, response);
+      handler.process(context, reqcontext, response);
     } catch (Throwable t) {
-      logger.error("Error servicing request", t);
-      response.setContentType("text/plain");
-      PrintWriter out = response.getWriter();
-      out.println(t);
-      t.printStackTrace(out);
-      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+      error("Error servicing request", t, response);
+      return;
     } finally {
+      log.debug("Releasing handler - " + handler);
       manager.release(handler);
     }
+    log.debug("Request complete");
+  }
+  
+  private void error(
+    String message, 
+    Throwable t, 
+    HttpServletResponse response) 
+      throws IOException {
+    if (response.isCommitted()) response.reset();
+    if (t != null) log.error(message, t);
+    else log.error(message);
+    response.sendError(500, message);
   }
   
   private Map<String,String> getProperties(ServletConfig config) {

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbstractFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbstractFilter.java?view=auto&rev=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbstractFilter.java (added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbstractFilter.java Wed Jul 11 11:07:36 2007
@@ -0,0 +1,303 @@
+/*
+* 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.protocol.server.servlet;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.util.zip.DeflaterOutputStream;
+import java.util.zip.GZIPOutputStream;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+import org.apache.abdera.i18n.io.RewindableInputStream;
+
+/**
+ * Utility class that serves as the basis for a variety of Filter implementations
+ */
+public abstract class AbstractFilter 
+  implements Filter {
+
+  private FilterConfig config;
+  
+  public void destroy() {
+  }
+
+  public void init(FilterConfig config) throws ServletException {
+    this.config = config;
+  }
+
+  protected FilterConfig getConfig() {
+    return config;
+  }
+   
+  /**
+   * A HttpServletResponseWrapper implementation that applies GZip or Deflate
+   * compression to response output.
+   */
+  public static class CompressingResponseWrapper 
+    extends HttpServletResponseWrapper {
+
+    ServletOutputStream out = null;
+    PrintWriter output = null;
+    
+    public CompressingResponseWrapper(
+      HttpServletResponse response, 
+      String method) 
+        throws IOException {
+      super(response);
+      out = new CompressingServletOutputStream(
+        method, response.getOutputStream());
+    }
+    
+    @Override
+    public PrintWriter getWriter() throws IOException {
+      if (output == null)
+        output = new PrintWriter(
+          new OutputStreamWriter(
+            getOutputStream(), 
+            this.getCharacterEncoding()));
+      return output;
+    }
+  
+    @Override
+    public ServletOutputStream getOutputStream() throws IOException {
+      return out;
+    }
+    
+    public void finish() throws IOException {
+      out.flush();
+    }
+    
+    public static boolean canHandle(String enc) {
+      return enc.equalsIgnoreCase("gzip") ||
+             enc.equalsIgnoreCase("compress");
+    }
+    
+  }
+  
+  /**
+   * A ServletOutputStream implementation that handles the GZip and Deflate
+   * compression for the CompressingResponseWrapper
+   */
+  public static class CompressingServletOutputStream 
+    extends ServletOutputStream {
+
+    private DeflaterOutputStream dout;
+    
+    public CompressingServletOutputStream(String method, ServletOutputStream out) {
+      try {
+        if ("gzip".equalsIgnoreCase(method)) 
+          dout = new GZIPOutputStream(out);
+        if ("compress".equalsIgnoreCase(method))
+          dout = new DeflaterOutputStream(out);
+      } catch (IOException e) {}
+    }
+    
+    public CompressingServletOutputStream(DeflaterOutputStream dout) {
+      this.dout = dout;
+    }
+    
+    @Override
+    public void write(int b) throws IOException {
+      dout.write(b);
+    }
+
+    @Override
+    public void write(byte[] b, int off, int len) throws IOException {
+      dout.write(b,off,len);
+    }
+
+    @Override
+    public void write(byte[] b) throws IOException {
+      dout.write(b);
+    }
+
+  }
+  
+  /**
+   * A HttpServletResponseWrapper implementation that buffers the response 
+   * content in memory so that a filter can perform operations on the full
+   * response content (e.g. digitally sign it, encrypt it, etc)
+   */
+  public static class BufferingResponseWrapper 
+    extends HttpServletResponseWrapper {
+  
+    PrintWriter output = null;
+    ServletOutputStream outStream = null;
+  
+    public BufferingResponseWrapper(HttpServletResponse response) {
+      super(response);
+    }
+  
+    @Override
+    public PrintWriter getWriter() throws IOException {
+      if (output == null)
+        output = new PrintWriter(
+          new OutputStreamWriter(
+            getOutputStream(), 
+            this.getCharacterEncoding()));
+      return output;
+    }
+  
+    @Override
+    public ServletOutputStream getOutputStream() throws IOException {
+      if (outStream == null)
+        outStream = new BufferingServletOutputStream();
+      return outStream;
+    }
+  
+    public Reader getReader() throws IOException {
+      return new InputStreamReader(
+        getInputStream(), 
+        this.getCharacterEncoding());
+    }
+  
+    public InputStream getInputStream() throws IOException {
+      BufferingServletOutputStream out = 
+        (BufferingServletOutputStream)getOutputStream();
+      return new ByteArrayInputStream(
+        out.getBuffer().toByteArray());
+    }
+  }
+
+  /**
+   * Implementation of ServletOutputStream that handles the in-memory 
+   * buffering of the response content
+   */
+  public static class BufferingServletOutputStream 
+    extends ServletOutputStream {
+
+    ByteArrayOutputStream out = null;
+  
+    public BufferingServletOutputStream() {
+      this.out = new ByteArrayOutputStream();
+    }
+    
+    public ByteArrayOutputStream getBuffer() {
+      return out;
+    }
+  
+    public void write(int b) throws IOException {
+      out.write(b);
+    }
+  
+    public void write(byte[] b) throws IOException {
+      out.write(b);
+    }
+  
+    public void write(byte[] b, int off, int len) throws IOException {
+      out.write(b, off, len);
+    }
+
+    @Override
+    public void close() throws IOException {
+      out.close();
+      super.close();
+    }
+
+    @Override
+    public void flush() throws IOException {
+      out.flush();
+      super.flush();
+    }
+    
+  }
+
+  /**
+   * Implementation of HttpServletRequestWrapper that allows a Filter 
+   * to perform operations on the full content of a request while still
+   * allowing downstream operations to be performed on the content.
+   * (e.g. decrypting requests, verifying digital signatures, etc) 
+   */
+  public static class BufferedRequestWrapper 
+    extends HttpServletRequestWrapper {
+
+    private BufferedServletInputStream bin;
+    private RewindableInputStream rin;
+    private BufferedReader rdr;
+
+    public BufferedRequestWrapper(HttpServletRequest request) {
+      super(request);
+    }
+
+    public void setInputStream(InputStream in) {
+      bin = new BufferedServletInputStream(in);
+    }
+    
+    @Override
+    public ServletInputStream getInputStream() throws IOException {
+      if (rdr != null) throw new IllegalStateException();
+      if (bin == null) {
+        rin = new RewindableInputStream(super.getInputStream());
+        bin = new BufferedServletInputStream(rin);
+      }
+      return bin;
+    }
+
+    @Override
+    public BufferedReader getReader() throws IOException {
+      if (rdr == null) {
+        String charset = this.getCharacterEncoding();
+        rdr = (charset == null) ?
+          new BufferedReader(new InputStreamReader(getInputStream())) :
+          new BufferedReader(new InputStreamReader(getInputStream(),charset));
+      }
+      return rdr;
+    }
+    
+    public void reset() throws IOException {
+      if (bin != null) rin.rewind();
+      rdr = null;
+    }
+    }
+    
+    public static class BufferedServletInputStream 
+    extends ServletInputStream {
+    
+    private InputStream in;
+    
+    public BufferedServletInputStream(InputStream in) {
+      this.in = in;
+      try {
+        in.mark(in.available());
+      } catch (Exception e) {}
+    }
+    
+    @Override
+    public int read() throws IOException {
+      return in.read();
+    }
+
+  }
+
+}

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/CompressionFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/CompressionFilter.java?view=auto&rev=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/CompressionFilter.java (added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/CompressionFilter.java Wed Jul 11 11:07:36 2007
@@ -0,0 +1,67 @@
+/*
+* 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.protocol.server.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.abdera.protocol.server.util.ServerUtils;
+
+/**
+ * A filter that applies either GZip or Compress encoding on a response
+ * depending on the value of the Accept-Encoding request header.
+ * 
+ * Note: This is currently untested
+ */
+public class CompressionFilter
+  extends AbstractFilter
+  implements Filter {
+
+  public void doFilter(
+    ServletRequest request, 
+    ServletResponse response,
+    FilterChain chain) 
+      throws IOException, ServletException {
+    
+    HttpServletRequest req = (HttpServletRequest) request;
+    String encoding = req.getHeader("Accept-Encoding");
+    String[] encodings = 
+      encoding != null ? 
+        ServerUtils.orderByQ(encoding) : 
+        new String[0];
+    for (String enc : encodings) {
+      if (CompressingResponseWrapper.canHandle(enc)) {
+        CompressingResponseWrapper resp = 
+          new CompressingResponseWrapper(
+            (HttpServletResponse) response, enc);
+        chain.doFilter(request, response);
+        resp.finish();
+        return;
+      }
+    }
+    chain.doFilter(request, response);
+  }
+
+}

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/MethodOverrideFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/MethodOverrideFilter.java?view=auto&rev=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/MethodOverrideFilter.java (added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/MethodOverrideFilter.java Wed Jul 11 11:07:36 2007
@@ -0,0 +1,100 @@
+/*
+* 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.protocol.server.servlet;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+
+
+/**
+ * HTTP Servlet Filter that implements support for Google's X-HTTP-Method-Override
+ * header to perform "POST Tunneling" of various HTTP operations 
+ */
+public class MethodOverrideFilter 
+  extends AbstractFilter
+  implements Filter {
+
+  public static final String METHODS = "org.apache.abdera.protocol.server.servlet.Overrides";
+  
+  private final List<String> METHODS_TO_OVERRIDE = new ArrayList<String>();
+  
+  public void doFilter(
+    ServletRequest request, 
+    ServletResponse response,
+    FilterChain chain) 
+      throws IOException, 
+             ServletException {
+    chain.doFilter(
+      new MethodOverrideRequestWrapper(
+        (HttpServletRequest) request), 
+        response);
+    
+    HttpServletResponse hresponse = (HttpServletResponse) response;
+    hresponse.setHeader("Cache-Control", "no-cache");
+  }
+
+  @Override
+  public void init(FilterConfig config) throws ServletException {
+    String param = config.getInitParameter(METHODS);
+    if (param != null) {
+      String[] methods = param.split(",");
+      for (String method : methods) {
+        method = method.trim();
+        METHODS_TO_OVERRIDE.add(method);
+      }
+    }
+  }
+
+  private class MethodOverrideRequestWrapper 
+    extends HttpServletRequestWrapper {
+
+    private final String method;
+    
+    public MethodOverrideRequestWrapper(HttpServletRequest request) {
+      super(request);
+      
+      String method = super.getMethod();
+      String xheader = getHeader("X-HTTP-Method-Override");
+      if (xheader == null) xheader = getHeader("X-Method-Override");
+      if (xheader != null) xheader = xheader.toUpperCase().trim();
+      if (method.equals("POST") && 
+          xheader != null && 
+          METHODS_TO_OVERRIDE.contains(xheader)) {
+        method = xheader;
+      }
+      this.method = method;
+    }
+
+    @Override
+    public String getMethod() {
+      return method;
+    }
+    
+  }
+}

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/test/server/UtilityTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/test/server/UtilityTest.java?view=diff&rev=555349&r1=555348&r2=555349
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/test/server/UtilityTest.java (original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/test/server/UtilityTest.java Wed Jul 11 11:07:36 2007
@@ -26,11 +26,11 @@
 import java.util.List;
 
 import org.apache.abdera.protocol.server.ServiceManager;
-import org.apache.abdera.protocol.server.provider.AbstractRequestContext;
-import org.apache.abdera.protocol.server.provider.Target;
-import org.apache.abdera.protocol.server.provider.TargetType;
-import org.apache.abdera.protocol.server.util.RegexTargetResolver;
-import org.apache.abdera.protocol.server.util.SimpleSubjectResolver;
+import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.TargetType;
+import org.apache.abdera.protocol.server.impl.AbstractRequestContext;
+import org.apache.abdera.protocol.server.impl.RegexTargetResolver;
+import org.apache.abdera.protocol.server.impl.SimpleSubjectResolver;
 import org.apache.abdera.protocol.util.EncodingUtil;
 import org.apache.abdera.util.EntityTag;
 import org.apache.abdera.i18n.iri.IRI;
@@ -126,8 +126,9 @@
         new IRI(request), 
         new IRI(base));
       
-      subject = context.getSubjectResolver().resolve(
-        (Principal) getProperty(Property.PRINCIPAL));
+      principal = (Principal) getProperty(Property.PRINCIPAL); 
+      
+      subject = context.getSubjectResolver().resolve(this);
     }
 
     public Object getAttribute(Scope scope, String name) {



Mime
View raw message