Skip to content
Snippets Groups Projects
Commit e8edd557 authored by Thorsten Vitt's avatar Thorsten Vitt
Browse files

Added cache control to TEIcorpus export

parent 0d1f8be8
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@
import info.textgrid.utils.export.filenames.DefaultFilenamePolicy;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.logging.Logger;
import javax.ws.rs.DefaultValue;
......@@ -20,6 +21,8 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
......@@ -75,12 +78,22 @@ public Response get(@Description("TextGrid URIs of the root objects, separated b
@Description("Whether to generate a Content-Disposition: attachment header") @QueryParam("attach") @DefaultValue("true") final boolean attach,
@Description("If true, no intermediate TEI corpus documents will be generated for intermediate aggregations, hierarchical structure will be lost") @QueryParam("flat") @DefaultValue("false") final boolean flat,
@Description("Title for the container if multiple root objects are given") @QueryParam("title") final String titleArgument,
@Description("Session id for accessing restricted resources") @QueryParam("sid") final String sid)
@Description("Session id for accessing restricted resources") @QueryParam("sid") final String sid,
@Context Request request)
throws URISyntaxException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault {
logger.fine("TEIcorpus called for root object(s): " + uriList);
final TGCrudService crud = repository.getCRUDService();
logger.finest("Yo, clients are there.");
final ObjectType[] rootObjects = ArgUtils.extractRootObjects(uriList, sid, crud);
// Return fast for If-Modified-Since
final Date lastModified = RESTUtils.createLastModified(rootObjects);
if (request != null) {
ResponseBuilder response304 = request.evaluatePreconditions(lastModified);
if (response304 != null)
return response304.build();
}
final String title = ArgUtils.createTitle(rootObjects, titleArgument);
logger.finer("CRUD request for root aggregations successful");
......@@ -88,6 +101,7 @@ public Response get(@Description("TextGrid URIs of the root objects, separated b
final TEICorpusSerializer serializer = new TEICorpusSerializer(rootObjects, flat, sid);
serializer.setTitle(title);
final ResponseBuilder builder = Response.ok(serializer, "text/xml");
RESTUtils.configureCache(builder, lastModified, sid == null || sid.isEmpty());
if (attach) {
final String fileName = DefaultFilenamePolicy.INSTANCE.translate(title)
+ (flat ? ".flat" : "") + ".xml";
......
......@@ -41,6 +41,13 @@ public void testEPUBBasket() throws MalformedURLException, IOException, ParseExc
assertEquals(304, connection2.getResponseCode());
}
@Test
public void testCorpusBasket() throws MalformedURLException, IOException, ParseException {
final HttpURLConnection connection2 = performTwoRequests("/epub/textgrid:mjsx.0,textgrid:mjqh.0");
assertEquals(304, connection2.getResponseCode());
}
private HttpURLConnection performTwoRequests(String request)
throws MalformedURLException, IOException, ParseException {
......
......@@ -33,7 +33,7 @@ public void setUp() throws Exception {
@Test(expected = ObjectNotFoundFault.class)
public void testGet404() throws URISyntaxException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault {
final Response response = teiCorpus.get("textgrid:doesnotexist",
true, false, null, null);
true, false, null, null, null);
Assert.assertEquals(404, response.getStatus());
}
......@@ -41,7 +41,7 @@ public void testGet404() throws URISyntaxException, ObjectNotFoundFault, Metadat
public void testGet() throws URISyntaxException, WebApplicationException,
IOException, ObjectNotFoundFault, MetadataParseFault, IoFault, AuthFault {
final Response response = teiCorpus.get("textgrid:jmzg.0", true,
false, null, null);
false, null, null, null);
final Object entity = response.getEntity();
final ByteArrayOutputStream output = new ByteArrayOutputStream();
((StreamingOutput) entity).write(output);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment