abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r564805 - in /incubator/abdera/java/trunk: examples/src/main/java/org/apache/abdera/examples/appserver/ server/src/main/java/org/apache/abdera/protocol/server/ server/src/main/java/org/apache/abdera/protocol/server/impl/ server/src/test/jav...
Date Fri, 10 Aug 2007 23:42:41 GMT
Author: jmsnell
Date: Fri Aug 10 16:42:40 2007
New Revision: 564805

URL: http://svn.apache.org/viewvc?view=rev&rev=564805
Log:
Inspired by Dan Diephouse's spring patch. Instead of initializing the context path, let's
pull
it directly from the request context on each resolution.  Doing so simplifies target resolver

implementations somewhat.

Modified:
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleTargetResolver.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/test/server/UtilityTest.java

Modified: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleTargetResolver.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleTargetResolver.java?view=diff&rev=564805&r1=564804&r2=564805
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleTargetResolver.java
(original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/SimpleTargetResolver.java
Fri Aug 10 16:42:40 2007
@@ -23,8 +23,7 @@
 public class SimpleTargetResolver 
   extends RegexTargetResolver {
 
-  public SimpleTargetResolver(String contextPath) {
-    super(contextPath);
+  public SimpleTargetResolver() {
     setPattern("/atom(\\?[^#]*)?", TargetType.TYPE_SERVICE);
     setPattern("/atom/feed(\\?[^#]*)?", TargetType.TYPE_COLLECTION);
     setPattern("/atom/feed/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY);

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/RequestContext.java?view=diff&rev=564805&r1=564804&r2=564805
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
Fri Aug 10 16:42:40 2007
@@ -90,4 +90,12 @@
   <T extends Element>Document<T> getDocument(ParserOptions options) throws ParseException,
IOException;
   
   boolean isUserInRole(String role);
+  
+  String getContextPath();
+  
+  /**
+   * Returns the subset of the request URI that is to be used to resolve the Target
+   * (everything after the context path)
+   */
+  String getTargetPath();
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/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=564805&r1=564804&r2=564805
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestContext.java
Fri Aug 10 16:42:40 2007
@@ -153,4 +153,11 @@
   public ServiceContext getServiceContext() {
     return context;
   }
+
+  public String getTargetPath() {
+    String uri = getUri().toString();
+    String cpath = getContextPath();
+    return cpath == null ? uri : uri.substring(cpath.length());
+  }
+  
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/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=564805&r1=564804&r2=564805
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultServiceContext.java
Fri Aug 10 16:42:40 2007
@@ -100,8 +100,7 @@
   public Resolver<Target> getTargetResolver(String contextPath) {
     if (targetResolver == null) {
       targetResolver = (Resolver<Target>) instance(
-        TARGET_RESOLVER, getDefaultTargetResolver(), 
-        contextPath);
+        TARGET_RESOLVER, getDefaultTargetResolver());
     }
     return targetResolver;
   }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/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=564805&r1=564804&r2=564805
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java
Fri Aug 10 16:42:40 2007
@@ -235,4 +235,8 @@
   public boolean isUserInRole(String role) {
     return request.isUserInRole(role);
   }
+
+  public String getContextPath() {
+    return request.getContextPath();
+  }
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/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=564805&r1=564804&r2=564805
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RegexTargetResolver.java
Fri Aug 10 16:42:40 2007
@@ -57,15 +57,12 @@
   implements Resolver<Target> {
 
   private final Map<Pattern, TargetType> patterns;
-  private String contextPath;
   
-  public RegexTargetResolver(String contextPath) {
-    this.contextPath = contextPath;
+  public RegexTargetResolver() {
     this.patterns = new HashMap<Pattern, TargetType>();
   }
   
-  public RegexTargetResolver(String contextPath, Map<String, TargetType> patterns)
{
-    this.contextPath = contextPath;
+  public RegexTargetResolver(Map<String, TargetType> patterns) {
     this.patterns = new HashMap<Pattern, TargetType>();
     for (String p : patterns.keySet()) {
       TargetType type = patterns.get(p);
@@ -74,13 +71,13 @@
   }
   
   public synchronized void setPattern(String pattern, TargetType type) {
-    Pattern p = Pattern.compile(getContextPath() + pattern);
+    Pattern p = Pattern.compile(pattern);
     this.patterns.put(p,type);
   }
   
   public Target resolve(Request request) {
     RequestContext context = (RequestContext) request;
-    String uri = context.getUri().toString();
+    String uri = context.getTargetPath();
     for (Pattern pattern : patterns.keySet()) {
       Matcher matcher = pattern.matcher(uri);
       if (matcher.matches()) {
@@ -179,12 +176,4 @@
     
   }
 
-  public void setContextPath(String contextPath) {
-    this.contextPath = contextPath;
-  }
-  
-  protected String getContextPath() {
-    return this.contextPath;
-  }
-  
 }

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=564805&r1=564804&r2=564805
==============================================================================
--- 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
Fri Aug 10 16:42:40 2007
@@ -89,7 +89,7 @@
   
   public static void testRegexTargetResolver() throws Exception {
     
-    RegexTargetResolver r = new RegexTargetResolver("/test");
+    RegexTargetResolver r = new RegexTargetResolver();
     r.setPattern("", TargetType.TYPE_SERVICE);
     r.setPattern("/([^/?#]+)", TargetType.TYPE_COLLECTION);
     
@@ -187,6 +187,10 @@
 
     public boolean isUserInRole(String role) {
       return false;
+    }
+
+    public String getContextPath() {
+      return "/test";
     }
     
   }



Mime
View raw message