Skip to content

Commit de9a1b5

Browse files
author
Nico Verwer
committed
do not show connection errors when rest client hangs up
1 parent cf21027 commit de9a1b5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

exist-core/src/main/java/org/exist/http/RESTServer.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,14 +1808,19 @@ private void writeResourceAs(final DocumentImpl resource, final DBBroker broker,
18081808
outputProperties.setProperty("omit-xml-declaration", "no");
18091809
}
18101810

1811-
final OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream(), encoding);
1812-
sax.setOutput(writer, outputProperties);
1813-
serializer.setSAXHandlers(sax, sax);
1811+
try {
1812+
final OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream(), encoding);
1813+
sax.setOutput(writer, outputProperties);
1814+
serializer.setSAXHandlers(sax, sax);
18141815

1815-
serializer.toSAX(resource);
1816+
serializer.toSAX(resource);
18161817

1817-
writer.flush();
1818-
writer.close(); // DO NOT use in try-write-resources, otherwise ther response stream is always closed, and we can't report the errors
1818+
// writer.flush(); // Not needed, because close() will flush the stream.
1819+
writer.close(); // DO NOT use in try-with-resources, otherwise the response stream is always closed, and we can't report the errors
1820+
} catch (org.eclipse.jetty.io.EofException connectionInterrupted) {
1821+
// Don't throw the EofException, which is caused by the client hanging up.
1822+
LOG.info("Ignored EofException while writing response to ReST client: {}", connectionInterrupted.getMessage());
1823+
}
18191824
} catch (final SAXException saxe) {
18201825
LOG.warn(saxe);
18211826
throw new BadRequestException("Error while serializing XML: " + saxe.getMessage());

0 commit comments

Comments
 (0)