}
if (uri == null) {
return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
headers);
}
ContentItem ci = solrStore.get(uri, indexName);
if (ci == null) {
return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
}
if (type.equals("metadata")) {
String fileName = URLEncoder.encode(uri, "utf-8") + "-metadata";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.serialize(baos, ci.getMetadata(), format);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
ResponseBuilder response = Response.ok((Object) is);
response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.type("text/plain");
addCORSOrigin(servletContext, response, headers);
return response.build();
} else if (type.equals("raw")) {
String fileName = URLEncoder.encode(uri, "utf-8") + "-raw";
ResponseBuilder response = Response.ok((Object) ci.getStream());
response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.type(ci.getMimeType());
addCORSOrigin(servletContext, response, headers);
return response.build();
} else {
throw new WebApplicationException(404);
}