提交 e60ddf8b 编写于 作者: K khazra

7152856: TEST_BUG: sun/net/www/protocol/jar/B4957695.java failing on Windows

Summary: Remove usage of HTTP Server at test/sun/net/www/httptest
Reviewed-by: chegar, alanb
上级 4840e2eb
/* /*
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
/** /**
* @test * @test
* @bug 4957695 * @bug 4957695
* @library ../../httptest/
* @build HttpCallback HttpServer ClosedChannelList HttpTransaction AbstractCallback
* @summary URLJarFile.retrieve does not delete tmpFile on IOException * @summary URLJarFile.retrieve does not delete tmpFile on IOException
*/ */
...@@ -34,43 +32,72 @@ import java.net.*; ...@@ -34,43 +32,72 @@ import java.net.*;
public class B4957695 { public class B4957695 {
static int count = 0; static Server server;
static boolean error = false;
static void read (InputStream is) throws IOException { static class Server extends Thread {
int c,len=0; final ServerSocket srv;
while ((c=is.read()) != -1) { static final byte[] requestEnd = new byte[] {'\r', '\n', '\r', '\n'};
len += c;
Server(ServerSocket s) {
srv = s;
} }
System.out.println ("read " + len + " bytes");
}
static class CallBack extends AbstractCallback { void readOneRequest(InputStream is) throws IOException {
int requestEndCount = 0, r;
while ((r = is.read()) != -1) {
if (r == requestEnd[requestEndCount]) {
requestEndCount++;
if (requestEndCount == 4) {
break;
}
} else {
requestEndCount = 0;
}
}
}
public void run() {
try (Socket s = srv.accept()) {
// read HTTP request from client
readOneRequest(s.getInputStream());
try (OutputStreamWriter ow =
new OutputStreamWriter((s.getOutputStream()))) {
FileInputStream fin = new FileInputStream("foo1.jar");
int length = fin.available();
byte[] b = new byte[length-10];
fin.read(b, 0, length-10);
ow.write("HTTP/1.0 200 OK\r\n");
// Note: The client expects length bytes.
ow.write("Content-Length: " + length + "\r\n");
ow.write("Content-Type: text/html\r\n");
ow.write("\r\n");
public void request (HttpTransaction req, int count) { // Note: The (buggy) server only sends length-10 bytes.
try { ow.write(new String(b));
System.out.println ("Request received"); ow.flush();
req.setResponseEntityBody (new FileInputStream ("foo1.jar")); }
System.out.println ("content length " + req.getResponseHeader (
"Content-length"
));
req.sendPartialResponse (200, "Ok");
req.abortiveClose();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
}; static void read (InputStream is) throws IOException {
int c,len=0;
static HttpServer server; while ((c=is.read()) != -1) {
len += c;
}
System.out.println ("read " + len + " bytes");
}
public static void main (String[] args) throws Exception { public static void main (String[] args) throws Exception {
String tmpdir = System.getProperty("java.io.tmpdir"); String tmpdir = System.getProperty("java.io.tmpdir");
String[] list1 = listTmpFiles(tmpdir); String[] list1 = listTmpFiles(tmpdir);
//server = new HttpServer (new CallBack(), 10, 1, 0); ServerSocket serverSocket = new ServerSocket(0);
server = new HttpServer (new CallBack(), 1, 5, 0); server = new Server(serverSocket);
int port = server.getLocalPort(); server.start();
int port = serverSocket.getLocalPort();
System.out.println ("Server: listening on port: " + port); System.out.println ("Server: listening on port: " + port);
URL url = new URL ("jar:http://localhost:"+port+"!/COPYRIGHT"); URL url = new URL ("jar:http://localhost:"+port+"!/COPYRIGHT");
try { try {
...@@ -81,14 +108,12 @@ public class B4957695 { ...@@ -81,14 +108,12 @@ public class B4957695 {
} catch (IOException e) { } catch (IOException e) {
System.out.println ("Received IOException as expected"); System.out.println ("Received IOException as expected");
} }
server.terminate();
String[] list2 = listTmpFiles(tmpdir); String[] list2 = listTmpFiles(tmpdir);
if (!sameList (list1, list2)) { if (!sameList (list1, list2)) {
throw new RuntimeException ("some jar_cache files left behind"); throw new RuntimeException ("some jar_cache files left behind");
} }
} }
static String[] listTmpFiles (String d) { static String[] listTmpFiles (String d) {
File dir = new File (d); File dir = new File (d);
return dir.list (new FilenameFilter () { return dir.list (new FilenameFilter () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册