Author: fguillaume
Date: Fri Dec 18 20:01:04 2009
New Revision: 892361
URL: http://svn.apache.org/viewvc?rev=892361&view=rev
Log:
CMIS-84: Incorrect SPI early close when getting children feed
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.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
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java?rev=892361&r1=892360&r2=892361&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
Fri Dec 18 20:01:04 2009
@@ -68,19 +68,16 @@
@Override
public ResponseContext getFeed(RequestContext request) {
+ SPI spi = repository.getSPI();
try {
- Feed feed;
- SPI spi = repository.getSPI();
- try {
- ListPage<ObjectEntry> entries = getEntries(request, spi);
- feed = createFeedBase(entries, request, spi);
- addFeedDetails(feed, entries, request);
- } finally {
- spi.close();
- }
+ ListPage<ObjectEntry> entries = getEntries(request, spi);
+ Feed feed = createFeedBase(entries, request, spi);
+ addFeedDetails(feed, entries, request);
return buildGetFeedResponse(feed);
} catch (ResponseContextException e) {
return createErrorResponse(e);
+ } finally {
+ spi.close();
}
}
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=892361&r1=892360&r2=892361&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
Fri Dec 18 20:01:04 2009
@@ -17,8 +17,6 @@
*/
package org.apache.chemistry.atompub.server;
-import static
org.apache.abdera.protocol.server.ProviderHelper.calculateEntityTag;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -230,7 +228,7 @@
boolean isNew = typeId == null;
Entry entry = getEntryFromRequest(request);
if (entry == null || !ProviderHelper.isValidEntry(entry)) {
- throw new ResponseContextException(400);
+ throw new ResponseContextException("Invalid entry", 400);
}
// get properties and type from entry
@@ -492,14 +490,18 @@
throws ResponseContextException {
SPI spi = repository.getSPI();
try {
- return getContentType(object) != null
- && getContentSize(object) != -1
- && spi.hasContentStream(object);
+ return isMediaEntry(object, spi);
} finally {
spi.close();
}
}
+ public boolean isMediaEntry(ObjectEntry object, SPI spi)
+ throws ResponseContextException {
+ return getContentType(object) != null && getContentSize(object) != -1
+ && spi.hasContentStream(object);
+ }
+
@Override
protected String addMediaContent(IRI feedIri, Entry entry,
ObjectEntry object, RequestContext request)
@@ -534,33 +536,63 @@
}
@Override
+ public ResponseContext getEntry(RequestContext request) {
+ SPI spi = repository.getSPI();
+ try {
+ String id = getResourceName(request);
+ ObjectEntry object = getEntry(id, request, spi);
+ if (object == null) {
+ return new EmptyResponseContext(404);
+ }
+ Entry entry = request.getAbdera().getFactory().newEntry();
+ IRI feedIri = new IRI(getFeedIriForEntry(object, request));
+ addEntryDetails(request, entry, feedIri, object);
+ if (isMediaEntry(object, spi)) {
+ addMediaContent(feedIri, entry, object, request);
+ } else {
+ addContent(entry, object, request);
+ }
+ return buildGetEntryResponse(request, entry);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ } finally {
+ spi.close();
+ }
+ }
+
+ @Override
public ObjectEntry getEntry(String resourceName, RequestContext request)
throws ResponseContextException {
SPI spi = repository.getSPI();
try {
- Target target = request.getTarget();
- String properties = target.getParameter(AtomPubCMIS.PARAM_FILTER);
- boolean allowableActions = getParameter(request,
- AtomPubCMIS.PARAM_INCLUDE_ALLOWABLE_ACTIONS, false);
- String incl =
target.getParameter(AtomPubCMIS.PARAM_INCLUDE_RELATIONSHIPS);
- RelationshipDirection relationships =
RelationshipDirection.fromInclusion(incl);
- Inclusion inclusion = new Inclusion(properties, null,
- relationships, allowableActions, false, false);
- if ("path".equals(getType())) {
- String path = resourceName;
- if (!path.startsWith("/")) {
- path = "/" + path;
- }
- return spi.getObjectByPath(path, inclusion);
- } else { // object
- String id = resourceName;
- return spi.getProperties(spi.newObjectId(id), inclusion);
- }
+ return getEntry(resourceName, request, spi);
} finally {
spi.close();
}
}
+ public ObjectEntry getEntry(String resourceName, RequestContext request,
+ SPI spi) throws ResponseContextException {
+ Target target = request.getTarget();
+ String properties = target.getParameter(AtomPubCMIS.PARAM_FILTER);
+ boolean allowableActions = getParameter(request,
+ AtomPubCMIS.PARAM_INCLUDE_ALLOWABLE_ACTIONS, false);
+ String incl =
target.getParameter(AtomPubCMIS.PARAM_INCLUDE_RELATIONSHIPS);
+ RelationshipDirection relationships =
RelationshipDirection.fromInclusion(incl);
+ Inclusion inclusion = new Inclusion(properties, null, relationships,
+ allowableActions, false, false);
+ if ("path".equals(getType())) {
+ String path = resourceName;
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ return spi.getObjectByPath(path, inclusion);
+ } else { // object
+ String id = resourceName;
+ return spi.getProperties(spi.newObjectId(id), inclusion);
+ }
+ }
+
@Override
public String getResourceName(RequestContext request) {
String name;
@@ -590,36 +622,35 @@
@Override
protected ResponseContext buildGetMediaResponse(String id,
ObjectEntry object) throws ResponseContextException {
- Date updated = getUpdated(object);
SPI spi = repository.getSPI();
- ContentStream contentStream;
try {
- contentStream = spi.getContentStream(object, null);
+ ContentStream contentStream = spi.getContentStream(object, null);
+ 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");
+ }
+ Date updated = getUpdated(object);
+ 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;
} catch (ConstraintViolationException e) {
- contentStream = null;
+ return new EmptyResponseContext(409, "No content");
} catch (IOException e) {
return new EmptyResponseContext(500, e.toString());
} finally {
spi.close();
}
- 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;
}
@Override
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=892361&r1=892360&r2=892361&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
Fri Dec 18 20:01:04 2009
@@ -289,8 +289,9 @@
return getAbderaEntry(2);
}
+ // TODO should we really accept AtomPub.MEDIA_TYPE_ATOM ?
@PUT
- @Consumes(AtomPub.MEDIA_TYPE_ATOM_ENTRY)
+ @Consumes( { AtomPub.MEDIA_TYPE_ATOM_ENTRY, AtomPub.MEDIA_TYPE_ATOM })
@Produces(AtomPub.MEDIA_TYPE_ATOM_ENTRY)
@Path("object/{objectid}")
public Response doPutObject() {