< prev index next >

test/java/net/URLConnection/HandleContentTypeWithAttrs.java

Print this page




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4160200
  27  * @summary Make sure URLConnection.getContnentHandler
  28  *     can handle MIME types with attributes
  29  * @modules java.base/sun.net.www java.base/sun.net.www.content.text
  30  */
  31 import java.net.*;
  32 import java.io.*;
  33 import sun.net.www.content.text.*;
  34 import sun.net.www.MessageHeader;

  35 
  36 public class HandleContentTypeWithAttrs {
  37 
  38     URL url;
  39 
  40     public HandleContentTypeWithAttrs (int port) throws Exception {
  41 
  42         String localHostName = InetAddress.getLocalHost().getHostName();
  43 
  44         // Request echo.html from myHttpServer.
  45         // In the header of the response, we make
  46         // the content type have some attributes.
  47         url = new URL("http://" + localHostName + ":" + port + "/echo.html");
  48         URLConnection urlConn = url.openConnection();
  49 
  50         // the method getContent() calls the method
  51         // getContentHandler(). With the fix, the method
  52         // getContentHandler() gets the correct content
  53         // handler for our response -  it should be the
  54         // PlainText conten handler; without the fix,
  55         // it gets the UnknownContent handler.
  56         // So based on what the getContent()
  57         // returns, we know whether getContentHandler()
  58         // can handle content type with attributes or not.
  59         Object obj = urlConn.getContent();
  60 
  61         if (!(obj instanceof PlainTextInputStream))
  62             throw new Exception("Cannot get the correct content handler.");
  63     }
  64 
  65     public static void main(String [] argv) throws Exception {
  66         // Start myHttpServer
  67         myHttpServer testServer = new myHttpServer();
  68         testServer.startServer(0);




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4160200
  27  * @summary Make sure URLConnection.getContnentHandler
  28  *     can handle MIME types with attributes
  29  * @modules java.base/sun.net.www java.base/sun.net.www.content.text
  30  */
  31 import java.net.*;
  32 import java.io.*;
  33 import sun.net.www.content.text.*;
  34 import sun.net.www.MessageHeader;
  35 import static java.net.Proxy.NO_PROXY;
  36 
  37 public class HandleContentTypeWithAttrs {
  38 
  39     URL url;
  40 
  41     public HandleContentTypeWithAttrs (int port) throws Exception {
  42 


  43         // Request echo.html from myHttpServer.
  44         // In the header of the response, we make
  45         // the content type have some attributes.
  46         url = new URL("http://localhost:" + port + "/echo.html");
  47         URLConnection urlConn = url.openConnection(NO_PROXY);
  48 
  49         // the method getContent() calls the method
  50         // getContentHandler(). With the fix, the method
  51         // getContentHandler() gets the correct content
  52         // handler for our response -  it should be the
  53         // PlainText conten handler; without the fix,
  54         // it gets the UnknownContent handler.
  55         // So based on what the getContent()
  56         // returns, we know whether getContentHandler()
  57         // can handle content type with attributes or not.
  58         Object obj = urlConn.getContent();
  59 
  60         if (!(obj instanceof PlainTextInputStream))
  61             throw new Exception("Cannot get the correct content handler.");
  62     }
  63 
  64     public static void main(String [] argv) throws Exception {
  65         // Start myHttpServer
  66         myHttpServer testServer = new myHttpServer();
  67         testServer.startServer(0);


< prev index next >