abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r597807 - in /incubator/abdera/java/trunk: ./ dependencies/i18n/ jcr/ jcr/src/main/java/org/apache/abdera/jcr/ jcr/src/main/resources/org/ jcr/src/main/resources/org/apache/ jcr/src/main/resources/org/apache/abdera/ jcr/src/main/resources/o...
Date Sat, 24 Nov 2007 05:24:50 GMT
Author: dandiep
Date: Fri Nov 23 21:24:45 2007
New Revision: 597807

URL: http://svn.apache.org/viewvc?rev=597807&view=rev
Log:
Make JCR stuff more robust. Pool Sessions. Store entires by their name to prevent duplicates.


Also, remove json from the maven build as it does not make sense to
publish 1.0 jars of the json build every time I publish a snapshot. 
JSON seems to be set in stone. If we change it any of the code we should
change the version number and release it, but otherwise I don't see
any reason to build/deploy it all the time.


Added:
    incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/SessionPoolManager.java
  (with props)
    incubator/abdera/java/trunk/jcr/src/main/resources/org/
    incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/
    incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/
    incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/jcr/
    incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/jcr/nodeTypes.xml
  (with props)
Modified:
    incubator/abdera/java/trunk/dependencies/i18n/pom.xml
    incubator/abdera/java/trunk/jcr/pom.xml
    incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
    incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionProviderTest.java
    incubator/abdera/java/trunk/pom.xml
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractItemManager.java

Modified: incubator/abdera/java/trunk/dependencies/i18n/pom.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/pom.xml?rev=597807&r1=597806&r2=597807&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/pom.xml (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/pom.xml Fri Nov 23 21:24:45 2007
@@ -74,12 +74,12 @@
     <snapshotRepository>
       <id>apache.snapshots</id>
       <name>Apache SNAPSHOT Repository</name>
-      <url>scp://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
+      <url>scpexe://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
     </snapshotRepository>
     <repository>
       <id>apache.incubating</id>
       <name>Apache Incubating Repository</name>
-      <url>scp://people.apache.org/www/people.apache.org/repo/m2-incubating-repository</url>
+      <url>scpexe://people.apache.org/www/people.apache.org/repo/m2-incubating-repository</url>
     </repository>
   </distributionManagement>
 </project>

Modified: incubator/abdera/java/trunk/jcr/pom.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/jcr/pom.xml?rev=597807&r1=597806&r2=597807&view=diff
==============================================================================
--- incubator/abdera/java/trunk/jcr/pom.xml (original)
+++ incubator/abdera/java/trunk/jcr/pom.xml Fri Nov 23 21:24:45 2007
@@ -44,6 +44,21 @@
   </scm>
   
   <dependencies>
+      
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty</artifactId>
+      <version>6.1.5</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-jdk14</artifactId>
+      <version>1.4.3</version>
+      <scope>test</scope>
+    </dependency>
+    
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
@@ -63,21 +78,23 @@
     </dependency>
     
     <dependency>
+      <groupId>org.apache.abdera</groupId>
+      <artifactId>abdera-spring</artifactId>
+      <version>0.4.0-incubating-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-core</artifactId>
       <version>1.3.1</version>
     </dependency>
-
+    
     <dependency>
-      <groupId>org.mortbay.jetty</groupId>
-      <artifactId>jetty</artifactId>
-      <version>6.1.5</version>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>jackrabbit-core</artifactId>
+      <version>1.3.1</version>
     </dependency>
 
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-jdk14</artifactId>
-      <version>1.4.3</version>
-    </dependency>
   </dependencies>
 </project>

Modified: incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java?rev=597807&r1=597806&r2=597807&view=diff
==============================================================================
--- incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
(original)
+++ incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionProvider.java
Fri Nov 23 21:24:45 2007
@@ -2,19 +2,14 @@
 
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Calendar;
-import java.util.Collections;
 import java.util.Date;
 import java.util.List;
-import java.util.logging.Logger;
 
 import javax.activation.MimeType;
-import javax.jcr.AccessDeniedException;
 import javax.jcr.Credentials;
-import javax.jcr.InvalidItemStateException;
 import javax.jcr.ItemExistsException;
-import javax.jcr.ItemNotFoundException;
+import javax.jcr.NamespaceException;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
@@ -25,13 +20,7 @@
 import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryManager;
-import javax.jcr.query.QueryResult;
-import javax.jcr.version.VersionException;
+import javax.jcr.Workspace;
 
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.model.Content;
@@ -44,8 +33,13 @@
 import org.apache.abdera.protocol.server.impl.EmptyResponseContext;
 import org.apache.abdera.protocol.server.impl.ResponseContextException;
 import org.apache.abdera.protocol.util.EncodingUtil;
+import org.apache.abdera.protocol.util.PoolManager;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
+import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
 
 public class JcrCollectionProvider extends AbstractCollectionProvider<Node> {
 
@@ -55,8 +49,6 @@
 
   private static final String SUMMARY = "summary";
 
-  private static final String ENTRY = "entry";
-
   private static final String UPDATED = "updated";
 
   private static final String AUTHOR = "author";
@@ -69,15 +61,13 @@
 
   private static final String CONTENT = "content";
 
-  private static final String RESOURCE_NAME = "resourceName";
-
-  private static final String SESSION = "jcrSession";
+  private static final String SESSION_KEY = "jcrSession";
 
   private static final String MEDIA = "media";
 
   private static final String CONTENT_TYPE = "contentType";
 
-  private Repository repository;
+  private static final String NAMESPACE = "http://abdera.apache.org";
 
   private String collectionNodePath;
 
@@ -87,22 +77,35 @@
 
   private String author;
 
-  private Credentials credentials;
-
   private String collectionNodeId;
 
-  public JcrCollectionProvider(String title, String author, String collectionNodePath, Repository
repository,
-                               Credentials credentials) throws RepositoryException {
-    super();
+  private Repository repository;
+
+  private Credentials credentials;
+  
+  private int maxActiveSessions = 100;
+  
+  private PoolManager<Session> sessionPool;
+  
+  public void setCollectionNodePath(String collectionNodePath) {
+    this.collectionNodePath = collectionNodePath;
+  }
+
+  public void setTitle(String title) {
     this.title = title;
+  }
+
+  public void setAuthor(String author) {
     this.author = author;
-    this.collectionNodePath = collectionNodePath;
-    this.credentials = credentials;
-    this.repository = repository;
   }
 
-  public void initialize() throws RepositoryException {
-    Session session = createSession();
+  /**
+   * Logs into the repository and creates a node for the collection if one does not exist.
Also,
+   * this will set up the session pool.
+   * @throws RepositoryException
+   */
+  public void initialize() throws Exception {
+    Session session = repository.login(credentials);
 
     Node collectionNode = null;
     try {
@@ -112,11 +115,39 @@
       collectionNode.addMixin("mix:referenceable");
       session.save();
     }
-
+    
     this.collectionNodeId = collectionNode.getUUID();
     this.id = "urn:" + collectionNodeId;
 
+    // UGH, Jackrabbit specific code
+    Workspace workspace = session.getWorkspace();
+    try {
+      workspace.getNamespaceRegistry().getPrefix(NAMESPACE);
+    } catch (NamespaceException e) {
+      workspace.getNamespaceRegistry().registerNamespace("abdera", NAMESPACE);
+    }
+    
+    NodeTypeDef[] nodeTypes = NodeTypeReader.read(getClass().getResourceAsStream("/org/apache/abdera/jcr/nodeTypes.xml"));
+
+    // Get the NodeTypeManager from the Workspace.
+    // Note that it must be cast from the generic JCR NodeTypeManager to the
+    // Jackrabbit-specific implementation.
+    NodeTypeManagerImpl ntmgr =(NodeTypeManagerImpl)workspace.getNodeTypeManager();
+    
+    // Acquire the NodeTypeRegistry
+    NodeTypeRegistry ntreg = ntmgr.getNodeTypeRegistry();
+
+    // Loop through the prepared NodeTypeDefs
+    for (NodeTypeDef ntd : nodeTypes) {
+        // ...and register it
+        if (!ntreg.isRegistered(ntd.getName())) {
+          ntreg.registerNodeType(ntd);
+        }
+    }
+
     session.logout();
+    
+    sessionPool = new SessionPoolManager(maxActiveSessions, repository, credentials);
   }
 
   @Override
@@ -124,10 +155,10 @@
     super.begin(request);
 
     try {
-      Session session = createSession();
+      Session session = (Session) sessionPool.get(request);
 
-      request.setAttribute(Scope.REQUEST, SESSION, session);
-    } catch (RepositoryException e) {
+      request.setAttribute(Scope.REQUEST, SESSION_KEY, session);
+    } catch (Exception e) {
       throw new ResponseContextException(500, e);
     }
   }
@@ -137,16 +168,16 @@
     // Logout of the JCR session
     Session session = getSession(request);
     if (session != null) {
-     // session.logout();
+      try {
+        sessionPool.release(session);
+      } catch (Exception e) {
+        log.warn("Could not return Session to pool!", e);
+      }
     }
 
     super.end(request, response);
   }
 
-  protected Session createSession() throws RepositoryException {
-    return repository.login(credentials);
-  }
-
 
   @Override
   public String getContentType(Node entry) {
@@ -208,18 +239,15 @@
   @Override
   public Node createEntry(String title, IRI id, String summary, Date updated, List<Person>
authors,
                           Content content, RequestContext request) throws ResponseContextException
{
-    
     Node entry = null;
     try {
       Session session = getSession(request);
 
       Node collectionNode = session.getNodeByUUID(collectionNodeId);
-      entry = collectionNode.addNode(ENTRY);
-      entry.addMixin("mix:referenceable");
-
-      mapEntryToNode(entry, title, summary, updated, authors, content, session);
-      
-      session.save();
+      String resourceName = EncodingUtil.sanitize(title);
+      entry =  createEntry(title, summary, updated, authors, 
+                           content, session, collectionNode,
+                           resourceName, 0);
       
       return entry;
     } catch (RepositoryException e) {
@@ -233,11 +261,36 @@
     }
   }
 
+  private Node createEntry(String title, String summary, 
+                           Date updated, List<Person> authors, 
+                           Content content, Session session, 
+                           Node collectionNode, String resourceName, int num)
+    throws ResponseContextException, RepositoryException {
+    try {
+      String name = resourceName;
+      if (num > 0) {
+        name = name + "_" + num;
+      }
+      
+      Node entry = collectionNode.addNode(name, "abdera:entry");
+      
+      entry.addMixin("mix:referenceable");
+
+      mapEntryToNode(entry, title, summary, updated, authors, content, session);
+      
+      session.save();
+      
+      return entry;
+    }
+    catch (ItemExistsException e) 
+    {
+      return createEntry(title, summary, updated, authors, content, session, collectionNode,
resourceName, num++);
+    }
+  }
+
   private Node mapEntryToNode(Node entry, String title, String summary, Date updated, List<Person>
authors,
-                              Content content, Session session) throws ResponseContextException,
-    ValueFormatException, VersionException, LockException, ConstraintViolationException,
RepositoryException,
-    ItemExistsException, PathNotFoundException, AccessDeniedException, InvalidItemStateException,
-    NoSuchNodeTypeException {
+                              Content content, Session session)
+    throws ResponseContextException, RepositoryException {
     if (title == null) {
       EmptyResponseContext ctx = new EmptyResponseContext(500);
       ctx.setStatusText("Entry title cannot be empty.");
@@ -246,11 +299,6 @@
 
     entry.setProperty(TITLE, title);
 
-    // TODO: figure out a full proof way to check for entries with this same
-    // resource name
-    String resourceName = EncodingUtil.sanitize(title);
-    entry.setProperty(RESOURCE_NAME, resourceName);
-
     if (summary != null) {
       entry.setProperty(SUMMARY, summary);
     }
@@ -280,7 +328,7 @@
   }
 
   private Session getSession(RequestContext request) {
-    return (Session)request.getAttribute(Scope.REQUEST, SESSION);
+    return (Session)request.getAttribute(Scope.REQUEST, SESSION_KEY);
   }
 
   @Override
@@ -299,22 +347,11 @@
 
   private Node getNode(Session session, String resourceName) throws ResponseContextException,
     RepositoryException {
-    QueryManager qm = session.getWorkspace().getQueryManager();
-
-    StringBuffer qStr = new StringBuffer();
-    qStr.append("//*[@jcr:uuid='").append(collectionNodeId).append("']/entry[@").append(RESOURCE_NAME)
-      .append("='").append(resourceName).append("']");
-    
-    Query query = qm.createQuery(qStr.toString(), Query.XPATH);
-
-    QueryResult execute = query.execute();
-
-    NodeIterator nodes = execute.getNodes();
-    if (!nodes.hasNext()) {
+    try {
+      return session.getNodeByUUID(collectionNodeId).getNode(resourceName);
+    } catch (PathNotFoundException e) {
       throw new ResponseContextException(404);
     }
-
-    return nodes.nextNode();
   }
 
   /** Recursively outputs the contents of the given node. */
@@ -460,7 +497,11 @@
   
   @Override
   public String getName(Node entry) throws ResponseContextException {
-    return getStringOrNull(entry, RESOURCE_NAME);
+    try {
+      return entry.getName();
+    } catch (RepositoryException e) {
+      throw new ResponseContextException(500, e);
+    }
   }
 
   @Override
@@ -512,16 +553,16 @@
     return null;
   }
 
-  public static Calendar getDateOrNull(Node node, String propName) {
+  public static Calendar getDateOrNull(Node node, String propName) throws ResponseContextException
{
     try {
       Value v = getValueOrNull(node, propName);
       if (v != null) {
         return v.getDate();
       }
     } catch (ValueFormatException e) {
-      throw new RuntimeException(e);
+      throw new ResponseContextException(500, e);
     } catch (RepositoryException e) {
-      throw new RuntimeException(e);
+      throw new ResponseContextException(500, e);
     }
 
     return null;
@@ -541,6 +582,18 @@
     }
 
     return p.getValue();
+  }
+
+  public void setRepository(Repository repository) {
+    this.repository = repository;
+  }
+
+  public void setCredentials(Credentials credentials) {
+    this.credentials = credentials;
+  }
+
+  public void setMaxActiveSessions(int maxActiveSessions) {
+    this.maxActiveSessions = maxActiveSessions;
   }
 
 }

Added: incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/SessionPoolManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/SessionPoolManager.java?rev=597807&view=auto
==============================================================================
--- incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/SessionPoolManager.java
(added)
+++ incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/SessionPoolManager.java
Fri Nov 23 21:24:45 2007
@@ -0,0 +1,33 @@
+package org.apache.abdera.jcr;
+
+import javax.jcr.Credentials;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.abdera.protocol.Request;
+import org.apache.abdera.protocol.server.impl.AbstractItemManager;
+
+public class SessionPoolManager extends AbstractItemManager<Session> {
+  private Repository repository;
+  private Credentials credentials;
+  
+  public SessionPoolManager(int maxSize, Repository repository, Credentials credentials)
{
+    super(maxSize);
+    this.repository = repository;
+    this.credentials = credentials;
+  }
+  
+  @Override
+  protected Session internalNewInstance() {
+    try {
+      return repository.login(credentials);
+    } catch (RepositoryException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public Session get(Request request) {
+    return getInstance();
+  }
+}

Propchange: incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/SessionPoolManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/SessionPoolManager.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/SessionPoolManager.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/jcr/nodeTypes.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/jcr/nodeTypes.xml?rev=597807&view=auto
==============================================================================
--- incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/jcr/nodeTypes.xml
(added)
+++ incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/jcr/nodeTypes.xml
Fri Nov 23 21:24:45 2007
@@ -0,0 +1,18 @@
+<nodeTypes xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+  xmlns:jcr="http://www.jcp.org/jcr/1.0" 
+  xmlns:abdera="http://abdera.apache.org"
+  xmlns:mix="http://www.jcp.org/jcr/mix/1.0">
+
+  <nodeType name="abdera:entry" 
+    isMixin="false" 
+    hasOrderableChildNodes="false"
+    primaryItemName="" 
+    allowSameNameSiblings="false">
+    
+    <supertypes>
+      <supertype>nt:unstructured</supertype>
+    </supertypes>
+    
+  </nodeType>
+
+</nodeTypes>

Propchange: incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/jcr/nodeTypes.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/jcr/nodeTypes.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/jcr/nodeTypes.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/abdera/java/trunk/jcr/src/main/resources/org/apache/abdera/jcr/nodeTypes.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionProviderTest.java?rev=597807&r1=597806&r2=597807&view=diff
==============================================================================
--- incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionProviderTest.java
(original)
+++ incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionProviderTest.java
Fri Nov 23 21:24:45 2007
@@ -44,157 +44,162 @@
 
 public class JcrCollectionProviderTest extends TestCase {
 
-    private Server server;
-    private DefaultServiceContext abderaServiceContext;
-    private Repository repository;
-
-    @Override
-    protected void setUp() throws Exception {
-      super.setUp();
-      
-      abderaServiceContext = new DefaultServiceContext();
-
-      RegexTargetResolver resolver = new RegexTargetResolver();
-      resolver.setPattern("/acme(\\?[^#]*)?", TargetType.TYPE_SERVICE);
-      resolver.setPattern("/acme/feed(\\?[^#]*)?", TargetType.TYPE_COLLECTION);
-      resolver.setPattern("/acme/feed/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY);
-      abderaServiceContext.setTargetResolver(resolver);
-      
-      SingletonProviderManager pm = new SingletonProviderManager();
-      abderaServiceContext.setProviderManager(pm);
-
-      WorkspaceProvider wp = new WorkspaceProvider();
-
-      SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
-      wi.setId("acme");
-      
-      repository = new TransientRepository();
-      JcrCollectionProvider cp = 
-          new JcrCollectionProvider("My Entries", 
-                                    "Apache Abdera", 
-                                    "entries", 
-                                    repository,
-                                    new SimpleCredentials("username", "bogus".toCharArray()));
-      cp.initialize();
-      
-      Map<String, CollectionProvider> contentProviders = new HashMap<String, CollectionProvider>();
-      contentProviders.put("feed", cp);
-      
-      wi.setCollectionProviders(contentProviders);
-
-      List<WorkspaceInfo> workspaces = new ArrayList<WorkspaceInfo>();
-      workspaces.add(wi);
-      wp.setWorkspaces(workspaces);
-      pm.setProvider(wp);
+  private Server server;
+  private DefaultServiceContext abderaServiceContext;
+  private Repository repository;
 
-      initializeJetty();
-    }
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
 
-    public void testCustomerProvider() throws Exception {
+    abderaServiceContext = new DefaultServiceContext();
 
-      Abdera abdera = new Abdera();
-      Factory factory = abdera.getFactory();
+    RegexTargetResolver resolver = new RegexTargetResolver();
+    resolver.setPattern("/acme(\\?[^#]*)?", TargetType.TYPE_SERVICE);
+    resolver.setPattern("/acme/feed(\\?[^#]*)?", TargetType.TYPE_COLLECTION);
+    resolver.setPattern("/acme/feed/([^/#?]+)(\\?[^#]*)?", TargetType.TYPE_ENTRY);
+    abderaServiceContext.setTargetResolver(resolver);
 
-      AbderaClient client = new AbderaClient(abdera);
+    SingletonProviderManager pm = new SingletonProviderManager();
+    abderaServiceContext.setProviderManager(pm);
 
-      String base = "http://localhost:9002/";
+    WorkspaceProvider wp = new WorkspaceProvider();
 
-      // Testing of entry creation
-      IRI colUri = new IRI(base).resolve("acme/feed");
-      Entry entry = factory.newEntry();
-      entry.setTitle("Some Entry");
-      entry.setUpdated(new Date());
-      entry.addAuthor("Dan Diephouse");
-      entry.setId(factory.newUuidUri());
-      entry.setSummary("This is my entry.");
-      entry.setContent("This is my entry. It's swell.");
-      
-      RequestOptions opts = new RequestOptions();
-      opts.setContentType("application/atom+xml;type=entry");
-      ClientResponse res = client.post(colUri.toString(), entry, opts);
-      assertEquals(201, res.getStatus());
-
-      //prettyPrint(abdera, res.getDocument());
-
-      IRI location = res.getLocation();
-      assertEquals(colUri + "/Some%20Entry", 
-                   location.toString());
-
-      // GET the entry
-      res = client.get(location.toString());
-      assertEquals(200, res.getStatus());
-
-      //prettyPrint(abdera, res.getDocument());
-      org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
-      Entry entry2 = entry_doc.getRoot();
-
-      assertEquals(entry.getTitle(), entry2.getTitle());
-      assertEquals(entry.getSummary(), entry2.getSummary());
-      assertEquals(entry.getContent(), entry2.getContent());
-      
-      List<Person> authors = entry2.getAuthors();
-      assertEquals(1, authors.size());
-      
-      entry = entry2;
-      entry.setSummary("New Summary");
-      entry.setContent("New Content");
-      res = client.put(location.toString(), entry, opts);
-      assertEquals(204, res.getStatus());
-      
-      res = client.get(colUri.toString());
-      org.apache.abdera.model.Document<Feed> feed_doc = res.getDocument();
-      Feed feed = feed_doc.getRoot();
-      
-      assertEquals(1, feed.getEntries().size());
-      //prettyPrint(abdera, feed_doc);
-    }
+    SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
+    wi.setId("acme");
 
-    protected void prettyPrint(Abdera abdera, Base doc) throws IOException {
-      Writer writer = abdera.getWriterFactory().getWriter("prettyxml");
-      writer.writeTo(doc, System.out);
-      System.out.println();
-    }
+    repository = new TransientRepository();
     
-    private void clearJcrRepository() {
-      try {
-          Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()));
-
-          Node node = session.getRootNode();
-
-          for (NodeIterator itr = node.getNodes(); itr.hasNext();) {
-              Node child = itr.nextNode();
-              if (!child.getName().equals("jcr:system")) {
-                  child.remove();
-              }
-          }
-          session.save();
-          session.logout();
-      } catch (PathNotFoundException t) {
-      } catch (Throwable t) {
-          t.printStackTrace();
-      }
+    JcrCollectionProvider cp = new JcrCollectionProvider();
+    cp.setTitle("My Entries");
+    cp.setAuthor("Apache Abdera");
+    cp.setCollectionNodePath("entries");         
+    cp.setRepository(repository);
+    cp.setCredentials(new SimpleCredentials("username", "pass".toCharArray()));
+    cp.initialize();
+
+    Map<String, CollectionProvider> contentProviders = new HashMap<String, CollectionProvider>();
+    contentProviders.put("feed", cp);
+
+    wi.setCollectionProviders(contentProviders);
+
+    List<WorkspaceInfo> workspaces = new ArrayList<WorkspaceInfo>();
+    workspaces.add(wi);
+    wp.setWorkspaces(workspaces);
+    pm.setProvider(wp);
+
+    initializeJetty();
   }
 
-    private void initializeJetty() throws Exception {
+  public void testCustomerProvider() throws Exception {
+    Abdera abdera = new Abdera();
+    Factory factory = abdera.getFactory();
+
+    AbderaClient client = new AbderaClient(abdera);
+
+    String base = "http://localhost:9002/";
+
+    // Testing of entry creation
+    IRI colUri = new IRI(base).resolve("acme/feed");
+    Entry entry = factory.newEntry();
+    entry.setTitle("Some Entry");
+    entry.setUpdated(new Date());
+    entry.addAuthor("Dan Diephouse");
+    entry.setId(factory.newUuidUri());
+    entry.setSummary("This is my entry.");
+    entry.setContent("This is my entry. It's swell.");
+
+    RequestOptions opts = new RequestOptions();
+    opts.setContentType("application/atom+xml;type=entry");
+    ClientResponse res = client.post(colUri.toString(), entry, opts);
+    assertEquals(201, res.getStatus());
+
+    //prettyPrint(abdera, res.getDocument());
+
+    IRI location = res.getLocation();
+    assertEquals(colUri + "/Some%20Entry", location.toString());
+
+    // GET the entry
+    res = client.get(location.toString());
+    assertEquals(200, res.getStatus());
+
+    //prettyPrint(abdera, res.getDocument());
+    org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
+    Entry entry2 = entry_doc.getRoot();
+
+    assertEquals(entry.getTitle(), entry2.getTitle());
+    assertEquals(entry.getSummary(), entry2.getSummary());
+    assertEquals(entry.getContent(), entry2.getContent());
+
+    List<Person> authors = entry2.getAuthors();
+    assertEquals(1, authors.size());
+
+    entry = entry2;
+    entry.setSummary("New Summary");
+    entry.setContent("New Content");
+
+    res = client.put(location.toString(), entry, opts);
+    assertEquals(204, res.getStatus());
+
+    res = client.get(colUri.toString());
+    org.apache.abdera.model.Document<Feed> feed_doc = res.getDocument();
+    Feed feed = feed_doc.getRoot();
+
+    assertEquals(1, feed.getEntries().size());
+    //prettyPrint(abdera, feed_doc);
+
+    // test 404 not found
+    res = client.get(location.toString() + "Invalid");
+    assertEquals(404, res.getStatus());
+  }
 
-      server = new Server(9002);
-      Context root = new Context(server, "/", Context.NO_SESSIONS);
-      root.addServlet(new ServletHolder(new AbderaServlet() {
-
-        @Override
-        protected ServiceContext createServiceContext() {
-          abderaServiceContext.init(getAbdera(), getProperties(getServletConfig()));
-          return abderaServiceContext;
+  protected void prettyPrint(Abdera abdera, Base doc) throws IOException {
+    Writer writer = abdera.getWriterFactory().getWriter("prettyxml");
+    writer.writeTo(doc, System.out);
+    System.out.println();
+  }
+  
+  private void clearJcrRepository() {
+    try {
+      Session session = repository.login(new SimpleCredentials("username", "password".toCharArray()));
+
+      Node node = session.getRootNode();
+
+      for (NodeIterator itr = node.getNodes(); itr.hasNext();) {
+        Node child = itr.nextNode();
+        if (!child.getName().equals("jcr:system")) {
+          child.remove();
         }
-      }), "/*");
-      server.start();
+      }
+      session.save();
+      session.logout();
+    } catch (PathNotFoundException t) {
+    } catch (Throwable t) {
+      t.printStackTrace();
     }
+  }
 
-    @Override
-    protected void tearDown() throws Exception {
-      clearJcrRepository();
+  private void initializeJetty() throws Exception {
 
-      if (server != null) server.stop();
-    }
+    server = new Server(9002);
+    Context root = new Context(server, "/", Context.NO_SESSIONS);
+    root.addServlet(new ServletHolder(new AbderaServlet() {
+
+      @Override
+      protected ServiceContext createServiceContext() {
+        abderaServiceContext.init(getAbdera(), getProperties(getServletConfig()));
+        return abderaServiceContext;
+      }
+    }), "/*");
+    server.start();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    clearJcrRepository();
+
+    if (server != null)
+      server.stop();
+  }
 
 }

Modified: incubator/abdera/java/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/pom.xml?rev=597807&r1=597806&r2=597807&view=diff
==============================================================================
--- incubator/abdera/java/trunk/pom.xml (original)
+++ incubator/abdera/java/trunk/pom.xml Fri Nov 23 21:24:45 2007
@@ -265,7 +265,6 @@
   
   <modules>
     <module>dependencies/i18n</module>
-    <module>dependencies/json</module>
     <module>core</module>
     <module>parser</module>
     <module>protocol</module>
@@ -289,12 +288,12 @@
     <snapshotRepository>
       <id>apache.snapshots</id>
       <name>Apache SNAPSHOT Repository</name>
-      <url>scp://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
+      <url>scpexe://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
     </snapshotRepository>
     <repository>
       <id>apache.incubating</id>
       <name>Apache Incubating Repository</name>
-      <url>scp://people.apache.org/www/people.apache.org/repo/m2-incubating-repository</url>
+      <url>scpexe://people.apache.org/www/people.apache.org/repo/m2-incubating-repository</url>
     </repository>
   </distributionManagement>
 </project>

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractItemManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractItemManager.java?rev=597807&r1=597806&r2=597807&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractItemManager.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractItemManager.java
Fri Nov 23 21:24:45 2007
@@ -25,6 +25,14 @@
   extends PoolManager<T>
   implements ItemManager<T> {
 
+  public AbstractItemManager() {
+    super();
+  }
+
+  public AbstractItemManager(int max) {
+    super(max);
+  }
+
   public T get(Request request) {
     return getInstance();
   }



Mime
View raw message