Skip to content
Permalink
Browse files

Use SessionProvider#dispose to logout injected sessions

Previously, JAX-RS endpoints were responsible for logging out as appropriate.
  • Loading branch information...
cbeer committed Oct 9, 2014
1 parent 4f36eaa commit e96995d8ff07efe56416f30158e2d18cae6bb3ea
Showing with 471 additions and 682 deletions.
  1. +8 −13 fcrepo-generator-dc/src/main/java/org/fcrepo/generator/DublinCoreGenerator.java
  2. +161 −173 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraBatch.java
  3. +0 −2 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraExport.java
  4. +0 −2 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraImport.java
  5. +87 −103 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraLdp.java
  6. +0 −4 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraLocks.java
  7. +0 −6 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraNodes.java
  8. +21 −34 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraVersioning.java
  9. +11 −28 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraVersions.java
  10. +22 −26 fcrepo-http-api/src/main/java/org/fcrepo/http/api/repository/FedoraRepositoriesProperties.java
  11. +12 −16 fcrepo-http-api/src/main/java/org/fcrepo/http/api/repository/FedoraRepositoryBackup.java
  12. +0 −2 fcrepo-http-api/src/main/java/org/fcrepo/http/api/repository/FedoraRepositoryNamespaces.java
  13. +0 −2 fcrepo-http-api/src/main/java/org/fcrepo/http/api/repository/FedoraRepositoryNodeTypes.java
  14. +13 −16 fcrepo-http-api/src/main/java/org/fcrepo/http/api/repository/FedoraRepositoryRestore.java
  15. +18 −25 fcrepo-http-api/src/main/java/org/fcrepo/http/api/repository/FedoraRepositorySitemap.java
  16. +0 −4 fcrepo-http-api/src/main/java/org/fcrepo/http/api/repository/FedoraRepositoryWorkspaces.java
  17. +0 −2 fcrepo-http-api/src/main/java/org/fcrepo/http/api/responses/StreamingBaseHtmlProvider.java
  18. +0 −1 fcrepo-http-api/src/test/java/org/fcrepo/http/api/repository/FedoraRepositoriesPropertiesTest.java
  19. +36 −0 ...-http-commons/src/main/java/org/fcrepo/http/commons/exceptionhandlers/VersionExceptionMapper.java
  20. +0 −3 fcrepo-http-commons/src/main/java/org/fcrepo/http/commons/responses/RdfStreamProvider.java
  21. +0 −3 fcrepo-http-commons/src/main/java/org/fcrepo/http/commons/responses/RdfStreamStreamingOutput.java
  22. +8 −2 fcrepo-http-commons/src/main/java/org/fcrepo/http/commons/session/SessionProvider.java
  23. +14 −0 fcrepo-kernel-impl/src/main/java/org/fcrepo/kernel/impl/services/TransactionServiceImpl.java
  24. +0 −61 fcrepo-kernel-impl/src/main/java/org/fcrepo/kernel/impl/utils/LogoutCallback.java
  25. +0 −66 fcrepo-kernel-impl/src/test/java/org/fcrepo/kernel/impl/utils/LogoutCallbackTest.java
  26. +48 −59 fcrepo-storage-policy/src/main/java/org/fcrepo/storage/policy/FedoraStoragePolicy.java
  27. +0 −4 fcrepo-transform/src/main/java/org/fcrepo/transform/http/FedoraSparql.java
  28. +6 −14 fcrepo-transform/src/main/java/org/fcrepo/transform/http/FedoraTransform.java
  29. +6 −11 fcrepo-transform/src/main/java/org/fcrepo/transform/http/responses/ResultSetStreamingOutput.java
@@ -62,23 +62,18 @@
@Produces(TEXT_XML)
public Response getObjectAsDublinCore(@PathParam("path") final String externalPath) throws RepositoryException {

try {
final FedoraResource obj = getResourceFromPath(externalPath);
final FedoraResource obj = getResourceFromPath(externalPath);

for (final DCGenerator indexer : dcgenerators) {
final InputStream inputStream =
indexer.getStream(obj.getNode());
for (final DCGenerator indexer : dcgenerators) {
final InputStream inputStream =
indexer.getStream(obj.getNode());

if (inputStream != null) {
return ok(inputStream).build();
}
if (inputStream != null) {
return ok(inputStream).build();
}
// no indexers = no path for DC
throw new PathNotFoundException();
} finally {
session.logout();
}

// no indexers = no path for DC
throw new PathNotFoundException();
}

@Override

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -99,8 +99,6 @@ public void write(final OutputStream out)
LOGGER.debug("Successfully serialized object: {}", resource);
} catch (final RepositoryException e) {
throw new WebApplicationException(e);
} finally {
session.logout();
}
}
}).build();
@@ -93,8 +93,6 @@ public Response importObject(@PathParam("path") final String externalPath,
return status(CONFLICT).entity("Item already exists").build();
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
} finally {
session.logout();
}
}

@@ -191,22 +191,17 @@ public Response describe(@HeaderParam("Prefer") final Prefer prefer,
@DELETE
@Timed
public Response deleteObject() {
try {

evaluateRequestPreconditions(request, servletResponse, resource(), session);
evaluateRequestPreconditions(request, servletResponse, resource(), session);

resource().delete();
resource().delete();

try {
session.save();
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}

return noContent().build();
} finally {
session.logout();
try {
session.save();
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}

return noContent().build();
}


@@ -226,62 +221,58 @@ public Response createOrReplaceObjectRdf(
@HeaderParam("Content-Disposition") final ContentDisposition contentDisposition)
throws InvalidChecksumException {

try {
final FedoraResource resource;
final Response.ResponseBuilder response;

final FedoraResource resource;
final Response.ResponseBuilder response;
final String path = toPath(translator(), externalPath);

final String path = toPath(translator(), externalPath);
final MediaType contentType = getSimpleContentType(requestContentType);

final MediaType contentType = getSimpleContentType(requestContentType);
if (nodeService.exists(session, path)) {
resource = resource();
response = noContent();
} else {
final MediaType effectiveContentType
= requestBodyStream == null || requestContentType == null ? null : contentType;
resource = createFedoraResource(null, effectiveContentType, path, contentDisposition);

if (nodeService.exists(session, path)) {
resource = resource();
response = noContent();
} else {
final MediaType effectiveContentType
= requestBodyStream == null || requestContentType == null ? null : contentType;
resource = createFedoraResource(null, effectiveContentType, path, contentDisposition);
final URI location = getUri(resource);

final URI location = getUri(resource);
response = created(location).entity(location.toString());
}

response = created(location).entity(location.toString());
}
evaluateRequestPreconditions(request, servletResponse, resource, session);

evaluateRequestPreconditions(request, servletResponse, resource, session);

if (requestContentType != null && requestBodyStream != null) {
if ((resource instanceof FedoraObject || resource instanceof Datastream)
&& isRdfContentType(contentType.toString())) {
try {
replaceResourceWithStream(resource, requestBodyStream, contentType);
} catch (final RiotException e) {
throw new BadRequestException("RDF was not parsable", e);
}
} else if (resource instanceof FedoraBinary) {
replaceResourceBinaryWithStream((FedoraBinary) resource,
requestBodyStream, contentDisposition, requestContentType.toString(), checksum);
} else {
throw new ClientErrorException(UNSUPPORTED_MEDIA_TYPE);
if (requestContentType != null && requestBodyStream != null) {
if ((resource instanceof FedoraObject || resource instanceof Datastream)
&& isRdfContentType(contentType.toString())) {
try {
replaceResourceWithStream(resource, requestBodyStream, contentType);
} catch (final RiotException e) {
throw new BadRequestException("RDF was not parsable", e);
}

} else if (!resource.isNew()) {
throw new ClientErrorException("No RDF provided and the resource already exists!", CONFLICT);
}

try {
session.save();
versionService.nodeUpdated(resource.getNode());
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
} else if (resource instanceof FedoraBinary) {
replaceResourceBinaryWithStream((FedoraBinary) resource,
requestBodyStream, contentDisposition, requestContentType.toString(), checksum);
} else {
throw new ClientErrorException(UNSUPPORTED_MEDIA_TYPE);
}

addCacheControlHeaders(servletResponse, resource, session);
} else if (!resource.isNew()) {
throw new ClientErrorException("No RDF provided and the resource already exists!", CONFLICT);
}

return response.build();
} finally {
session.logout();
try {
session.save();
versionService.nodeUpdated(resource.getNode());
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}

addCacheControlHeaders(servletResponse, resource, session);

return response.build();

}

/**
@@ -336,8 +327,6 @@ public Response updateSparql(@ContentLocation final InputStream requestBodyStrea
throw new BadRequestException(cause.getMessage());
}
throw ex;
} finally {
session.logout();
}
}

@@ -372,61 +361,56 @@ public Response createObject(@QueryParam("mixin") final String mixin,

LOGGER.debug("Attempting to ingest with path: {}", newObjectPath);

try {
final MediaType effectiveContentType
= requestBodyStream == null || requestContentType == null ? null : contentType;
final FedoraResource result = createFedoraResource(mixin,
effectiveContentType,
newObjectPath, contentDisposition);

final MediaType effectiveContentType
= requestBodyStream == null || requestContentType == null ? null : contentType;
final FedoraResource result = createFedoraResource(mixin,
effectiveContentType,
newObjectPath, contentDisposition);
if (requestBodyStream == null || requestContentType == null) {
LOGGER.trace("No request body detected");
} else {
LOGGER.trace("Received createObject with a request body and content type \"{}\"", contentTypeString);

if ((result instanceof FedoraObject || result instanceof Datastream)
&& isRdfContentType(contentTypeString)) {
replaceResourceWithStream(result, requestBodyStream, contentType);
} else if (result instanceof FedoraBinary) {
LOGGER.trace("Created a datastream and have a binary payload.");

replaceResourceBinaryWithStream((FedoraBinary) result,
requestBodyStream, contentDisposition, contentTypeString, checksum);

if (requestBodyStream == null || requestContentType == null) {
LOGGER.trace("No request body detected");
} else if (contentTypeString.equals(contentTypeSPARQLUpdate)) {
LOGGER.trace("Found SPARQL-Update content, applying..");
patchResourcewithSparql(result, IOUtils.toString(requestBodyStream));
} else {
LOGGER.trace("Received createObject with a request body and content type \"{}\"", contentTypeString);

if ((result instanceof FedoraObject || result instanceof Datastream)
&& isRdfContentType(contentTypeString)) {
replaceResourceWithStream(result, requestBodyStream, contentType);
} else if (result instanceof FedoraBinary) {
LOGGER.trace("Created a datastream and have a binary payload.");

replaceResourceBinaryWithStream((FedoraBinary) result,
requestBodyStream, contentDisposition, contentTypeString, checksum);

} else if (contentTypeString.equals(contentTypeSPARQLUpdate)) {
LOGGER.trace("Found SPARQL-Update content, applying..");
patchResourcewithSparql(result, IOUtils.toString(requestBodyStream));
} else {
throw new WebApplicationException(notAcceptable(null)
.entity("Invalid Content Type " + contentTypeString).build());
}
throw new WebApplicationException(notAcceptable(null)
.entity("Invalid Content Type " + contentTypeString).build());
}
}

try {
session.save();
versionService.nodeUpdated(result.getNode());
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
try {
session.save();
versionService.nodeUpdated(result.getNode());
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}

LOGGER.debug("Finished creating {} with path: {}", mixin, newObjectPath);
LOGGER.debug("Finished creating {} with path: {}", mixin, newObjectPath);

addCacheControlHeaders(servletResponse, result, session);
addCacheControlHeaders(servletResponse, result, session);

final URI location = getUri(result);
final URI location = getUri(result);

if (result instanceof FedoraBinary) {
final URI descriptionUri = getUri(((FedoraBinary) result).getDescription());
servletResponse.addHeader("Link", "<" + descriptionUri + ">;rel=\"describedby\";"
+ " anchor=\"" + location + "\"");
}
if (result instanceof FedoraBinary) {
final URI descriptionUri = getUri(((FedoraBinary) result).getDescription());
servletResponse.addHeader("Link", "<" + descriptionUri + ">;rel=\"describedby\";"
+ " anchor=\"" + location + "\"");
}

return created(location).entity(location.toString()).build();
return created(location).entity(location.toString()).build();

} finally {
session.logout();
}
}

protected void addResourceHttpHeaders(final FedoraResource resource) {
@@ -116,8 +116,6 @@ public Response createLock(@PathParam("path") final String externalPath,
return created(new URI(location)).entity(location).header("Lock-Token", lock.getLockToken()).build();
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
} finally {
session.logout();
}
}

@@ -137,8 +135,6 @@ public Response deleteLock(@PathParam("path") final String externalPath) {
return noContent().build();
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
} finally {
session.logout();
}
}

@@ -108,7 +108,6 @@ public Response copyObject(@HeaderParam("Destination") final String destinationU
throws URISyntaxException {

try {

final String source = translator().asString(translator().toDomain(externalPath));

if (!nodeService.exists(session, source)) {
@@ -145,8 +144,6 @@ public Response copyObject(@HeaderParam("Destination") final String destinationU
}
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
} finally {
session.logout();
}

}
@@ -195,10 +192,7 @@ public Response moveObject(@HeaderParam("Destination") final String destinationU
}
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
} finally {
session.logout();
}

}

@Override
Oops, something went wrong.

0 comments on commit e96995d

Please sign in to comment.
You can’t perform that action at this time.