From 5d24a9d92a3a0dd31d76c6885552add016c37c5f Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Wed, 1 Apr 2015 10:20:36 +0200 Subject: [PATCH] send out a 404 when the entry found is a directory --- .../de/dentrassi/osgi/web/ResourceRequestHandler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/de.dentrassi.osgi.web/src/de/dentrassi/osgi/web/ResourceRequestHandler.java b/de.dentrassi.osgi.web/src/de/dentrassi/osgi/web/ResourceRequestHandler.java index 119ed2d9..297472b8 100644 --- a/de.dentrassi.osgi.web/src/de/dentrassi/osgi/web/ResourceRequestHandler.java +++ b/de.dentrassi.osgi.web/src/de/dentrassi/osgi/web/ResourceRequestHandler.java @@ -10,6 +10,7 @@ *******************************************************************************/ package de.dentrassi.osgi.web; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -54,11 +55,16 @@ public void process ( final HttpServletRequest request, final HttpServletRespons return; } - response.setDateHeader ( Responses.LAST_MODIFIED, this.lastModified ); - try ( InputStream in = this.url.openStream () ) { + response.setDateHeader ( Responses.LAST_MODIFIED, this.lastModified ); ByteStreams.copy ( in, response.getOutputStream () ); } + catch ( final FileNotFoundException e ) + { + // caused by accessing a directory + Responses.notFound ( request, response ); + } + } }