abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r614798 [2/2] - in /incubator/abdera/java/branches/server_refactor_all: ./ .settings/ examples/src/main/java/org/apache/abdera/examples/appserver/ server/src/main/java/org/apache/abdera/protocol/server/ server/src/main/java/org/apache/abder...
Date Thu, 24 Jan 2008 05:38:30 GMT
Modified: incubator/abdera/java/branches/server_refactor_all/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java?rev=614798&r1=614797&r2=614798&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
Wed Jan 23 21:38:20 2008
@@ -32,6 +32,7 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.protocol.error.Error;
+import org.apache.abdera.protocol.server.FilterChain;
 import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
@@ -84,11 +85,12 @@
       throws ServletException, IOException {
     RequestContext reqcontext = 
       new ServletRequestContext(provider, request);
+    FilterChain chain = new FilterChain(provider,reqcontext);
     try {
       output(
         request,
         response,
-        provider.process(
+        chain.next(
           reqcontext));
     } catch (Throwable t) {
       error("Error servicing request", t, response);

Modified: incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/basic/BasicTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/basic/BasicTest.java?rev=614798&r1=614797&r2=614798&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/basic/BasicTest.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/basic/BasicTest.java
Wed Jan 23 21:38:20 2008
@@ -21,7 +21,6 @@
 import java.util.Date;
 
 import junit.framework.Assert;
-import junit.framework.TestCase;
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Collection;

Copied: incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProvider.java
(from r614767, incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProvider.java?p2=incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProvider.java&p1=incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java&r1=614767&r2=614798&rev=614798&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleProvider.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProvider.java
Wed Jan 23 21:38:20 2008
@@ -15,34 +15,82 @@
  * copyright in this work, please see the NOTICE file in the top level
  * directory of this distribution.
  */
-package org.apache.abdera.protocol.server.test.simple;
+package org.apache.abdera.protocol.server.test.custom;
 
-import java.io.IOException;
-
-import org.apache.abdera.protocol.Resolver;
 import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.Filter;
+import org.apache.abdera.protocol.server.FilterChain;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
-import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.protocol.server.TargetType;
-import org.apache.abdera.protocol.server.context.StreamWriterResponseContext;
-import org.apache.abdera.protocol.server.impl.DefaultProvider;
-import org.apache.abdera.protocol.server.impl.DefaultWorkspaceManager;
+import org.apache.abdera.protocol.server.context.RequestContextWrapper;
+import org.apache.abdera.protocol.server.impl.AbstractWorkspaceProvider;
 import org.apache.abdera.protocol.server.impl.RegexTargetResolver;
+import org.apache.abdera.protocol.server.impl.SimpleCollectionInfo;
 import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;
-import org.apache.abdera.util.Constants;
-import org.apache.abdera.writer.StreamWriter;
 
-public class SimpleProvider extends DefaultProvider {
+public class CustomProvider 
+  extends AbstractWorkspaceProvider {
 
-  public SimpleProvider() {
-    super("/atom");
+  private final CollectionAdapter adapter;
+  
+  public CustomProvider() {
+    
+    this.adapter = new SimpleAdapter();
+    
+    super.setTargetResolver(      
+      new RegexTargetResolver()
+        .setPattern("/atom(\\?[^#]*)?", TargetType.TYPE_SERVICE)
+        .setPattern("/atom/([^/#?]+);categories", TargetType.TYPE_CATEGORIES, "collection")
+        .setPattern("/atom/([^/#?;]+)(\\?[^#]*)?", TargetType.TYPE_COLLECTION, "collection")
+        .setPattern("/atom/([^/#?]+)/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY, "collection","entry")
+        .setPattern("/search", OpenSearchFilter.TYPE_OPENSEARCH_DESCRIPTION)
+    );
     
-    SimpleWorkspaceInfo wkspc = new SimpleWorkspaceInfo();
-    wkspc.setTitle("A Simple Workspace");
-    wkspc.addCollection(new SimpleAdapter());
+    SimpleWorkspaceInfo workspace = new SimpleWorkspaceInfo();
+    workspace.setTitle("A Simple Workspace");
+    workspace.addCollection(
+      new SimpleCollectionInfo(
+        "feed",
+        "A simple feed",
+        "/atom/feed",
+        "application/atom+xml;type=entry"
+      ));
+    addWorkspace(workspace);
+    
+    addFilter(new SimpleFilter());
+    addFilter(
+      new OpenSearchFilter()
+        .setShortName("My OpenSearch")
+        .setDescription("My Description")
+        .setTags("test","example","opensearch")
+        .setContact("john.doe@example.org")
+        .setTemplate("http://localhost:8080/atom/feed?q={searchTerms}&c={count?}&s={startIndex?}&p={startPage?}&l={language?}&i={indexEncoding?}&o={outputEncoding?}")
+        .mapTargetParameter("q", "searchTerms")
+        .mapTargetParameter("c", "count")
+        .mapTargetParameter("s", "startIndex")
+        .mapTargetParameter("p", "startPage")
+        .mapTargetParameter("l", "language")
+        .mapTargetParameter("i", "inputEncoding")
+        .mapTargetParameter("o", "outputEncoding")
+      );
+  }
+
+  public CollectionAdapter getCollectionAdapter(
+    RequestContext request) {
+      return adapter;
+  }
 
-    addWorkspace(wkspc);
+  public class SimpleFilter 
+    implements Filter {
+      public ResponseContext filter(
+        RequestContext request, 
+        FilterChain chain) {
+          RequestContextWrapper rcw = new RequestContextWrapper(request);
+          rcw.setAttribute("offset", 10);
+          rcw.setAttribute("count", 10);
+          return chain.next(rcw);
+      }    
   }
 
 }

Copied: incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProviderTest.java
(from r614767, incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProviderTest.java?p2=incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProviderTest.java&p1=incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java&r1=614767&r2=614798&rev=614798&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/simple/SimpleTest.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProviderTest.java
Wed Jan 23 21:38:20 2008
@@ -15,12 +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.test.simple;
+package org.apache.abdera.protocol.server.test.custom;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.Date;
 
+import junit.framework.Assert;
+
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Base;
 import org.apache.abdera.model.Categories;
@@ -39,16 +41,11 @@
 import org.apache.abdera.util.MimeTypeHelper;
 import org.apache.abdera.writer.Writer;
 import org.apache.abdera.writer.WriterFactory;
-import org.junit.After;
 import org.junit.AfterClass;
-import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-public class SimpleTest extends Assert {
+public class CustomProviderTest extends Assert {
 
   private static JettyServer server;
   private static Abdera abdera = Abdera.getInstance();
@@ -58,7 +55,7 @@
   public static void setUp() throws Exception {
     try {
       server = new JettyServer();
-      server.start(SimpleProvider.class);
+      server.start(CustomProvider.class);
     } catch (Exception e) {
       e.printStackTrace();
     }

Added: incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/OpenSearchFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/OpenSearchFilter.java?rev=614798&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/OpenSearchFilter.java
(added)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/OpenSearchFilter.java
Wed Jan 23 21:38:20 2008
@@ -0,0 +1,163 @@
+/*
+* 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.test.custom;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.abdera.protocol.server.Filter;
+import org.apache.abdera.protocol.server.FilterChain;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.TargetType;
+import org.apache.abdera.protocol.server.context.StreamWriterResponseContext;
+import org.apache.abdera.writer.StreamWriter;
+
+public class OpenSearchFilter 
+  implements Filter {
+  
+  public static final String OSDNS = "http://a9.com/-/spec/opensearch/1.1/";
+  public static final String OS_PREFIX = "OpenSearch_";
+  
+  public static final TargetType TYPE_OPENSEARCH_DESCRIPTION = 
+    TargetType.get("OPENSEARCH_DESCRIPTION",true);
+  
+  private String shortName;
+  private String description;
+  private String[] tags;
+  private String contact;
+  private String template;
+  private Map<String,String> map = new HashMap<String,String>();
+  
+  public OpenSearchFilter() {}
+  
+  public String getShortName() {
+    return shortName;
+  }
+
+  public OpenSearchFilter setShortName(String shortName) {
+    this.shortName = shortName;
+    return this;
+  }
+
+  public String getDescription() {
+    return description;
+  }
+
+  public OpenSearchFilter setDescription(String description) {
+    this.description = description;
+    return this;
+  }
+
+  public String[] getTags() {
+    return tags;
+  }
+
+  public OpenSearchFilter setTags(String... tags) {
+    this.tags = tags;
+    return this;
+  }
+
+  public String getContact() {
+    return contact;
+  }
+  
+  public OpenSearchFilter setContact(String contact) {
+    this.contact = contact;
+    return this;
+  }
+
+  public String getTemplate() {
+    return template;
+  }
+
+  public OpenSearchFilter setTemplate(String template) {
+    this.template = template;
+    return this;
+  }
+
+  public OpenSearchFilter mapTargetParameter(
+    String targetParam, 
+    String openSearchParam) {
+      map.put(targetParam, openSearchParam);
+      return this;
+  }
+  
+  public ResponseContext filter(
+    RequestContext request, 
+    FilterChain chain) {
+    
+      Target target = request.getTarget();
+      TargetType type = target.getType();
+      if (type == TYPE_OPENSEARCH_DESCRIPTION) {
+        return getOpenSearchDescription(request);
+      } else {
+        for (Entry<String,String> entry : map.entrySet()) {
+          String value = target.getParameter(entry.getKey());
+          if (value != null) 
+            request.setAttribute(
+              OS_PREFIX + "_" + entry.getValue(), value);
+        }
+        return chain.next(request);
+      }
+  }
+  
+  private String combineTags() {
+    if (tags == null) return "";
+    StringBuilder buf = new StringBuilder();
+    for (String tag : tags) {
+      if (buf.length() > 0) buf.append(" ");
+      buf.append(tag);
+    }
+    return buf.toString();
+  }
+  
+  private ResponseContext getOpenSearchDescription(
+    RequestContext request) {
+      return new StreamWriterResponseContext(request.getAbdera()) {
+        protected void writeTo(
+          StreamWriter sw) 
+            throws IOException {
+          sw.startDocument()
+            .startElement("OpenSearchDescription", OSDNS)
+              .startElement("ShortName", OSDNS)
+                .writeElementText(getShortName())
+              .endElement()
+              .startElement("Description", OSDNS)
+                .writeElementText(getDescription())
+              .endElement()
+              .startElement("Tags", OSDNS)
+                .writeElementText(combineTags())
+              .endElement()
+              .startElement("Contact", OSDNS)
+                .writeElementText(getContact())
+              .endElement()
+              .startElement("Url", OSDNS)
+                .writeAttribute("type", "application/atom+xml")
+                .writeAttribute("template",getTemplate())
+              .endElement()
+            .endElement()
+            .endDocument();
+        }
+      }.setStatus(200)
+       .setContentType("application/opensearchdescription+xml");
+  }
+}

Modified: incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/SimpleAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/SimpleAdapter.java?rev=614798&r1=614767&r2=614798&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/SimpleAdapter.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/custom/SimpleAdapter.java
Wed Jan 23 21:38:20 2008
@@ -15,21 +15,17 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.test.simple;
+package org.apache.abdera.protocol.server.test.custom;
 
 import java.io.IOException;
 import java.util.Date;
 
-import javax.activation.MimeType;
-
 import org.apache.abdera.Abdera;
-import org.apache.abdera.factory.Factory;
 import org.apache.abdera.i18n.text.UrlEncoding;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.Feed;
 import org.apache.abdera.parser.ParseException;
-import org.apache.abdera.protocol.server.CollectionAdapter;
 import org.apache.abdera.protocol.server.ProviderHelper;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
@@ -40,11 +36,11 @@
 import org.apache.abdera.protocol.server.context.StreamWriterResponseContext;
 import org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter;
 import org.apache.abdera.util.Constants;
-import org.apache.abdera.util.MimeTypeHelper;
 import org.apache.abdera.writer.StreamWriter;
 
 @SuppressWarnings("unchecked")
-public class SimpleAdapter extends AbstractCollectionAdapter {
+public class SimpleAdapter 
+  extends AbstractCollectionAdapter {
   
   @Override
   public String getAuthor() throws ResponseContextException {

Modified: incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/Customer.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/Customer.java?rev=614798&r1=614767&r2=614798&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/Customer.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/Customer.java
Wed Jan 23 21:38:20 2008
@@ -1,6 +1,4 @@
-package org.apache.abdera.protocol.server.customer;
-
-import java.util.Date;
+package org.apache.abdera.protocol.server.test.customer;
 
 public class Customer {
   private int id;

Modified: incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapter.java?rev=614798&r1=614767&r2=614798&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapter.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapter.java
Wed Jan 23 21:38:20 2008
@@ -1,6 +1,5 @@
-package org.apache.abdera.protocol.server.customer;
+package org.apache.abdera.protocol.server.test.customer;
 
-import java.io.IOException;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;

Modified: incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java?rev=614798&r1=614767&r2=614798&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
(original)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
Wed Jan 23 21:38:20 2008
@@ -1,10 +1,12 @@
-package org.apache.abdera.protocol.server.customer;
+package org.apache.abdera.protocol.server.test.customer;
 
 import java.io.IOException;
 import java.util.Date;
 
 import javax.xml.namespace.QName;
 
+import junit.framework.TestCase;
+
 import org.apache.abdera.Abdera;
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.i18n.iri.IRI;
@@ -24,8 +26,6 @@
 import org.mortbay.jetty.servlet.Context;
 import org.mortbay.jetty.servlet.ServletHolder;
 
-import junit.framework.TestCase;
-
 public class CustomerAdapterTest extends TestCase {
 
   private Server server;
@@ -102,6 +102,7 @@
     System.out.println();
   }
 
+  @SuppressWarnings("serial") 
   private void initializeJetty() throws Exception {
 
     server = new Server(9002);

Modified: incubator/abdera/java/branches/server_refactor_all/server/src/test/resources/abdera/adapter/sample.properties
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor_all/server/src/test/resources/abdera/adapter/sample.properties?rev=614798&r1=614797&r2=614798&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor_all/server/src/test/resources/abdera/adapter/sample.properties
(original)
+++ incubator/abdera/java/branches/server_refactor_all/server/src/test/resources/abdera/adapter/sample.properties
Wed Jan 23 21:38:20 2008
@@ -1,4 +1,4 @@
-feedUri=http://localhost:8080/sample
+feedUri=http://localhost:9002/sample
 adapterClassName=org.apache.abdera.protocol.server.test.basic.SampleBasicAdapter
 title=title for any sample feed
 author=rayc



Mime
View raw message