chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r787218 - in /incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src: main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
Date Mon, 22 Jun 2009 12:26:50 GMT
Author: fguillaume
Date: Mon Jun 22 12:26:49 2009
New Revision: 787218

URL: http://svn.apache.org/viewvc?rev=787218&view=rev
Log:
Added POST query processing to AtomPub server (abdera+jaxrs)

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java?rev=787218&r1=787217&r2=787218&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
Mon Jun 22 12:26:49 2009
@@ -20,6 +20,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
+import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
@@ -73,8 +74,10 @@
     }
 
     /**
-     * Gets a {@link ServletRequestContext} wrapping the httpRequest but
-     * pretending that this Resource's path is part of the servlet path.
+     * Gets a {@link ServletRequestContext} wrapping the httpRequest.
+     * <p>
+     * Wrapping is needed to fixup the servlet path to take include this
+     * Resource's path.
      *
      * @param segments the number of segments of the method invoking this, used
      *            to determine the Resource path
@@ -126,6 +129,12 @@
         return Response.ok(adapter.getEntry(requestContext)).build();
     }
 
+    protected Response getAbderaPostFeed(int skipSegments) {
+        RequestContext requestContext = getRequestContext(skipSegments);
+        CollectionAdapter adapter = getAbderaCollectionAdapter(requestContext);
+        return Response.ok(adapter.postEntry(requestContext)).build();
+    }
+
     @GET
     @Produces("application/atomsvc+xml")
     @Path("repository")
@@ -169,4 +178,12 @@
         return Response.ok(responseContext).type(contentType).build();
     }
 
+    @POST
+    @Consumes("application/cmisquery+xml")
+    @Produces("application/atom+xml;type=feed")
+    @Path("query")
+    public Response doPostQuery() {
+        return getAbderaPostFeed(1);
+    }
+
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java?rev=787218&r1=787217&r2=787218&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
Mon Jun 22 12:26:49 2009
@@ -24,8 +24,11 @@
 import org.apache.abdera.model.Element;
 import org.apache.abdera.model.Service;
 import org.apache.abdera.model.Workspace;
+import org.apache.abdera.protocol.EntityProvider;
 import org.apache.abdera.protocol.client.AbderaClient;
 import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.util.AbstractEntityProvider;
+import org.apache.abdera.writer.StreamWriter;
 import org.apache.chemistry.BaseType;
 import org.apache.chemistry.Connection;
 import org.apache.chemistry.ContentStream;
@@ -177,8 +180,50 @@
         assertEquals(HttpStatus.SC_OK, status);
         assertEquals("text/plain",
                 method.getResponseHeader("Content-Type").getValue());
+        assertEquals(String.valueOf(TEST_FILE_CONTENT.getBytes().length),
+                method.getResponseHeader("Content-Length").getValue());
         byte[] body = method.getResponseBody();
         assertEquals(TEST_FILE_CONTENT, new String(body, "UTF-8"));
         method.releaseConnection();
+
+        EntityProvider provider = new QueryEntityProvider("SELECT * FROM doc");
+        resp = client.post(base + "/query", provider);
+        assertEquals(200, resp.getStatus());
+        Element res = resp.getDocument().getRoot();
+        assertNotNull(res);
     }
+
+    public static class QueryEntityProvider extends AbstractEntityProvider {
+
+        public String statement;
+
+        public QueryEntityProvider(String statement) {
+            this.statement = statement;
+        }
+
+        @Override
+        public String getContentType() {
+            return "application/cmisquery+xml";
+        }
+
+        public boolean isRepeatable() {
+            return true;
+        }
+
+        public void writeTo(StreamWriter sw) {
+            sw.startDocument();
+            sw.startElement("query", CMIS.CMIS_NS, CMIS.CMIS_PREFIX);
+            sw.startElement("statement", CMIS.CMIS_NS, CMIS.CMIS_PREFIX).writeElementText(
+                    statement).endElement();
+            sw.startElement("searchAllVersions", CMIS.CMIS_NS, CMIS.CMIS_PREFIX).writeElementText(
+                    "false").endElement();
+            sw.startElement("pageSize", CMIS.CMIS_NS, CMIS.CMIS_PREFIX).writeElementText(
+                    0).endElement();
+            sw.startElement("skipCount", CMIS.CMIS_NS, CMIS.CMIS_PREFIX).writeElementText(
+                    0).endElement();
+            sw.endElement(); // query
+            sw.endDocument();
+        }
+    }
+
 }



Mime
View raw message