You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ru...@locus.apache.org on 1999/12/23 21:30:02 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/protocol WARConnection.java
rubys 99/12/23 12:30:01
Modified: src/share/org/apache/tomcat/protocol WARConnection.java
Log:
Defensive programming against bad JDK implementations of URLConnection.
Submitted by: Bob Jamison <rj...@lincom-asg.com>
Revision Changes Path
1.4 +27 -1 jakarta-tomcat/src/share/org/apache/tomcat/protocol/WARConnection.java
Index: WARConnection.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/protocol/WARConnection.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WARConnection.java 1999/11/13 00:54:01 1.3
+++ WARConnection.java 1999/12/23 20:30:01 1.4
@@ -67,6 +67,7 @@
import java.util.zip.ZipEntry;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.net.FileNameMap;
/**
*
@@ -148,7 +149,32 @@
// XXX
// hmmm .. what about the mimeTypes associated with
// this context
- return URLConnection.getFileNameMap().getContentTypeFor(path);
+ FileNameMap map = URLConnection.getFileNameMap();
+ String type = null;
+
+ // the following try/catch will guard against a
+ // bug in some versions of URLConnection.java
+ try {
+
+ // if there is a nameMapper, use it
+ type=map.getContentTypeFor(path);
+
+ } catch (NullPointerException e) {
+
+ // otherwise use a poor approximation which does the job
+ if (path!=null && path.length()>=1) {
+ String name=path.toLowerCase();
+ if (name.endsWith(".xml"))
+ type="application/xml";
+ else if (name.endsWith(".dtd"))
+ type="text/dtd";
+ else
+ type="application/unknown";
+ }
+
+ }
+
+ return type;
}
public int getContentLength() {