Author: fguillaume
Date: Wed Dec 9 16:32:06 2009
New Revision: 888861
URL: http://svn.apache.org/viewvc?rev=888861&view=rev
Log:
CMIS-72: add JAX-RS bridge of entry POST in children collection
Added:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/resources/templates/
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/resources/templates/createdocument.atomentry.xml
(with props)
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=888861&r1=888860&r2=888861&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
Wed Dec 9 16:32:06 2009
@@ -13,6 +13,7 @@
*
* Authors:
* Florent Guillaume, Nuxeo
+ * Florian Roth, In-integrierte Informationssysteme
*/
package org.apache.chemistry.atompub.server.jaxrs;
@@ -28,7 +29,9 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.protocol.server.CollectionAdapter;
import org.apache.abdera.protocol.server.RequestContext;
import org.apache.abdera.protocol.server.ResponseContext;
@@ -164,15 +167,37 @@
requestContext);
}
+ protected Response getResponse(ResponseContext responseContext) {
+ ResponseBuilder b = Response.status(responseContext.getStatus());
+ b.entity(responseContext);
+ String contentType = responseContext.getHeader("Content-Type");
+ b.type(contentType);
+ IRI location = responseContext.getLocation();
+ if (location != null) {
+ try {
+ b.location(location.toURI());
+ } catch (Exception e) {
+ log.error("Bad Location: " + location, e);
+ }
+ }
+ IRI contentLocation = responseContext.getContentLocation();
+ if (contentLocation != null) {
+ try {
+ b.contentLocation(contentLocation.toURI());
+ } catch (Exception e) {
+ log.error("Bad Content-Location: " + contentLocation, e);
+ }
+ }
+ return b.build();
+ }
+
protected Response getAbderaFeed(int skipSegments) {
RequestContext requestContext = getRequestContext(skipSegments);
CollectionAdapter adapter = getAbderaCollectionAdapter(requestContext);
if (adapter == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
- ResponseContext responseContext = adapter.getFeed(requestContext);
- return Response.status(responseContext.getStatus()).entity(
- responseContext).build();
+ return getResponse(adapter.getFeed(requestContext));
}
protected Response getAbderaEntry(int skipSegments) {
@@ -181,20 +206,16 @@
if (adapter == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
- ResponseContext responseContext = adapter.getEntry(requestContext);
- return Response.status(responseContext.getStatus()).entity(
- responseContext).build();
+ return getResponse(adapter.getEntry(requestContext));
}
- protected Response getAbderaPostFeed(int skipSegments) {
+ protected Response getAbderaPostEntry(int skipSegments) {
RequestContext requestContext = getRequestContext(skipSegments);
CollectionAdapter adapter = getAbderaCollectionAdapter(requestContext);
if (adapter == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
- ResponseContext responseContext = adapter.postEntry(requestContext);
- return Response.status(responseContext.getStatus()).entity(
- responseContext).build();
+ return getResponse(adapter.postEntry(requestContext));
}
@GET
@@ -202,9 +223,7 @@
@Path("repository")
public Response doGetRepository(@Context HttpServletRequest httpRequest) {
RequestContext requestContext = getRequestContext(1);
- ResponseContext responseContext =
provider.getServiceDocument(requestContext);
- return Response.status(responseContext.getStatus()).entity(
- responseContext).build();
+ return getResponse(provider.getServiceDocument(requestContext));
}
@GET
@@ -244,6 +263,14 @@
return getAbderaFeed(2);
}
+ @POST
+ @Consumes(AtomPub.MEDIA_TYPE_ATOM_ENTRY)
+ @Path("children/{objectid}")
+ public Response doPostChildren() {
+ // objectid decoded by Abdera getCollectionAdapter
+ return getAbderaPostEntry(2);
+ }
+
@GET
@Produces(AtomPub.MEDIA_TYPE_ATOM_ENTRY)
@Path("object/{objectid}")
@@ -258,10 +285,7 @@
// objectid decoded by Abdera getCollectionAdapter
RequestContext requestContext = getRequestContext(2);
AbstractCollectionAdapter adapter = (AbstractCollectionAdapter)
getAbderaCollectionAdapter(requestContext);
- ResponseContext responseContext = adapter.getMedia(requestContext);
- String contentType = responseContext.getHeader("Content-Type");
- return Response.status(responseContext.getStatus()).entity(
- responseContext).type(contentType).build();
+ return getResponse(adapter.getMedia(requestContext));
}
@POST
@@ -269,7 +293,7 @@
@Produces(AtomPub.MEDIA_TYPE_ATOM_FEED)
@Path("query")
public Response doPostQuery() {
- return getAbderaPostFeed(1);
+ return getAbderaPostEntry(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=888861&r1=888860&r2=888861&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
Wed Dec 9 16:32:06 2009
@@ -14,11 +14,15 @@
* Authors:
* Florent Guillaume, Nuxeo
* Amelie Avramo, EntropySoft
+ * Florian Roth, In-integrierte Informationssysteme
*/
package org.apache.chemistry.atompub.server;
+import java.io.InputStream;
import java.util.Arrays;
+import javax.ws.rs.core.HttpHeaders;
+
import junit.framework.TestCase;
import org.apache.abdera.model.Element;
@@ -40,6 +44,7 @@
import org.apache.chemistry.PropertyType;
import org.apache.chemistry.Repository;
import org.apache.chemistry.Updatability;
+import org.apache.chemistry.atompub.AtomPub;
import org.apache.chemistry.atompub.AtomPubCMIS;
import org.apache.chemistry.impl.simple.SimpleContentStream;
import org.apache.chemistry.impl.simple.SimplePropertyDefinition;
@@ -49,6 +54,10 @@
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.cxf.helpers.FileUtils;
+import org.apache.cxf.helpers.IOUtils;
import org.mortbay.jetty.Server;
public abstract class AtomPubServerTestCase extends TestCase {
@@ -57,6 +66,8 @@
protected static final AbderaClient client = new AbderaClient();
+ protected static String rootFolderId;
+
protected static String doc2id;
protected static String doc3id;
@@ -121,6 +132,7 @@
ft), rootId);
Connection conn = repo.getConnection(null);
Folder root = conn.getRootFolder();
+ rootFolderId = root.getId();
Folder folder1 = root.newFolder("fold");
folder1.setValue("title", "The folder 1 description");
@@ -174,8 +186,7 @@
Element el = resp.getDocument().getRoot();
assertNotNull(el);
- resp = client.get(base + "/children/"
- + repository.getInfo().getRootFolderId().getId());
+ resp = client.get(base + "/children/" + rootFolderId);
assertEquals(HttpStatus.SC_OK, resp.getStatus());
Element ch = resp.getDocument().getRoot();
assertNotNull(ch);
@@ -220,6 +231,21 @@
assertEquals(HttpStatus.SC_OK, resp.getStatus());
Element res = resp.getDocument().getRoot();
assertNotNull(res);
+
+ // post of new document
+ PostMethod postMethod = new PostMethod(base + "/children/"
+ + rootFolderId);
+ postMethod.setRequestEntity(new InputStreamRequestEntity(
+ load("templates/createdocument.atomentry.xml"),
+ AtomPub.MEDIA_TYPE_ATOM_ENTRY));
+ status = new HttpClient().executeMethod(postMethod);
+ assertEquals(HttpStatus.SC_CREATED, status);
+ assertNotNull(postMethod.getResponseHeader(HttpHeaders.LOCATION));
+
assertNotNull(postMethod.getResponseHeader(HttpHeaders.CONTENT_LOCATION));
+ }
+
+ protected InputStream load(String resource) throws Exception {
+ return getClass().getClassLoader().getResource(resource).openStream();
}
public static class QueryEntityProvider extends AbstractEntityProvider {
Added:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/resources/templates/createdocument.atomentry.xml
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/resources/templates/createdocument.atomentry.xml?rev=888861&view=auto
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/resources/templates/createdocument.atomentry.xml
(added)
+++
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/resources/templates/createdocument.atomentry.xml
Wed Dec 9 16:32:06 2009
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/"
xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/">
+ <id>urn:uuid:00000000-0000-0000-0000-000000000000</id>
+ <title>${NAME}</title>
+ <updated>2009-01-01T00:00:00Z</updated>
+ <author>admin</author>
+ <summary>${NAME} (summary)</summary>
+ <content type="text/html">${CONTENT}</content>
+ <cmisra:object>
+ <cmis:properties>
+ <cmis:propertyId propertyDefinitionId="cmis:objectTypeId">
+ <cmis:value>cmis:document</cmis:value>
+ </cmis:propertyId>
+ </cmis:properties>
+ </cmisra:object>
+</entry>
Propchange:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/resources/templates/createdocument.atomentry.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/resources/templates/createdocument.atomentry.xml
------------------------------------------------------------------------------
svn:keywords = Id