Skip to content

Commit

Permalink
add a media type hint to serializers so they can provide the correct …
Browse files Browse the repository at this point in the history
…content type header to http endpoints
  • Loading branch information
cbeer committed Jun 13, 2013
1 parent 4be6008 commit 1578d77
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraExport.java
Expand Up @@ -15,6 +15,7 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;

import org.fcrepo.AbstractResource;
Expand All @@ -40,7 +41,7 @@ public class FedoraExport extends AbstractResource {
private final Logger logger = getLogger(this.getClass());

@GET
public StreamingOutput exportObject(@PathParam("path")
public Response exportObject(@PathParam("path")
final List<PathSegment> pathList, @QueryParam("format")
@DefaultValue("jcr/xml")
final String format) {
Expand All @@ -49,16 +50,18 @@ public StreamingOutput exportObject(@PathParam("path")
logger.debug("Requested object serialization for: " + path +
" using serialization format " + format);

return new StreamingOutput() {

final FedoraObjectSerializer serializer =
serializers.getSerializer(format);

return Response.ok().type(serializer.getMediaType()).entity(new StreamingOutput() {

@Override
public void write(final OutputStream out) throws IOException {

try {
logger.debug("Selecting from serializer map: " +
serializers);
final FedoraObjectSerializer serializer =
serializers.getSerializer(format);
logger.debug("Retrieved serializer for format: " + format);
serializer.serialize(
objectService.getObject(session, path), out);
Expand All @@ -69,7 +72,7 @@ public void write(final OutputStream out) throws IOException {
session.logout();
}
}
};
}).build();

}

Expand Down
Expand Up @@ -28,6 +28,7 @@ public void shouldRoundTripOneObject() throws IOException {
final HttpGet getObjMethod =
new HttpGet(serverAddress + "objects/JcrXmlSerializerIT1" + "/fcr:export");
HttpResponse response = client.execute(getObjMethod);
assertEquals("application/xml", response.getEntity().getContentType().getValue());
assertEquals(200, response.getStatusLine().getStatusCode());
logger.debug("Successfully exported: " + objName);
final String content = EntityUtils.toString(response.getEntity());
Expand Down
Expand Up @@ -17,6 +17,8 @@ public interface FedoraObjectSerializer {

String getKey();

String getMediaType();

void serialize(final FedoraObject obj, final OutputStream out)
throws RepositoryException, IOException;

Expand Down
Expand Up @@ -22,6 +22,11 @@ public String getKey() {
return "jcr/xml";
}

@Override
public String getMediaType() {
return "application/xml";
}

@Override
public void serialize(final FedoraObject obj, final OutputStream out)
throws RepositoryException, IOException {
Expand Down

0 comments on commit 1578d77

Please sign in to comment.