Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/URLConnection/SetIfModifiedSince.java
38811 views
/*1* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 439709625* @run main/othervm SetIfModifiedSince26* @summary setIfModifiedSince() of HttpURLConnection sets invalid date of default locale27*/2829import java.net.*;30import java.io.*;31import java.util.*;3233public class SetIfModifiedSince {3435static class XServer extends Thread {36ServerSocket srv;37Socket s;38InputStream is;39OutputStream os;4041XServer (ServerSocket s) {42srv = s;43}4445Socket getSocket () {46return (s);47}4849public void run() {50try {51String x;52s = srv.accept ();53is = s.getInputStream ();54BufferedReader r = new BufferedReader(new InputStreamReader(is));55os = s.getOutputStream ();56while ((x=r.readLine()) != null) {57String header = "If-Modified-Since: ";58if (x.startsWith(header)) {59if (x.charAt(header.length()) == '?') {60s.close ();61srv.close (); // or else the HTTPURLConnection will retry62throw new RuntimeException63("Invalid HTTP date specification");64}65break;66}67}68s.close ();69srv.close (); // or else the HTTPURLConnection will retry70} catch (IOException e) {}71}72}7374public static void main (String[] args) {75Locale reservedLocale = Locale.getDefault();76try {77Locale.setDefault(Locale.JAPAN);78ServerSocket serversocket = new ServerSocket (0);79int port = serversocket.getLocalPort ();80XServer server = new XServer (serversocket);81server.start ();82Thread.sleep (2000);83URL url = new URL ("http://localhost:"+port+"/index.html");84URLConnection urlc = url.openConnection ();85urlc.setIfModifiedSince (10000000);86InputStream is = urlc.getInputStream ();87int i=0, c;88Thread.sleep (5000);89} catch (Exception e) {90} finally {91// restore the reserved locale92Locale.setDefault(reservedLocale);93}9495}96}979899