author | mikael |
Fri, 04 Dec 2015 15:08:49 -0800 | |
changeset 35090 | 1f5b6aa795d0 |
parent 10138 | b7572da25d15 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
10138 | 2 |
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @bug 4397096 |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
26 |
* @run main/othervm SetIfModifiedSince |
2 | 27 |
* @summary setIfModifiedSince() of HttpURLConnection sets invalid date of default locale |
28 |
*/ |
|
29 |
||
30 |
import java.net.*; |
|
31 |
import java.io.*; |
|
32 |
import java.util.*; |
|
33 |
||
34 |
public class SetIfModifiedSince { |
|
35 |
||
36 |
static class XServer extends Thread { |
|
37 |
ServerSocket srv; |
|
38 |
Socket s; |
|
39 |
InputStream is; |
|
40 |
OutputStream os; |
|
41 |
||
42 |
XServer (ServerSocket s) { |
|
43 |
srv = s; |
|
44 |
} |
|
45 |
||
46 |
Socket getSocket () { |
|
47 |
return (s); |
|
48 |
} |
|
49 |
||
50 |
public void run() { |
|
51 |
try { |
|
52 |
String x; |
|
53 |
s = srv.accept (); |
|
54 |
is = s.getInputStream (); |
|
55 |
BufferedReader r = new BufferedReader(new InputStreamReader(is)); |
|
56 |
os = s.getOutputStream (); |
|
57 |
while ((x=r.readLine()) != null) { |
|
58 |
String header = "If-Modified-Since: "; |
|
59 |
if (x.startsWith(header)) { |
|
60 |
if (x.charAt(header.length()) == '?') { |
|
61 |
s.close (); |
|
62 |
srv.close (); // or else the HTTPURLConnection will retry |
|
63 |
throw new RuntimeException |
|
64 |
("Invalid HTTP date specification"); |
|
65 |
} |
|
66 |
break; |
|
67 |
} |
|
68 |
} |
|
69 |
s.close (); |
|
70 |
srv.close (); // or else the HTTPURLConnection will retry |
|
71 |
} catch (IOException e) {} |
|
72 |
} |
|
73 |
} |
|
74 |
||
75 |
public static void main (String[] args) { |
|
10138 | 76 |
Locale reservedLocale = Locale.getDefault(); |
2 | 77 |
try { |
78 |
Locale.setDefault(Locale.JAPAN); |
|
79 |
ServerSocket serversocket = new ServerSocket (0); |
|
80 |
int port = serversocket.getLocalPort (); |
|
81 |
XServer server = new XServer (serversocket); |
|
82 |
server.start (); |
|
83 |
Thread.sleep (2000); |
|
84 |
URL url = new URL ("http://localhost:"+port+"/index.html"); |
|
85 |
URLConnection urlc = url.openConnection (); |
|
86 |
urlc.setIfModifiedSince (10000000); |
|
87 |
InputStream is = urlc.getInputStream (); |
|
88 |
int i=0, c; |
|
89 |
Thread.sleep (5000); |
|
90 |
} catch (Exception e) { |
|
10138 | 91 |
} finally { |
92 |
// restore the reserved locale |
|
93 |
Locale.setDefault(reservedLocale); |
|
2 | 94 |
} |
10138 | 95 |
|
2 | 96 |
} |
97 |
} |