Skip to content

Commit

Permalink
Changed FedoraExport to use injected Session
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed May 8, 2013
1 parent 46bdbf9 commit de54a45
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraExport.java
Expand Up @@ -22,50 +22,62 @@

import org.fcrepo.AbstractResource;
import org.fcrepo.serialization.FedoraObjectSerializer;
import org.fcrepo.session.InjectedSession;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")
@Path("/rest/{path: .*}/fcr:export")
public class FedoraExport extends AbstractResource {

@InjectedSession
private Session session;

@Resource
private Map<String, FedoraObjectSerializer> serializers;

private final Logger logger = getLogger(this.getClass());

@GET
public StreamingOutput exportObject(@PathParam("path") final List<PathSegment> pathList, @QueryParam("format")
public StreamingOutput exportObject(@PathParam("path")
final List<PathSegment> pathList, @QueryParam("format")
@DefaultValue("jcr/xml")
final String format) {
final String path = toPath(pathList);
final String path = toPath(pathList);

logger.debug("Requested object serialization for: " + path +
" using serialization format " + format);

return new StreamingOutput() {
@Override
public void write(final OutputStream out) throws IOException {
final Session session = getAuthenticatedSession();
try {
logger.debug("Selecting from serializer map: " +
serializers);
final FedoraObjectSerializer serializer =
serializers.get(format);
logger.debug("Retrieved serializer for format: " + format);
serializer.serialize(objectService.getObject(session, path), out);
logger.debug("Successfully serialized object: " + path);
} catch (final RepositoryException e) {
throw new WebApplicationException(e);
} finally {
session.logout();
}
}
};
return new StreamingOutput() {

@Override
public void write(final OutputStream out) throws IOException {
try {
logger.debug("Selecting from serializer map: " +
serializers);
final FedoraObjectSerializer serializer =
serializers.get(format);
logger.debug("Retrieved serializer for format: " + format);
serializer.serialize(
objectService.getObject(session, path), out);
logger.debug("Successfully serialized object: " + path);
} catch (final RepositoryException e) {
throw new WebApplicationException(e);
} finally {
session.logout();
}
}
};
}

public void setSerializers(
final Map<String, FedoraObjectSerializer> serializers) {
this.serializers = serializers;
}

public void setSession(final Session session) {
this.session = session;
}
}

0 comments on commit de54a45

Please sign in to comment.