duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2000-2002 Sun Microsystems, Inc. All Rights Reserved. |
| 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 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* @test |
| 25 | * @bug 4397096 |
| 26 | * @run main SetIfModifiedSince |
| 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) { |
| 76 | try { |
| 77 | Locale.setDefault(Locale.JAPAN); |
| 78 | ServerSocket serversocket = new ServerSocket (0); |
| 79 | int port = serversocket.getLocalPort (); |
| 80 | XServer server = new XServer (serversocket); |
| 81 | server.start (); |
| 82 | Thread.sleep (2000); |
| 83 | URL url = new URL ("http://localhost:"+port+"/index.html"); |
| 84 | URLConnection urlc = url.openConnection (); |
| 85 | urlc.setIfModifiedSince (10000000); |
| 86 | InputStream is = urlc.getInputStream (); |
| 87 | int i=0, c; |
| 88 | Thread.sleep (5000); |
| 89 | } catch (Exception e) { |
| 90 | } |
| 91 | } |
| 92 | } |