8007322: untangle ftp protocol from general networking URL tests
Reviewed-by: alanb
--- a/jdk/test/java/net/URL/Constructor.java Fri Feb 01 22:18:18 2013 -0800
+++ b/jdk/test/java/net/URL/Constructor.java Sat Feb 02 17:15:13 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,71 +21,235 @@
* questions.
*/
-/* This is no longer run directly. See runconstructor.sh
- *
- *
- *
+/*
+ * @test
+ * @bug 4393671
+ * @summary URL constructor URL(URL context, String spec) FAILED with specific input
+ */
+
+/*
* This program tests the URL parser in the URL constructor. It
* tries to construct a variety of valid URLs with a given context
* (which may be null) and a variety of specs. It then compares the
* result with an expected value.
- *
- * It expects that a data file named "urls" be available in the
- * current directory, from which it will get its testing data. The
- * format of the file is:
- *
- * URL: null
- * spec: jar:http://www.foo.com/dir1/jar.jar!/
- * expected: jar:http://www.foo.com/dir1/jar.jar!/
- *
- * where URL is the context, spec is the spec and expected is the
- * expected result. The first : must be followed by a space. Each test
- * entry should be followed by a blank line.
*/
-import java.io.*;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
public class Constructor {
public static void main(String[] args) throws Exception {
- URL url = null;
- String urls = "jar_urls";
- if (args.length > 0 && args[0] != null) {
- urls = args[0];
- }
+ List<Entry> entries = new ArrayList<>();
+ entries.addAll(Arrays.asList(fileURLs));
+ entries.addAll(Arrays.asList(jarURLs));
+ entries.addAll(Arrays.asList(normalHttpURLs));
+ entries.addAll(Arrays.asList(abnormalHttpURLs));
+ if (hasFtp())
+ entries.addAll(Arrays.asList(ftpURLs));
+ URL url;
- File f = new File(urls);
- InputStream file = new FileInputStream(f);
- BufferedReader in = new BufferedReader(new InputStreamReader(file));
- while(true) {
- String context = in.readLine();
- if (context == null) {
- break;
- }
- context = getValue(context);
- String spec = getValue(in.readLine());
- String expected = getValue(in.readLine());
+ for (Entry e : entries) {
+ if (e.context == null)
+ url = new URL(e.spec);
+ else
+ url = new URL(new URL(e.context), e.spec);
- if (context.equals("null")) {
- url = new URL(spec);
- } else {
- url = new URL(new URL(context), spec);
- }
- if (!(url.toString().equals(expected))) {
- throw new RuntimeException("error for: \n\tURL:" + context +
- "\n\tspec: " + spec +
- "\n\texpected: " + expected +
+ if (!(url.toString().equals(e.expected))) {
+ throw new RuntimeException("error for: \n\tURL:" + e.context +
+ "\n\tspec: " + e.spec +
+ "\n\texpected: " + e.expected +
"\n\tactual: " + url.toString());
} else {
- System.out.println("success for: " + url + "\n");
+ //debug
+ //System.out.println("success for: " + url);
}
- in.readLine();
+ }
+ }
+
+ private static boolean hasFtp() {
+ try {
+ return new java.net.URL("ftp://") != null;
+ } catch (java.net.MalformedURLException x) {
+ System.out.println("FTP not supported by this runtime.");
+ return false;
}
- in.close();
+ }
+
+ static class Entry {
+ final String context;
+ final String spec;
+ final String expected;
+ Entry(String context, String spec, String expected) {
+ this.context = context;
+ this.spec =spec;
+ this.expected = expected;
+ }
}
- private static String getValue(String value) {
- return value.substring(value.indexOf(':') + 2);
- }
+ static Entry[] fileURLs = new Entry[] {
+ new Entry(null,
+ "file://JavaSoft/Test",
+ "file://JavaSoft/Test"),
+ new Entry(null,
+ "file:///JavaSoft/Test",
+ "file:/JavaSoft/Test"),
+ new Entry(null,
+ "file:/JavaSoft/Test",
+ "file:/JavaSoft/Test"),
+ new Entry(null,
+ "file:/c:/JavaSoft/Test",
+ "file:/c:/JavaSoft/Test"),
+ new Entry(null,
+ "file:/c:/JavaSoft/Test:something",
+ "file:/c:/JavaSoft/Test:something"),
+ new Entry(null,
+ "file:/c:/JavaSoft/Test#anchor",
+ "file:/c:/JavaSoft/Test#anchor"),
+ new Entry("file://JavaSoft/Test",
+ "Test#bar",
+ "file://JavaSoft/Test#bar"),
+ new Entry("file://codrus/c:/jdk/eng/index.html",
+ "pulsar.html",
+ "file://codrus/c:/jdk/eng/pulsar.html"),
+ new Entry("file:///c:/jdk/eng/index.html",
+ "pulsar.html",
+ "file:/c:/jdk/eng/pulsar.html"),
+ new Entry("file:///jdk/eng/index.html",
+ "pulsar.html",
+ "file:/jdk/eng/pulsar.html"),
+ new Entry("file://JavaSoft/Test",
+ "file://radartoad.com/Test#bar",
+ "file://radartoad.com/Test#bar"),
+ new Entry("file://JavaSoft/Test",
+ "/c:/Test#bar",
+ "file://JavaSoft/c:/Test#bar"),
+ };
+
+ static Entry[] jarURLs = new Entry[] {
+ new Entry(null,
+ "jar:http://www.foo.com/dir1/jar.jar!/dir2/entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/dir2/entry.txt"),
+ new Entry(null,
+ "jar:http://www.foo.com/dir1/jar.jar!/",
+ "jar:http://www.foo.com/dir1/jar.jar!/"),
+ new Entry(null,
+ "jar:http://www.foo.com/dir1/jar.jar!/",
+ "jar:http://www.foo.com/dir1/jar.jar!/"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
+ "entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
+ "/entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
+ "dir1/entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
+ "/dir1/entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
+ "entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
+ "/entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
+ "/entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/dir1/",
+ "entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/dir2/dir3/entry2.txt",
+ "/dir1/entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
+ "/dir1/foo/entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/dir1/foo/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/dir1/dir2/dir3/",
+ "dir4/foo/entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/dir1/dir2/dir3/dir4/foo/entry.txt"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/",
+ "/dir1/foo/entry.txt",
+ "jar:http://www.foo.com/dir1/jar.jar!/dir1/foo/entry.txt"),
+ new Entry(null,
+ "jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor",
+ "jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/foo.txt",
+ "#anchor",
+ "jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor"),
+ new Entry("jar:http://www.foo.com/dir1/jar.jar!/foo/bar/",
+ "baz/quux#anchor",
+ "jar:http://www.foo.com/dir1/jar.jar!/foo/bar/baz/quux#anchor"),
+ new Entry("jar:http://balloo.com/olle.jar!/",
+ "p2",
+ "jar:http://balloo.com/olle.jar!/p2")
+ };
+
+ static Entry[] normalHttpURLs = new Entry[] {
+ new Entry("http://a/b/c/d;p?q", "g", "http://a/b/c/g"),
+ new Entry("http://a/b/c/d;p?q", "./g", "http://a/b/c/g"),
+ new Entry("http://a/b/c/d;p?q", "g/", "http://a/b/c/g/"),
+ new Entry("http://a/b/c/d;p?q", "/g", "http://a/g"),
+ new Entry("http://a/b/c/d;p?q", "//g", "http://g"),
+ new Entry("http://a/b/c/d;p?q", "?y", "http://a/b/c/?y"),
+ new Entry("http://a/b/c/d;p?q", "g?y", "http://a/b/c/g?y"),
+ new Entry("http://a/b/c/d;p?q", "g#s", "http://a/b/c/g#s"),
+ new Entry("http://a/b/c/d;p?q", "g?y#s", "http://a/b/c/g?y#s"),
+ new Entry("http://a/b/c/d;p?q", ";x", "http://a/b/c/;x"),
+ new Entry("http://a/b/c/d;p?q", "g;x", "http://a/b/c/g;x"),
+ new Entry("http://a/b/c/d;p?q", "g;x?y#s", "http://a/b/c/g;x?y#s"),
+ new Entry("http://a/b/c/d;p?q", ".", "http://a/b/c/"),
+ new Entry("http://a/b/c/d;p?q", "./", "http://a/b/c/"),
+ new Entry("http://a/b/c/d;p?q", "..", "http://a/b/"),
+ new Entry("http://a/b/c/d;p?q", "../", "http://a/b/"),
+ new Entry("http://a/b/c/d;p?q", "../g", "http://a/b/g"),
+ new Entry("http://a/b/c/d;p?q", "../..", "http://a/"),
+ new Entry("http://a/b/c/d;p?q", "../../", "http://a/"),
+ new Entry("http://a/b/c/d;p?q", "../../g", "http://a/g"),
+ new Entry(null,
+ "http://www.javasoft.com/jdc/community/chat/index.html#javalive?frontpage-jdc",
+ "http://www.javasoft.com/jdc/community/chat/index.html#javalive?frontpage-jdc")
+ };
+
+ static Entry[] abnormalHttpURLs = new Entry[] {
+ new Entry("http://a/b/c/d;p?q", "../../../g", "http://a/../g"),
+ new Entry("http://a/b/c/d;p?q", "../../../../g", "http://a/../../g"),
+ new Entry("http://a/b/c/d;p?q", "/./g", "http://a/./g"),
+ new Entry("http://a/b/c/d;p?q", "/../g", "http://a/../g"),
+ new Entry("http://a/b/c/d;p?q", ".g", "http://a/b/c/.g"),
+ new Entry("http://a/b/c/d;p?q", "g.", "http://a/b/c/g."),
+ new Entry("http://a/b/c/d;p?q", "./../g", "http://a/b/g"),
+ new Entry("http://a/b/c/d;p?q", "./g/.", "http://a/b/c/g/"),
+ new Entry("http://a/b/c/d;p?q", "g/./h", "http://a/b/c/g/h"),
+ new Entry("http://a/b/c/d;p?q", "g;x=1/./y", "http://a/b/c/g;x=1/y"),
+ new Entry("http://a/b/c/d;p?q", "g;x=1/../y", "http://a/b/c/y")
+ };
+
+ static Entry[] ftpURLs = new Entry[] {
+ new Entry(null,
+ "ftp://ftp.foo.com/dir1/entry.txt",
+ "ftp://ftp.foo.com/dir1/entry.txt"),
+ new Entry(null,
+ "ftp://br:pwd@ftp.foo.com/dir1/jar.jar",
+ "ftp://br:pwd@ftp.foo.com/dir1/jar.jar"),
+ new Entry("ftp://ftp.foo.com/dir1/foo.txt",
+ "bar.txt",
+ "ftp://ftp.foo.com/dir1/bar.txt"),
+ new Entry("ftp://ftp.foo.com/dir1/jar.jar",
+ "/entry.txt",
+ "ftp://ftp.foo.com/entry.txt"),
+ new Entry("ftp://ftp.foo.com/dir1/jar.jar",
+ "dir1/entry.txt",
+ "ftp://ftp.foo.com/dir1/dir1/entry.txt"),
+ new Entry("ftp://ftp.foo.com/dir1/jar.jar",
+ "/dir1/entry.txt",
+ "ftp://ftp.foo.com/dir1/entry.txt"),
+ new Entry("ftp://br:pwd@ftp.foo.com/dir1/jar.jar",
+ "/dir1/entry.txt",
+ "ftp://br:pwd@ftp.foo.com/dir1/entry.txt")
+ };
}
--- a/jdk/test/java/net/URL/HandlerLoop.java Fri Feb 01 22:18:18 2013 -0800
+++ b/jdk/test/java/net/URL/HandlerLoop.java Sat Feb 02 17:15:13 2013 +0000
@@ -36,7 +36,7 @@
public static void main(String args[]) throws Exception {
URL.setURLStreamHandlerFactory(
new HandlerFactory("sun.net.www.protocol"));
- URL url = new URL("file://bogus/index.html");
+ URL url = new URL("file:///bogus/index.html");
System.out.println("url = " + url);
url.openConnection();
}
--- a/jdk/test/java/net/URL/Test.java Fri Feb 01 22:18:18 2013 -0800
+++ b/jdk/test/java/net/URL/Test.java Sat Feb 02 17:15:13 2013 +0000
@@ -310,7 +310,14 @@
throw new RuntimeException("Test failed");
}
-
+ private static boolean hasFtp() {
+ try {
+ return new java.net.URL("ftp://") != null;
+ } catch (java.net.MalformedURLException x) {
+ System.out.println("FTP not supported by this runtime.");
+ return false;
+ }
+ }
// -- Tests --
@@ -319,8 +326,9 @@
header("RFC2396: Basic examples");
- test("ftp://ftp.is.co.za/rfc/rfc1808.txt")
- .s("ftp").h("ftp.is.co.za").p("/rfc/rfc1808.txt").z();
+ if (hasFtp())
+ test("ftp://ftp.is.co.za/rfc/rfc1808.txt")
+ .s("ftp").h("ftp.is.co.za").p("/rfc/rfc1808.txt").z();
test("http://www.math.uio.no/faq/compression-faq/part1.html")
.s("http").h("www.math.uio.no").p("/faq/compression-faq/part1.html").z();
@@ -328,8 +336,9 @@
test("http://www.w3.org/Addressing/")
.s("http").h("www.w3.org").p("/Addressing/").z();
- test("ftp://ds.internic.net/rfc/")
- .s("ftp").h("ds.internic.net").p("/rfc/").z();
+ if (hasFtp())
+ test("ftp://ds.internic.net/rfc/")
+ .s("ftp").h("ds.internic.net").p("/rfc/").z();
test("http://www.ics.uci.edu/pub/ietf/url/historical.html#WARNING")
.s("http").h("www.ics.uci.edu").p("/pub/ietf/url/historical.html")
--- a/jdk/test/java/net/URL/URIToURLTest.java Fri Feb 01 22:18:18 2013 -0800
+++ b/jdk/test/java/net/URL/URIToURLTest.java Sat Feb 02 17:15:13 2013 +0000
@@ -28,20 +28,22 @@
*/
import java.net.*;
+import java.util.ArrayList;
+import java.util.List;
public class URIToURLTest {
public static void main(String args[]) throws Exception {
- String[] uris = {
- "http://jag:cafebabe@java.sun.com:94/b/c/d?q#g",
- "http://[1080:0:0:0:8:800:200C:417A]/index.html",
- "http://a/b/c/d;p?q",
- "ftp://ftp.is.co.za/rfc/rfc1808.txt",
- "mailto:mduerst@ifi.unizh.ch", // opaque url
- "http:comp.infosystems.www.servers.unix" //opaque url
- };
+ List<String> uris = new ArrayList<>();
+ uris.add("http://jag:cafebabe@java.sun.com:94/b/c/d?q#g");
+ uris.add("http://[1080:0:0:0:8:800:200C:417A]/index.html");
+ uris.add("http://a/b/c/d;p?q");
+ uris.add("mailto:mduerst@ifi.unizh.ch");
+ uris.add("http:comp.infosystems.www.servers.unix");
+ if (hasFtp())
+ uris.add("ftp://ftp.is.co.za/rfc/rfc1808.txt");
- for (int i = 0; i < uris.length; i++) {
- URI uri = new URI(uris[i]);
+ for (String uriStr : uris) {
+ URI uri = new URI(uriStr);
URL url = uri.toURL();
String scheme = uri.getScheme();
boolean schemeCheck = scheme == null? url.getProtocol() == null :
@@ -111,4 +113,13 @@
url.getRef());
}
}
+
+ private static boolean hasFtp() {
+ try {
+ return new java.net.URL("ftp://") != null;
+ } catch (java.net.MalformedURLException x) {
+ System.out.println("FTP not supported by this runtime.");
+ return false;
+ }
+ }
}
--- a/jdk/test/java/net/URL/abnormal_http_urls Fri Feb 01 22:18:18 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-URL: http://a/b/c/d;p?q
-spec: ../../../g
-expected: http://a/../g
-
-URL: http://a/b/c/d;p?q
-spec: ../../../../g
-expected: http://a/../../g
-
-URL: http://a/b/c/d;p?q
-spec: /./g
-expected: http://a/./g
-
-URL: http://a/b/c/d;p?q
-spec: /../g
-expected: http://a/../g
-
-URL: http://a/b/c/d;p?q
-spec: .g
-expected: http://a/b/c/.g
-
-URL: http://a/b/c/d;p?q
-spec: g.
-expected: http://a/b/c/g.
-
-URL: http://a/b/c/d;p?q
-spec: ./../g
-expected: http://a/b/g
-
-URL: http://a/b/c/d;p?q
-spec: ./g/.
-expected: http://a/b/c/g/
-
-URL: http://a/b/c/d;p?q
-spec: g/./h
-expected: http://a/b/c/g/h
-
-URL: http://a/b/c/d;p?q
-spec: g;x=1/./y
-expected: http://a/b/c/g;x=1/y
-
-URL: http://a/b/c/d;p?q
-spec: g;x=1/../y
-expected: http://a/b/c/y
--- a/jdk/test/java/net/URL/ftp_urls Fri Feb 01 22:18:18 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-URL: null
-spec: ftp://ftp.foo.com/dir1/entry.txt
-expected: ftp://ftp.foo.com/dir1/entry.txt
-
-URL: null
-spec: ftp://br:pwd@ftp.foo.com/dir1/jar.jar
-expected: ftp://br:pwd@ftp.foo.com/dir1/jar.jar
-
-URL: ftp://ftp.foo.com/dir1/foo.txt
-spec: bar.txt
-expected: ftp://ftp.foo.com/dir1/bar.txt
-
-URL: ftp://ftp.foo.com/dir1/jar.jar
-spec: /entry.txt
-expected: ftp://ftp.foo.com/entry.txt
-
-URL: ftp://ftp.foo.com/dir1/jar.jar
-spec: dir1/entry.txt
-expected: ftp://ftp.foo.com/dir1/dir1/entry.txt
-
-URL: ftp://ftp.foo.com/dir1/jar.jar
-spec: /dir1/entry.txt
-expected: ftp://ftp.foo.com/dir1/entry.txt
-
-URL: ftp://br:pwd@ftp.foo.com/dir1/jar.jar
-spec: /dir1/entry.txt
-expected: ftp://br:pwd@ftp.foo.com/dir1/entry.txt
--- a/jdk/test/java/net/URL/jar_urls Fri Feb 01 22:18:18 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-URL: null
-spec: jar:http://www.foo.com/dir1/jar.jar!/dir2/entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/dir2/entry.txt
-
-URL: null
-spec: jar:http://www.foo.com/dir1/jar.jar!/
-expected: jar:http://www.foo.com/dir1/jar.jar!/
-
-URL: null
-spec: jar:http://www.foo.com/dir1/jar.jar!/
-expected: jar:http://www.foo.com/dir1/jar.jar!/
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/
-spec: entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/
-spec: /entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/
-spec: dir1/entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/
-spec: /dir1/entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/
-spec: entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/
-spec: /entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/
-spec: /entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/dir1/
-spec: entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/dir2/dir3/entry2.txt
-spec: /dir1/entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/
-spec: /dir1/foo/entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/foo/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/dir1/dir2/dir3/
-spec: dir4/foo/entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/dir2/dir3/dir4/foo/entry.txt
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/
-spec: /dir1/foo/entry.txt
-expected: jar:http://www.foo.com/dir1/jar.jar!/dir1/foo/entry.txt
-
-URL: null
-spec: jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor
-expected: jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/foo.txt
-spec: #anchor
-expected: jar:http://www.foo.com/dir1/jar.jar!/foo.txt#anchor
-
-URL: jar:http://www.foo.com/dir1/jar.jar!/foo/bar/
-spec: baz/quux#anchor
-expected: jar:http://www.foo.com/dir1/jar.jar!/foo/bar/baz/quux#anchor
-
-URL: jar:http://balloo.com/olle.jar!/
-spec: p2
-expected: jar:http://balloo.com/olle.jar!/p2
--- a/jdk/test/java/net/URL/normal_http_urls Fri Feb 01 22:18:18 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-URL: http://a/b/c/d;p?q
-spec: g
-expected: http://a/b/c/g
-
-URL: http://a/b/c/d;p?q
-spec: ./g
-expected: http://a/b/c/g
-
-URL: http://a/b/c/d;p?q
-spec: g/
-expected: http://a/b/c/g/
-
-URL: http://a/b/c/d;p?q
-spec: /g
-expected: http://a/g
-
-URL: http://a/b/c/d;p?q
-spec: //g
-expected: http://g
-
-URL: http://a/b/c/d;p?q
-spec: ?y
-expected: http://a/b/c/?y
-
-URL: http://a/b/c/d;p?q
-spec: g?y
-expected: http://a/b/c/g?y
-
-URL: http://a/b/c/d;p?q
-spec: g#s
-expected: http://a/b/c/g#s
-
-URL: http://a/b/c/d;p?q
-spec: g?y#s
-expected: http://a/b/c/g?y#s
-
-URL: http://a/b/c/d;p?q
-spec: ;x
-expected: http://a/b/c/;x
-
-URL: http://a/b/c/d;p?q
-spec: g;x
-expected: http://a/b/c/g;x
-
-URL: http://a/b/c/d;p?q
-spec: g;x?y#s
-expected: http://a/b/c/g;x?y#s
-
-URL: http://a/b/c/d;p?q
-spec: .
-expected: http://a/b/c/
-
-URL: http://a/b/c/d;p?q
-spec: ./
-expected: http://a/b/c/
-
-URL: http://a/b/c/d;p?q
-spec: ..
-expected: http://a/b/
-
-URL: http://a/b/c/d;p?q
-spec: ../
-expected: http://a/b/
-
-URL: http://a/b/c/d;p?q
-spec: ../g
-expected: http://a/b/g
-
-URL: http://a/b/c/d;p?q
-spec: ../..
-expected: http://a/
-
-URL: http://a/b/c/d;p?q
-spec: ../../
-expected: http://a/
-
-URL: http://a/b/c/d;p?q
-spec: ../../g
-expected: http://a/g
-
-URL: null
-spec: http://www.javasoft.com/jdc/community/chat/index.html#javalive?frontpage-jdc
-expected: http://www.javasoft.com/jdc/community/chat/index.html#javalive?frontpage-jdc
--- a/jdk/test/java/net/URL/runconstructor.sh Fri Feb 01 22:18:18 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-#
-# Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4393671
-# @summary URL constructor URL(URL context, String spec) FAILED with specific input in merlin
-#
-OS=`uname -s`
-case "$OS" in
- SunOS | Linux | Darwin )
- PS=":"
- FS="/"
- ;;
- CYGWIN* )
- PS=";"
- FS="/"
- ;;
- Windows* )
- PS=";"
- FS="\\"
- ;;
- * )
- echo "Unrecognized system!"
- exit 1;
- ;;
-esac
-${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . \
- ${TESTSRC}${FS}Constructor.java
-
-failures=0
-
-go() {
- echo ''
- ${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} Constructor $1
- if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
-}
-
-go ${TESTSRC}${FS}share_file_urls
-go ${TESTSRC}${FS}jar_urls
-go ${TESTSRC}${FS}normal_http_urls
-go ${TESTSRC}${FS}ftp_urls
-go ${TESTSRC}${FS}abnormal_http_urls
-
-if [ "$failures" != "0" ]; then
- echo $failures tests failed
- exit 1;
-fi
--- a/jdk/test/java/net/URL/share_file_urls Fri Feb 01 22:18:18 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-URL: null
-spec: file://JavaSoft/Test
-expected: file://JavaSoft/Test
-
-URL: null
-spec: file:///JavaSoft/Test
-expected: file:/JavaSoft/Test
-
-URL: null
-spec: file:/JavaSoft/Test
-expected: file:/JavaSoft/Test
-
-URL: null
-spec: file:/c:/JavaSoft/Test
-expected: file:/c:/JavaSoft/Test
-
-URL: null
-spec: file:/c:/JavaSoft/Test:something
-expected: file:/c:/JavaSoft/Test:something
-
-URL: null
-spec: file:/c:/JavaSoft/Test#anchor
-expected: file:/c:/JavaSoft/Test#anchor
-
-URL: null
-spec: file:/JavaSoft/Test
-expected: file:/JavaSoft/Test
-
-URL: file://JavaSoft/Test
-spec: Test#bar
-expected: file://JavaSoft/Test#bar
-
-URL: file://codrus/c:/jdk/eng/index.html
-spec: pulsar.html
-expected: file://codrus/c:/jdk/eng/pulsar.html
-
-URL: file:///c:/jdk/eng/index.html
-spec: pulsar.html
-expected: file:/c:/jdk/eng/pulsar.html
-
-URL: file:///jdk/eng/index.html
-spec: pulsar.html
-expected: file:/jdk/eng/pulsar.html
-
-URL: file://JavaSoft/Test
-spec: file://radartoad.com/Test#bar
-expected: file://radartoad.com/Test#bar
-
-URL: file://JavaSoft/Test
-spec: /c:/Test#bar
-expected: file://JavaSoft/c:/Test#bar
\ No newline at end of file
--- a/jdk/test/java/net/URL/win32_file_urls Fri Feb 01 22:18:18 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-URL: null
-spec: file://c:\JavaSoft\Test
-expected: file://c:/JavaSoft/Test
-
-URL: null
-spec: file:/c:\JavaSoft\Test
-expected: file:/c:/JavaSoft/Test
-
-URL: null
-spec: file:/c:\JavaSoft\Test:something#anchor
-expected: file:/c:/JavaSoft/Test:something#anchor
-
-URL: file:///c:\jdk\eng\index.html
-spec: pulsar.html
-expected: file:/c:/jdk/eng/pulsar.html
\ No newline at end of file
--- a/jdk/test/java/net/URLConnection/RequestProperties.java Fri Feb 01 22:18:18 2013 -0800
+++ b/jdk/test/java/net/URLConnection/RequestProperties.java Sat Feb 02 17:15:13 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2013 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -28,90 +28,55 @@
*/
import java.net.*;
+import java.util.ArrayList;
+import java.util.List;
public class RequestProperties {
+ static int failed;
+
public static void main (String args[]) throws Exception {
- URL url0 = new URL ("http://foo.com/bar/");
- URL url1 = new URL ("file:/etc/passwd");
- URL url2 = new URL ("ftp://foo:bar@foobar.com/etc/passwd");
- URL url3 = new URL ("jar:http://foo.com/bar.html!/foo/bar");
- URLConnection urlc0 = url0.openConnection ();
- URLConnection urlc1 = url1.openConnection ();
- URLConnection urlc2 = url2.openConnection ();
- URLConnection urlc3 = url3.openConnection ();
- int count = 0;
- String s = null;
- try {
- urlc0.setRequestProperty (null, null);
- System.out.println ("http: setRequestProperty (null,) did not throw NPE");
- } catch (NullPointerException e) {
- count ++;
- }
+ List<String> urls = new ArrayList<>();
+ urls.add("http://foo.com/bar/");
+ urls.add("jar:http://foo.com/bar.html!/foo/bar");
+ urls.add("file:/etc/passwd");
+ if (hasFtp())
+ urls.add("ftp://foo:bar@foobar.com/etc/passwd");
+
+ for (String urlStr : urls)
+ test(new URL(urlStr));
+
+ if (failed != 0)
+ throw new RuntimeException(failed + " errors") ;
+ }
+
+ static void test(URL url) throws Exception {
+ URLConnection urlc = url.openConnection();
try {
- urlc0.addRequestProperty (null, null);
- System.out.println ("http: addRequestProperty (null,) did not throw NPE");
- } catch (NullPointerException e) {
- count ++;
- }
+ urlc.setRequestProperty(null, null);
+ System.out.println(url.getProtocol()
+ + ": setRequestProperty(null,) did not throw NPE");
+ failed++;
+ } catch (NullPointerException e) { /* Expected */ }
try {
- urlc1.setRequestProperty (null, null);
- System.out.println ("file: setRequestProperty (null,) did not throw NPE");
- } catch (NullPointerException e) {
- count ++;
- }
- try {
- urlc1.addRequestProperty (null, null);
- System.out.println ("file: addRequestProperty (null,) did not throw NPE");
- } catch (NullPointerException e) {
- count ++;
- }
- try {
- urlc2.setRequestProperty (null, null);
- System.out.println ("ftp: setRequestProperty (null,) did not throw NPE");
- } catch (NullPointerException e) {
- count ++;
+ urlc.addRequestProperty(null, null);
+ System.out.println(url.getProtocol()
+ + ": addRequestProperty(null,) did not throw NPE");
+ failed++;
+ } catch (NullPointerException e) { /* Expected */ }
+
+ if (urlc.getRequestProperty(null) != null) {
+ System.out.println(url.getProtocol()
+ + ": getRequestProperty(null,) did not return null");
+ failed++;
}
- try {
- urlc2.addRequestProperty (null, null);
- System.out.println ("ftp: addRequestProperty (null,) did not throw NPE");
- } catch (NullPointerException e) {
- count ++;
- }
- try {
- urlc3.setRequestProperty (null, null);
- System.out.println ("jar: setRequestProperty (null,) did not throw NPE");
- } catch (NullPointerException e) {
- count ++;
- }
+ }
+
+ private static boolean hasFtp() {
try {
- urlc3.addRequestProperty (null, null);
- System.out.println ("jar: addRequestProperty (null,) did not throw NPE");
- } catch (NullPointerException e) {
- count ++;
- }
- if (urlc0.getRequestProperty (null) != null) {
- System.out.println ("http: getRequestProperty (null,) did not return null");
- } else {
- count ++;
- }
- if (urlc1.getRequestProperty (null) != null) {
- System.out.println ("file: getRequestProperty (null,) did not return null");
- } else {
- count ++;
- }
- if (urlc2.getRequestProperty (null) != null) {
- System.out.println ("ftp: getRequestProperty (null,) did not return null");
- } else {
- count ++;
- }
- if (urlc2.getRequestProperty (null) != null) {
- System.out.println ("jar: getRequestProperty (null,) did not return null");
- } else {
- count ++;
- }
-
- if (count != 12) {
- throw new RuntimeException ((12 -count) + " errors") ;
+ return new java.net.URL("ftp://") != null;
+ } catch (java.net.MalformedURLException x) {
+ System.out.println("FTP not supported by this runtime.");
+ return false;
}
}
}
--- a/jdk/test/java/net/URLConnection/RequestPropertyValues.java Fri Feb 01 22:18:18 2013 -0800
+++ b/jdk/test/java/net/URLConnection/RequestPropertyValues.java Sat Feb 02 17:15:13 2013 +0000
@@ -27,8 +27,11 @@
* @summary Test URLConnection Request Proterties
*/
+import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.List;
/**
* Part1:
@@ -45,28 +48,29 @@
}
public static void part1() throws Exception {
- URL[] urls = { new URL("http://localhost:8088"),
- new URL("file:/etc/passwd"),
- new URL("ftp://foo:bar@foobar.com/etc/passwd"),
- new URL("jar:http://foo.com/bar.html!/foo/bar")
- };
+ List<URL> urls = new ArrayList<>();
+ urls.add(new URL("http://localhost:8088"));
+ urls.add(new URL("file:/etc/passwd"));
+ urls.add(new URL("jar:http://foo.com/bar.html!/foo/bar"));
+ if (hasFtp())
+ urls.add(new URL("ftp://foo:bar@foobar.com/etc/passwd"));
boolean failed = false;
- for (int proto = 0; proto < urls.length; proto++) {
- URLConnection uc = (URLConnection) urls[proto].openConnection();
+ for (URL url : urls) {
+ URLConnection uc = url.openConnection();
try {
uc.setRequestProperty("TestHeader", null);
} catch (NullPointerException npe) {
System.out.println("setRequestProperty is throwing NPE" +
- " for url: " + urls[proto]);
+ " for url: " + url);
failed = true;
}
try {
uc.addRequestProperty("TestHeader", null);
} catch (NullPointerException npe) {
System.out.println("addRequestProperty is throwing NPE" +
- " for url: " + urls[proto]);
+ " for url: " + url);
failed = true;
}
}
@@ -110,4 +114,12 @@
}
}
+ private static boolean hasFtp() {
+ try {
+ return new java.net.URL("ftp://") != null;
+ } catch (java.net.MalformedURLException x) {
+ System.out.println("FTP not supported by this runtime.");
+ return false;
+ }
+ }
}
Binary file jdk/test/sun/net/ftp/EncDec.doc has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/net/ftp/MarkResetTest.java Sat Feb 02 17:15:13 2013 +0000
@@ -0,0 +1,455 @@
+/*
+ * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ *
+ * run from MarkResetTest.sh
+ */
+
+import java.io.*;
+import java.net.*;
+import java.util.regex.*;
+
+public class MarkResetTest {
+
+ /**
+ * A class that simulates, on a separate, an FTP server.
+ */
+ private class FtpServer extends Thread {
+ private ServerSocket server;
+ private int port;
+ private boolean done = false;
+ private boolean pasvEnabled = true;
+ private boolean portEnabled = true;
+ private boolean extendedEnabled = true;
+
+ /**
+ * This Inner class will handle ONE client at a time.
+ * That's where 99% of the protocol handling is done.
+ */
+
+ private class FtpServerHandler extends Thread {
+ BufferedReader in;
+ PrintWriter out;
+ Socket client;
+ private final int ERROR = 0;
+ private final int USER = 1;
+ private final int PASS = 2;
+ private final int CWD = 3;
+ private final int TYPE = 4;
+ private final int RETR = 5;
+ private final int PASV = 6;
+ private final int PORT = 7;
+ private final int QUIT = 8;
+ private final int EPSV = 9;
+ String[] cmds = { "USER", "PASS", "CWD",
+ "TYPE", "RETR", "PASV",
+ "PORT", "QUIT", "EPSV"};
+ private String arg = null;
+ private ServerSocket pasv = null;
+ private int data_port = 0;
+ private InetAddress data_addr = null;
+
+ /**
+ * Parses a line to match it with one of the supported FTP commands.
+ * Returns the command number.
+ */
+
+ private int parseCmd(String cmd) {
+ if (cmd == null || cmd.length() < 3)
+ return ERROR;
+ int blank = cmd.indexOf(' ');
+ if (blank < 0)
+ blank = cmd.length();
+ if (blank < 3)
+ return ERROR;
+ String s = cmd.substring(0, blank);
+ if (cmd.length() > blank+1)
+ arg = cmd.substring(blank+1, cmd.length());
+ else
+ arg = null;
+ for (int i = 0; i < cmds.length; i++) {
+ if (s.equalsIgnoreCase(cmds[i]))
+ return i+1;
+ }
+ return ERROR;
+ }
+
+ public FtpServerHandler(Socket cl) {
+ client = cl;
+ }
+
+ protected boolean isPasvSet() {
+ if (pasv != null && !pasvEnabled) {
+ try {
+ pasv.close();
+ } catch (IOException ex) {
+ }
+ pasv = null;
+ }
+ if (pasvEnabled && pasv != null)
+ return true;
+ return false;
+ }
+
+ /**
+ * Open the data socket with the client. This can be the
+ * result of a "PASV" or "PORT" command.
+ */
+
+ protected OutputStream getOutDataStream() {
+ try {
+ if (isPasvSet()) {
+ Socket s = pasv.accept();
+ return s.getOutputStream();
+ }
+ if (data_addr != null) {
+ Socket s = new Socket(data_addr, data_port);
+ data_addr = null;
+ data_port = 0;
+ return s.getOutputStream();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ protected InputStream getInDataStream() {
+ try {
+ if (isPasvSet()) {
+ Socket s = pasv.accept();
+ return s.getInputStream();
+ }
+ if (data_addr != null) {
+ Socket s = new Socket(data_addr, data_port);
+ data_addr = null;
+ data_port = 0;
+ return s.getInputStream();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Handles the protocol exchange with the client.
+ */
+
+ public void run() {
+ boolean done = false;
+ String str;
+ int res;
+ boolean logged = false;
+ boolean waitpass = false;
+
+ try {
+ in = new BufferedReader(new InputStreamReader(
+ client.getInputStream()));
+ out = new PrintWriter(client.getOutputStream(), true);
+ out.println("220 tatooine FTP server (SunOS 5.8) ready.");
+ } catch (Exception ex) {
+ return;
+ }
+ while (!done) {
+ try {
+ str = in.readLine();
+ res = parseCmd(str);
+ if ((res > PASS && res != QUIT) && !logged) {
+ out.println("530 Not logged in.");
+ continue;
+ }
+ switch (res) {
+ case ERROR:
+ out.println("500 '" + str +
+ "': command not understood.");
+ break;
+ case USER:
+ if (!logged && !waitpass) {
+ out.println("331 Password required for " + arg);
+ waitpass = true;
+ } else {
+ out.println("503 Bad sequence of commands.");
+ }
+ break;
+ case PASS:
+ if (!logged && waitpass) {
+ out.println("230-Welcome to the FTP server!");
+ out.println("ab");
+ out.println("230 Guest login ok, " +
+ "access restrictions apply.");
+ logged = true;
+ waitpass = false;
+ } else
+ out.println("503 Bad sequence of commands.");
+ break;
+ case QUIT:
+ out.println("221 Goodbye.");
+ out.flush();
+ out.close();
+ if (pasv != null)
+ pasv.close();
+ done = true;
+ break;
+ case TYPE:
+ out.println("200 Type set to " + arg + ".");
+ break;
+ case CWD:
+ out.println("250 CWD command successful.");
+ break;
+ case EPSV:
+ if (!extendedEnabled || !pasvEnabled) {
+ out.println("500 EPSV is disabled, " +
+ "use PORT instead.");
+ continue;
+ }
+ if ("all".equalsIgnoreCase(arg)) {
+ out.println("200 EPSV ALL command successful.");
+ continue;
+ }
+ try {
+ if (pasv == null)
+ pasv = new ServerSocket(0);
+ int port = pasv.getLocalPort();
+ out.println("229 Entering Extended" +
+ " Passive Mode (|||" + port + "|)");
+ } catch (IOException ssex) {
+ out.println("425 Can't build data connection:" +
+ " Connection refused.");
+ }
+ break;
+
+ case PASV:
+ if (!pasvEnabled) {
+ out.println("500 PASV is disabled, " +
+ "use PORT instead.");
+ continue;
+ }
+ try {
+ if (pasv == null)
+ pasv = new ServerSocket(0);
+ int port = pasv.getLocalPort();
+
+ // Parenthesis are optional, so let's be
+ // nasty and don't put them
+ out.println("227 Entering Passive Mode" +
+ " 127,0,0,1," +
+ (port >> 8) + "," + (port & 0xff));
+ } catch (IOException ssex) {
+ out.println("425 Can't build data connection:" +
+ "Connection refused.");
+ }
+ break;
+ case PORT:
+ if (!portEnabled) {
+ out.println("500 PORT is disabled, " +
+ "use PASV instead");
+ continue;
+ }
+ StringBuffer host;
+ int i = 0, j = 4;
+ while (j > 0) {
+ i = arg.indexOf(',', i + 1);
+ if (i < 0)
+ break;
+ j--;
+ }
+ if (j != 0) {
+ out.println("500 '" + arg + "':" +
+ " command not understood.");
+ continue;
+ }
+ try {
+ host = new StringBuffer(arg.substring(0, i));
+ for (j = 0; j < host.length(); j++)
+ if (host.charAt(j) == ',')
+ host.setCharAt(j, '.');
+ String ports = arg.substring(i+1);
+ i = ports.indexOf(',');
+ data_port = Integer.parseInt(
+ ports.substring(0, i)) << 8;
+ data_port += (Integer.parseInt(
+ ports.substring(i+1)));
+ data_addr = InetAddress.getByName(
+ host.toString());
+ out.println("200 Command okay.");
+ } catch (Exception ex3) {
+ data_port = 0;
+ data_addr = null;
+ out.println("500 '" + arg + "':" +
+ " command not understood.");
+ }
+ break;
+ case RETR:
+ {
+ File file = new File(arg);
+ if (!file.exists()) {
+ System.out.println("File not found");
+ out.println("200 Command okay.");
+ out.println("550 '" + arg +
+ "' No such file or directory.");
+ break;
+ }
+ FileInputStream fin = new FileInputStream(file);
+ OutputStream dout = getOutDataStream();
+ if (dout != null) {
+ out.println("150 Binary data connection" +
+ " for " + arg +
+ " (" + client.getInetAddress().
+ getHostAddress() + ") (" +
+ file.length() + " bytes).");
+ int c;
+ int len = 0;
+ while ((c = fin.read()) != -1) {
+ dout.write(c);
+ len++;
+ }
+ dout.flush();
+ dout.close();
+ fin.close();
+ out.println("226 Binary Transfer complete.");
+ } else {
+ out.println("425 Can't build data" +
+ " connection: Connection refused.");
+ }
+ }
+ break;
+ }
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ try {
+ out.close();
+ } catch (Exception ex2) {
+ }
+ done = true;
+ }
+ }
+ }
+ }
+
+ public FtpServer(int port) {
+ this.port = port;
+ }
+
+ public FtpServer() {
+ this(21);
+ }
+
+ public int getPort() {
+ if (server != null)
+ return server.getLocalPort();
+ return 0;
+ }
+
+ /**
+ * A way to tell the server that it can stop.
+ */
+ synchronized public void terminate() {
+ done = true;
+ }
+
+
+ /*
+ * All we got to do here is create a ServerSocket and wait for a
+ * connection. When a connection happens, we just have to create
+ * a thread that will handle it.
+ */
+ public void run() {
+ try {
+ server = new ServerSocket(port);
+ Socket client;
+ client = server.accept();
+ (new FtpServerHandler(client)).start();
+ server.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ MarkResetTest test = new MarkResetTest();
+ }
+
+ public MarkResetTest() {
+ FtpServer server = null;
+ try {
+ server = new FtpServer(0);
+ server.start();
+ int port = 0;
+ while (port == 0) {
+ Thread.sleep(500);
+ port = server.getPort();
+ }
+
+ String filename = "EncDec.doc";
+ URL url = new URL("ftp://localhost:" + port + "/" +
+ filename);
+
+ URLConnection con = url.openConnection();
+ System.out.println("getContent: " + con.getContent());
+ System.out.println("getContent-length: " + con.getContentLength());
+
+ InputStream is = con.getInputStream();
+
+ /**
+ * guessContentTypeFromStream method calls mark and reset methods
+ * on the given stream. Make sure that calling
+ * guessContentTypeFromStream repeatedly does not affect
+ * reading from the stream afterwards
+ */
+ System.out.println("Call GuessContentTypeFromStream()" +
+ " several times..");
+ for (int i = 0; i < 5; i++) {
+ System.out.println((i + 1) + " mime-type: " +
+ con.guessContentTypeFromStream(is));
+ }
+
+ int len = 0;
+ int c;
+ while ((c = is.read()) != -1) {
+ len++;
+ }
+ is.close();
+ System.out.println("read: " + len + " bytes of the file");
+
+ // We're done!
+ server.terminate();
+ server.interrupt();
+
+ // Did we pass ?
+ if (len != (new File(filename)).length()) {
+ throw new Exception("Failed to read the file correctly");
+ }
+ System.out.println("PASSED: File read correctly");
+ } catch (Exception e) {
+ e.printStackTrace();
+ try {
+ server.terminate();
+ server.interrupt();
+ } catch (Exception ex) {
+ }
+ throw new RuntimeException("FTP support error: " + e.getMessage());
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/net/ftp/MarkResetTest.sh Sat Feb 02 17:15:13 2013 +0000
@@ -0,0 +1,55 @@
+#
+# Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# @test
+# @bug 4673103
+# @run shell/timeout=140 MarkResetTest.sh
+# @summary URLConnection.getContent() hangs over FTP for DOC, PPT, XLS files
+
+OS=`uname -s`
+case "$OS" in
+ SunOS | Linux | Darwin )
+ PS=":"
+ FS="/"
+ ;;
+ CYGWIN* )
+ PS=";"
+ FS="/"
+ ;;
+ Windows* )
+ PS=";"
+ FS="\\"
+ ;;
+ * )
+ echo "Unrecognized system!"
+ exit 1;
+ ;;
+esac
+
+${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}${FS}MarkResetTest.java
+
+# ftp server used by the test requires the file to be present
+# in this directory
+cp ${TESTSRC}${FS}EncDec.doc .
+
+${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} MarkResetTest
Binary file jdk/test/sun/net/www/EncDec.doc has changed
--- a/jdk/test/sun/net/www/MarkResetTest.java Fri Feb 01 22:18:18 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,455 +0,0 @@
-/*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- *
- * run from MarkResetTest.sh
- */
-
-import java.io.*;
-import java.net.*;
-import java.util.regex.*;
-
-public class MarkResetTest {
-
- /**
- * A class that simulates, on a separate, an FTP server.
- */
- private class FtpServer extends Thread {
- private ServerSocket server;
- private int port;
- private boolean done = false;
- private boolean pasvEnabled = true;
- private boolean portEnabled = true;
- private boolean extendedEnabled = true;
-
- /**
- * This Inner class will handle ONE client at a time.
- * That's where 99% of the protocol handling is done.
- */
-
- private class FtpServerHandler extends Thread {
- BufferedReader in;
- PrintWriter out;
- Socket client;
- private final int ERROR = 0;
- private final int USER = 1;
- private final int PASS = 2;
- private final int CWD = 3;
- private final int TYPE = 4;
- private final int RETR = 5;
- private final int PASV = 6;
- private final int PORT = 7;
- private final int QUIT = 8;
- private final int EPSV = 9;
- String[] cmds = { "USER", "PASS", "CWD",
- "TYPE", "RETR", "PASV",
- "PORT", "QUIT", "EPSV"};
- private String arg = null;
- private ServerSocket pasv = null;
- private int data_port = 0;
- private InetAddress data_addr = null;
-
- /**
- * Parses a line to match it with one of the supported FTP commands.
- * Returns the command number.
- */
-
- private int parseCmd(String cmd) {
- if (cmd == null || cmd.length() < 3)
- return ERROR;
- int blank = cmd.indexOf(' ');
- if (blank < 0)
- blank = cmd.length();
- if (blank < 3)
- return ERROR;
- String s = cmd.substring(0, blank);
- if (cmd.length() > blank+1)
- arg = cmd.substring(blank+1, cmd.length());
- else
- arg = null;
- for (int i = 0; i < cmds.length; i++) {
- if (s.equalsIgnoreCase(cmds[i]))
- return i+1;
- }
- return ERROR;
- }
-
- public FtpServerHandler(Socket cl) {
- client = cl;
- }
-
- protected boolean isPasvSet() {
- if (pasv != null && !pasvEnabled) {
- try {
- pasv.close();
- } catch (IOException ex) {
- }
- pasv = null;
- }
- if (pasvEnabled && pasv != null)
- return true;
- return false;
- }
-
- /**
- * Open the data socket with the client. This can be the
- * result of a "PASV" or "PORT" command.
- */
-
- protected OutputStream getOutDataStream() {
- try {
- if (isPasvSet()) {
- Socket s = pasv.accept();
- return s.getOutputStream();
- }
- if (data_addr != null) {
- Socket s = new Socket(data_addr, data_port);
- data_addr = null;
- data_port = 0;
- return s.getOutputStream();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- protected InputStream getInDataStream() {
- try {
- if (isPasvSet()) {
- Socket s = pasv.accept();
- return s.getInputStream();
- }
- if (data_addr != null) {
- Socket s = new Socket(data_addr, data_port);
- data_addr = null;
- data_port = 0;
- return s.getInputStream();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * Handles the protocol exchange with the client.
- */
-
- public void run() {
- boolean done = false;
- String str;
- int res;
- boolean logged = false;
- boolean waitpass = false;
-
- try {
- in = new BufferedReader(new InputStreamReader(
- client.getInputStream()));
- out = new PrintWriter(client.getOutputStream(), true);
- out.println("220 tatooine FTP server (SunOS 5.8) ready.");
- } catch (Exception ex) {
- return;
- }
- while (!done) {
- try {
- str = in.readLine();
- res = parseCmd(str);
- if ((res > PASS && res != QUIT) && !logged) {
- out.println("530 Not logged in.");
- continue;
- }
- switch (res) {
- case ERROR:
- out.println("500 '" + str +
- "': command not understood.");
- break;
- case USER:
- if (!logged && !waitpass) {
- out.println("331 Password required for " + arg);
- waitpass = true;
- } else {
- out.println("503 Bad sequence of commands.");
- }
- break;
- case PASS:
- if (!logged && waitpass) {
- out.println("230-Welcome to the FTP server!");
- out.println("ab");
- out.println("230 Guest login ok, " +
- "access restrictions apply.");
- logged = true;
- waitpass = false;
- } else
- out.println("503 Bad sequence of commands.");
- break;
- case QUIT:
- out.println("221 Goodbye.");
- out.flush();
- out.close();
- if (pasv != null)
- pasv.close();
- done = true;
- break;
- case TYPE:
- out.println("200 Type set to " + arg + ".");
- break;
- case CWD:
- out.println("250 CWD command successful.");
- break;
- case EPSV:
- if (!extendedEnabled || !pasvEnabled) {
- out.println("500 EPSV is disabled, " +
- "use PORT instead.");
- continue;
- }
- if ("all".equalsIgnoreCase(arg)) {
- out.println("200 EPSV ALL command successful.");
- continue;
- }
- try {
- if (pasv == null)
- pasv = new ServerSocket(0);
- int port = pasv.getLocalPort();
- out.println("229 Entering Extended" +
- " Passive Mode (|||" + port + "|)");
- } catch (IOException ssex) {
- out.println("425 Can't build data connection:" +
- " Connection refused.");
- }
- break;
-
- case PASV:
- if (!pasvEnabled) {
- out.println("500 PASV is disabled, " +
- "use PORT instead.");
- continue;
- }
- try {
- if (pasv == null)
- pasv = new ServerSocket(0);
- int port = pasv.getLocalPort();
-
- // Parenthesis are optional, so let's be
- // nasty and don't put them
- out.println("227 Entering Passive Mode" +
- " 127,0,0,1," +
- (port >> 8) + "," + (port & 0xff));
- } catch (IOException ssex) {
- out.println("425 Can't build data connection:" +
- "Connection refused.");
- }
- break;
- case PORT:
- if (!portEnabled) {
- out.println("500 PORT is disabled, " +
- "use PASV instead");
- continue;
- }
- StringBuffer host;
- int i = 0, j = 4;
- while (j > 0) {
- i = arg.indexOf(',', i + 1);
- if (i < 0)
- break;
- j--;
- }
- if (j != 0) {
- out.println("500 '" + arg + "':" +
- " command not understood.");
- continue;
- }
- try {
- host = new StringBuffer(arg.substring(0, i));
- for (j = 0; j < host.length(); j++)
- if (host.charAt(j) == ',')
- host.setCharAt(j, '.');
- String ports = arg.substring(i+1);
- i = ports.indexOf(',');
- data_port = Integer.parseInt(
- ports.substring(0, i)) << 8;
- data_port += (Integer.parseInt(
- ports.substring(i+1)));
- data_addr = InetAddress.getByName(
- host.toString());
- out.println("200 Command okay.");
- } catch (Exception ex3) {
- data_port = 0;
- data_addr = null;
- out.println("500 '" + arg + "':" +
- " command not understood.");
- }
- break;
- case RETR:
- {
- File file = new File(arg);
- if (!file.exists()) {
- System.out.println("File not found");
- out.println("200 Command okay.");
- out.println("550 '" + arg +
- "' No such file or directory.");
- break;
- }
- FileInputStream fin = new FileInputStream(file);
- OutputStream dout = getOutDataStream();
- if (dout != null) {
- out.println("150 Binary data connection" +
- " for " + arg +
- " (" + client.getInetAddress().
- getHostAddress() + ") (" +
- file.length() + " bytes).");
- int c;
- int len = 0;
- while ((c = fin.read()) != -1) {
- dout.write(c);
- len++;
- }
- dout.flush();
- dout.close();
- fin.close();
- out.println("226 Binary Transfer complete.");
- } else {
- out.println("425 Can't build data" +
- " connection: Connection refused.");
- }
- }
- break;
- }
- } catch (IOException ioe) {
- ioe.printStackTrace();
- try {
- out.close();
- } catch (Exception ex2) {
- }
- done = true;
- }
- }
- }
- }
-
- public FtpServer(int port) {
- this.port = port;
- }
-
- public FtpServer() {
- this(21);
- }
-
- public int getPort() {
- if (server != null)
- return server.getLocalPort();
- return 0;
- }
-
- /**
- * A way to tell the server that it can stop.
- */
- synchronized public void terminate() {
- done = true;
- }
-
-
- /*
- * All we got to do here is create a ServerSocket and wait for a
- * connection. When a connection happens, we just have to create
- * a thread that will handle it.
- */
- public void run() {
- try {
- server = new ServerSocket(port);
- Socket client;
- client = server.accept();
- (new FtpServerHandler(client)).start();
- server.close();
- } catch (Exception e) {
- }
- }
- }
-
- public static void main(String[] args) throws Exception {
- MarkResetTest test = new MarkResetTest();
- }
-
- public MarkResetTest() {
- FtpServer server = null;
- try {
- server = new FtpServer(0);
- server.start();
- int port = 0;
- while (port == 0) {
- Thread.sleep(500);
- port = server.getPort();
- }
-
- String filename = "EncDec.doc";
- URL url = new URL("ftp://localhost:" + port + "/" +
- filename);
-
- URLConnection con = url.openConnection();
- System.out.println("getContent: " + con.getContent());
- System.out.println("getContent-length: " + con.getContentLength());
-
- InputStream is = con.getInputStream();
-
- /**
- * guessContentTypeFromStream method calls mark and reset methods
- * on the given stream. Make sure that calling
- * guessContentTypeFromStream repeatedly does not affect
- * reading from the stream afterwards
- */
- System.out.println("Call GuessContentTypeFromStream()" +
- " several times..");
- for (int i = 0; i < 5; i++) {
- System.out.println((i + 1) + " mime-type: " +
- con.guessContentTypeFromStream(is));
- }
-
- int len = 0;
- int c;
- while ((c = is.read()) != -1) {
- len++;
- }
- is.close();
- System.out.println("read: " + len + " bytes of the file");
-
- // We're done!
- server.terminate();
- server.interrupt();
-
- // Did we pass ?
- if (len != (new File(filename)).length()) {
- throw new Exception("Failed to read the file correctly");
- }
- System.out.println("PASSED: File read correctly");
- } catch (Exception e) {
- e.printStackTrace();
- try {
- server.terminate();
- server.interrupt();
- } catch (Exception ex) {
- }
- throw new RuntimeException("FTP support error: " + e.getMessage());
- }
- }
-}
--- a/jdk/test/sun/net/www/MarkResetTest.sh Fri Feb 01 22:18:18 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-#
-# Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-# @test
-# @bug 4673103
-# @run shell/timeout=140 MarkResetTest.sh
-# @summary URLConnection.getContent() hangs over FTP for DOC, PPT, XLS files
-
-OS=`uname -s`
-case "$OS" in
- SunOS | Linux | Darwin )
- PS=":"
- FS="/"
- ;;
- CYGWIN* )
- PS=";"
- FS="/"
- ;;
- Windows* )
- PS=";"
- FS="\\"
- ;;
- * )
- echo "Unrecognized system!"
- exit 1;
- ;;
-esac
-
-${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . ${TESTSRC}${FS}MarkResetTest.java
-
-# ftp server used by the test requires the file to be present
-# in this directory
-cp ${TESTSRC}${FS}EncDec.doc .
-
-${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} MarkResetTest
--- a/jdk/test/sun/net/www/http/HttpClient/ProxyTest.java Fri Feb 01 22:18:18 2013 -0800
+++ b/jdk/test/sun/net/www/http/HttpClient/ProxyTest.java Sat Feb 02 17:15:13 2013 +0000
@@ -161,8 +161,18 @@
}
}
+ private static boolean hasFtp() {
+ try {
+ return new java.net.URL("ftp://") != null;
+ } catch (java.net.MalformedURLException x) {
+ System.out.println("FTP not supported by this runtime.");
+ return false;
+ }
+ }
+
public static void main(String[] args) throws Exception {
- ProxyTest test = new ProxyTest();
+ if (hasFtp())
+ new ProxyTest();
}
public ProxyTest() throws Exception {