Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4234091

JarURLConnection does not return the right content type (getContentType())

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.2
    • 1.2.1
    • core-libs
    • 1.2.2
    • x86
    • windows_95
    • Not verified



      Name: dbT83986 Date: 04/29/99


      getContentType() of JarURLConnection (the one under sun.net.*) isn't returning a valid content type for .java files; shouldn't getContentType() recognize .java source files?

      The following

      import java.security.*;
      import java.io.*;
      import java.net.*;

      class test {
      public test() {}
      public static void main(String args[]) {
      try {
      URL u = new URL("jar:file:/c://temp//test.jar!/test.java");
      JarURLConnection uc = (JarURLConnection)u.openConnection();
      //System.out.println(uc.getInputStream());
      System.out.println(uc.getContentType());
      } catch (Exception e) {
      System.out.println("error here");
      e.printStackTrace();
      }
      }
      }
      returns null. In fact it returns null as long as that URL does not refer to a JarFile (JarEntry is null).
      In the case where it is refering to a JarFile, it returns "x-java/jar"
      Since the generic getContent() uses getContentType() to find the right content handler, this leads to another problem:
      If getContent() is called in the test case above, it will raise an UnknownServiceException saying no content-type. I
      suspect it is due to the null returned by getContentType()
      (Review ID: 57640)
      ======================================================================

            michaelm Michael McMahon
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: