Skip to content

Commit

Permalink
allow 404 to be thrown if METS file not found, even when fitering;
Browse files Browse the repository at this point in the history
refs #26720
  • Loading branch information
Keelhaul committed Feb 4, 2025
1 parent 36bb872 commit 4135cd1
Showing 1 changed file with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,23 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
response.setContentType(StringConstants.MIMETYPE_TEXT_XML);
File file = new File(filePath);
response.setHeader("Content-Disposition", "filename=\"" + file.getName() + "\"");
if (!superuserAccess && SolrConstants.SOURCEDOCFORMAT_METS.equals(format)) {
try {
Document metsDoc = XmlTools.readXmlFile(filePath);
Document cleanDoc = filterRestrictedMetadata(metsDoc);
if (cleanDoc != null) {
XMLOutputter outputter = XmlTools.getXMLOutputter();
outputter.setFormat(Format.getPrettyFormat());
outputter.output(cleanDoc, response.getOutputStream());

try (FileInputStream fis = new FileInputStream(file); ServletOutputStream out = response.getOutputStream()) {
if (!superuserAccess && SolrConstants.SOURCEDOCFORMAT_METS.equals(format)) {
// Filters METS documents, unless client has superuser access
try {
Document metsDoc = XmlTools.readXmlFile(filePath);
Document cleanDoc = filterRestrictedMetadata(metsDoc);
if (cleanDoc != null) {
XMLOutputter outputter = XmlTools.getXMLOutputter();
outputter.setFormat(Format.getPrettyFormat());
outputter.output(cleanDoc, response.getOutputStream());
}
} catch (IOException | JDOMException e) {
logger.error(e.getMessage());
}
} catch (IOException | JDOMException e) {
logger.error(e.getMessage());
}
} else {
try (FileInputStream fis = new FileInputStream(file); ServletOutputStream out = response.getOutputStream()) {
} else {
// Unfiltered access
int bytesRead = 0;
byte[] byteArray = new byte[300];
try {
Expand All @@ -221,20 +224,20 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
} catch (IOException e) {
logger.error(e.getMessage());
}
} catch (FileNotFoundException e) {
logger.debug(e.getMessage());
try {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found: " + file.getName());
} catch (IOException e1) {
logger.error(e1.getMessage());
}
} catch (IOException e) {
logger.error(e.getMessage());
try {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
} catch (IOException e1) {
logger.error(e1.getMessage());
}
}
} catch (FileNotFoundException e) {
logger.debug(e.getMessage());
try {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found: " + file.getName());
} catch (IOException e1) {
logger.error(e1.getMessage());
}
} catch (IOException e) {
logger.error(e.getMessage());
try {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
} catch (IOException e1) {
logger.error(e1.getMessage());
}
}
}
Expand Down

0 comments on commit 4135cd1

Please sign in to comment.