myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwald...@apache.org
Subject svn commit: r886013 - /myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
Date Tue, 01 Dec 2009 23:53:49 GMT
Author: jwaldman
Date: Tue Dec  1 23:53:49 2009
New Revision: 886013

URL: http://svn.apache.org/viewvc?rev=886013&view=rev
Log:
TRINIDAD-1629 ResourceServlet.java._setHeaders() can call response.setContentType() with a
null contentType resulting in an NPE on Websphere.
Thanks to Gary Kind.
The _setHeaders method was changed to check for more cases and to check for null and log a
warning.

Modified:
    myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java

Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java?rev=886013&r1=886012&r2=886013&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
(original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
Tue Dec  1 23:53:49 2009
@@ -418,24 +418,47 @@
     URLConnection       connection,
     HttpServletResponse response)
   {
-    String contentType = connection.getContentType();
+    String resourcePath;
+    URL    url;
+    String contentType  = connection.getContentType();
+
     if (contentType == null || "content/unknown".equals(contentType))
     {
-      URL url = connection.getURL();
-      String resourcePath = url.getPath();
-      if(resourcePath.endsWith(".css"))
+      url = connection.getURL();
+      resourcePath = url.getPath();
+
+      // 'Case' statement for unknown content types
+      if (resourcePath.endsWith(".css"))
         contentType = "text/css";
-      else if(resourcePath.endsWith(".js"))
+      else if (resourcePath.endsWith(".js"))
         contentType = "application/x-javascript";
+      else if (resourcePath.endsWith(".cur") || resourcePath.endsWith(".ico"))
+        contentType = "image/vnd.microsoft.icon";
       else
         contentType = getServletContext().getMimeType(resourcePath);
     }
-    response.setContentType(contentType);
-
-    int contentLength = connection.getContentLength();
-    if (contentLength >= 0)
-      response.setContentLength(contentLength);
+    
+    if (contentType != null)
+    {
+      response.setContentType(contentType);    
+      int contentLength = connection.getContentLength();
 
+      if (contentLength >= 0)
+        response.setContentLength(contentLength);
+    }
+    else
+    {
+      // The resource has an file extension we have not 
+      // included in the case statement above
+      url = connection.getURL();
+      resourcePath = url.getPath();
+
+      _LOG.warning("ResourceServlet._setHeaders(): " +  
+                   "Content type for {0} is NULL!\n" +
+                   "Cause: Unknown file extension",
+                   resourcePath);
+    } 
+    
     long lastModified;
     try
     {



Mime
View raw message