Author: fguillaume
Date: Wed Dec 9 14:02:33 2009
New Revision: 888805
URL: http://svn.apache.org/viewvc?rev=888805&view=rev
Log:
CMIS-68, CMIS-69: return 409 on empty content stream, don't swallow status
codes in JAX-RS bridge
Modified:
incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
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-api/src/main/java/org/apache/chemistry/SPI.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java?rev=888805&r1=888804&r2=888805&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java
Wed Dec 9 14:02:33 2009
@@ -391,6 +391,9 @@
* <p>
* A content stream ID can be provided, to access alternate content streams
* (renditions for instance).
+ * <p>
+ * If no content stream is available, {...@code null} may be returned or
+ * {...@link ConstraintViolationException} may be thrown.
*
* @param object the document or folder
* @param contentStreamId the content stream ID, or {...@code null}
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java?rev=888805&r1=888804&r2=888805&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
Wed Dec 9 14:02:33 2009
@@ -36,6 +36,7 @@
import org.apache.chemistry.BaseType;
import org.apache.chemistry.CMISObject;
import org.apache.chemistry.Connection;
+import org.apache.chemistry.ConstraintViolationException;
import org.apache.chemistry.ContentStream;
import org.apache.chemistry.Document;
import org.apache.chemistry.Folder;
@@ -450,6 +451,10 @@
}
Request req = new Request(href);
Response resp = connector.get(req);
+ int status = resp.getStatusCode();
+ if (status == 404 || status == 409) {
+ throw new ConstraintViolationException("No content stream");
+ }
if (!resp.isOk()) {
// TODO exceptions
throw new ContentManagerException(
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=888805&r1=888804&r2=888805&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
Wed Dec 9 14:02:33 2009
@@ -51,6 +51,7 @@
import org.apache.chemistry.BaseType;
import org.apache.chemistry.CMIS;
import org.apache.chemistry.CMISRuntimeException;
+import org.apache.chemistry.ConstraintViolationException;
import org.apache.chemistry.ContentStream;
import org.apache.chemistry.ObjectEntry;
import org.apache.chemistry.ObjectId;
@@ -582,30 +583,39 @@
return getObjectLink(object.getId(), request);
}
+ // override to use a custom SizedMediaResponseContext
+ // and return 409 on no content
@Override
- public InputStream getMediaStream(ObjectEntry object)
- throws ResponseContextException {
- // TODO entry was fetched for mostly nothing...
+ protected ResponseContext buildGetMediaResponse(String id,
+ ObjectEntry object) throws ResponseContextException {
+ Date updated = getUpdated(object);
SPI spi = repository.getSPI();
+ ContentStream contentStream;
try {
- ContentStream contentStream = spi.getContentStream(object, null);
- return contentStream == null ? null : contentStream.getStream();
+ contentStream = spi.getContentStream(object, null);
+ } catch (ConstraintViolationException e) {
+ contentStream = null;
} catch (IOException e) {
- throw new ResponseContextException(500, e);
+ return new EmptyResponseContext(500, e.toString());
} finally {
spi.close();
}
- }
-
- // override to use a custom SizedMediaResponseContext
- @Override
- protected ResponseContext buildGetMediaResponse(String id,
- ObjectEntry entryObj) throws ResponseContextException {
- Date updated = getUpdated(entryObj);
- SizedMediaResponseContext ctx = new SizedMediaResponseContext(
- getMediaStream(entryObj), updated, 200);
- ctx.setSize(getContentSize(entryObj));
- ctx.setContentType(getContentType(entryObj));
+ if (contentStream == null) {
+ return new EmptyResponseContext(409, "No content");
+ }
+ InputStream stream;
+ try {
+ stream = contentStream.getStream();
+ } catch (IOException e) {
+ return new EmptyResponseContext(500, e.toString());
+ }
+ if (stream == null) {
+ return new EmptyResponseContext(409, "No content");
+ }
+ SizedMediaResponseContext ctx = new SizedMediaResponseContext(stream,
+ updated, 200);
+ ctx.setSize(getContentSize(object));
+ ctx.setContentType(getContentType(object));
ctx.setEntityTag(EntityTag.generate(id, AtomDate.format(updated)));
return ctx;
}
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=888805&r1=888804&r2=888805&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 14:02:33 2009
@@ -170,7 +170,9 @@
if (adapter == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
- return Response.ok(adapter.getFeed(requestContext)).build();
+ ResponseContext responseContext = adapter.getFeed(requestContext);
+ return Response.status(responseContext.getStatus()).entity(
+ responseContext).build();
}
protected Response getAbderaEntry(int skipSegments) {
@@ -179,7 +181,9 @@
if (adapter == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
- return Response.ok(adapter.getEntry(requestContext)).build();
+ ResponseContext responseContext = adapter.getEntry(requestContext);
+ return Response.status(responseContext.getStatus()).entity(
+ responseContext).build();
}
protected Response getAbderaPostFeed(int skipSegments) {
@@ -188,7 +192,9 @@
if (adapter == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
- return Response.ok(adapter.postEntry(requestContext)).build();
+ ResponseContext responseContext = adapter.postEntry(requestContext);
+ return Response.status(responseContext.getStatus()).entity(
+ responseContext).build();
}
@GET
@@ -197,7 +203,8 @@
public Response doGetRepository(@Context HttpServletRequest httpRequest) {
RequestContext requestContext = getRequestContext(1);
ResponseContext responseContext =
provider.getServiceDocument(requestContext);
- return Response.ok(responseContext).build();
+ return Response.status(responseContext.getStatus()).entity(
+ responseContext).build();
}
@GET
@@ -253,7 +260,8 @@
AbstractCollectionAdapter adapter = (AbstractCollectionAdapter)
getAbderaCollectionAdapter(requestContext);
ResponseContext responseContext = adapter.getMedia(requestContext);
String contentType = responseContext.getHeader("Content-Type");
- return Response.ok(responseContext).type(contentType).build();
+ return Response.status(responseContext.getStatus()).entity(
+ responseContext).type(contentType).build();
}
@POST
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=888805&r1=888804&r2=888805&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 14:02:33 2009
@@ -57,6 +57,8 @@
protected static final AbderaClient client = new AbderaClient();
+ protected static String doc2id;
+
protected static String doc3id;
public Server server;
@@ -139,6 +141,7 @@
doc2.setValue("title", "doc 2 title");
doc2.setValue("description", "The doc 2 descr");
doc2.save();
+ doc2id = doc2.getId();
Document doc3 = folder2.newDocument("doc");
doc3.setValue("title", "doc 3 title");
@@ -159,7 +162,7 @@
ClientResponse resp;
resp = client.get(base + "/repository");
- assertEquals(200, resp.getStatus());
+ assertEquals(HttpStatus.SC_OK, resp.getStatus());
Service root = (Service) resp.getDocument().getRoot();
Workspace workspace = root.getWorkspaces().get(0);
assertNotNull(root);
@@ -167,31 +170,31 @@
assertNotNull(info);
resp = client.get(base + "/types");
- assertEquals(200, resp.getStatus());
+ assertEquals(HttpStatus.SC_OK, resp.getStatus());
Element el = resp.getDocument().getRoot();
assertNotNull(el);
resp = client.get(base + "/children/"
+ repository.getInfo().getRootFolderId().getId());
- assertEquals(200, resp.getStatus());
+ assertEquals(HttpStatus.SC_OK, resp.getStatus());
Element ch = resp.getDocument().getRoot();
assertNotNull(ch);
resp = client.get(base + "/children/"
+ repository.getInfo().getRootFolderId().getId() + "?"
+ AtomPubCMIS.PARAM_MAX_ITEMS + "=4");
- assertEquals(200, resp.getStatus());
+ assertEquals(HttpStatus.SC_OK, resp.getStatus());
ch = resp.getDocument().getRoot();
assertNotNull(ch);
resp = client.get(base + "/object/" + doc3id);
- assertEquals(200, resp.getStatus());
+ assertEquals(HttpStatus.SC_OK, resp.getStatus());
Element ob = resp.getDocument().getRoot();
assertNotNull(ob);
resp = client.get(base + "/object/" + doc3id + '?'
+ AtomPubCMIS.PARAM_FILTER + "=cmis:name");
- assertEquals(200, resp.getStatus());
+ assertEquals(HttpStatus.SC_OK, resp.getStatus());
ob = resp.getDocument().getRoot();
assertNotNull(ob);
@@ -206,9 +209,15 @@
assertEquals(TEST_FILE_CONTENT, new String(body, "UTF-8"));
method.releaseConnection();
+ // get of missing content stream
+ method = new GetMethod(base + "/file/" + doc2id);
+ status = new HttpClient().executeMethod(method);
+ assertEquals(HttpStatus.SC_CONFLICT, status);
+ method.releaseConnection();
+
EntityProvider provider = new QueryEntityProvider("SELECT * FROM doc");
resp = client.post(base + "/query", provider);
- assertEquals(200, resp.getStatus());
+ assertEquals(HttpStatus.SC_OK, resp.getStatus());
Element res = resp.getDocument().getRoot();
assertNotNull(res);
}