You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2009/05/27 16:47:29 UTC
svn commit: r779195 -
/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java
Author: lofwyr
Date: Wed May 27 14:47:29 2009
New Revision: 779195
URL: http://svn.apache.org/viewvc?rev=779195&view=rev
Log:
TOBAGO-759: ResourceServlet should set the status 404, if the resource could not be found
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java?rev=779195&r1=779194&r2=779195&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java Wed May 27 14:47:29 2009
@@ -56,9 +56,6 @@
* </pre><p>
*
* @since 1.0.7
- * <p/>
- * XXX This class is in development. Please don't use it in
- * production environment!
*/
public class ResourceServlet extends HttpServlet {
@@ -98,9 +95,7 @@
throws ServletException, IOException {
String requestURI = request.getRequestURI();
-
- String resource = requestURI.substring(
- request.getContextPath().length() + 1); // todo: make it "stable"
+ String resource = requestURI.substring(request.getContextPath().length() + 1);
if (expires != null) {
response.setDateHeader("Last-Modified", 0);
@@ -111,10 +106,12 @@
if (contentType != null) {
response.setContentType(contentType);
} else {
- LOG.warn("Unsupported file extension, will be ignored for security reasons; resource='"
- + resource + "'");
- response.setStatus(HttpServletResponse.SC_FORBIDDEN);
+ String message = "Unsupported mime type of resource='" + resource + "'";
+ LOG.warn(message + " (because of security reasons)");
+ response.sendError(HttpServletResponse.SC_FORBIDDEN, message);
+ return;
}
+
InputStream inputStream = null;
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
@@ -128,10 +125,11 @@
}
if (inputStream != null) {
- OutputStream outputStream = response.getOutputStream();
- copy(inputStream, outputStream);
+ IOUtils.copy(inputStream, response.getOutputStream());
} else {
- LOG.warn("Resource '" + resource + "' not found!");
+ String message = "Resource '" + resource + "' not found!";
+ LOG.warn(message);
+ response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
}
} finally {
IOUtils.closeQuietly(inputStream);