6969395: TEST_BUG: Tests in java/net sun/net problems
Reviewed-by: alanb
This commit is contained in:
parent
882b752caf
commit
2890d62dbb
@ -369,139 +369,6 @@ javax/print/attribute/MediaMappingsTest.java generic-all
|
||||
|
||||
# jdk_net
|
||||
|
||||
# Suspect many of these tests auffer from using fixed ports, no concrete
|
||||
# evidence.
|
||||
|
||||
# Times out on Windows X64
|
||||
sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java generic-all
|
||||
|
||||
# Dies on Solaris 10 sparc and sparcv9, Linux -ea -esa with
|
||||
# Interrupted or IO exception, maybe writing to non-unique named file?
|
||||
com/sun/net/httpserver/bugs/B6373555.java generic-all
|
||||
|
||||
# Fails on OpenSolaris, times out
|
||||
java/net/MulticastSocket/SetOutgoingIf.java generic-all
|
||||
|
||||
# Timed out on Solaris 10 X86.
|
||||
com/sun/net/httpserver/Test3.java generic-all
|
||||
|
||||
# Exception in test on windows
|
||||
com/sun/net/httpserver/bugs/B6373555.java windows-all
|
||||
|
||||
# One of these pollutes the samevm on Linux, too many open files, kills jtreg
|
||||
com/sun/net/httpserver/bugs/B6339483.java generic-all
|
||||
com/sun/net/httpserver/bugs/B6341616.java generic-all
|
||||
|
||||
# Suspects in cascading samevm problem, solaris 11 i586 (needs othervm?)
|
||||
# Suspect use of setHttps*()?
|
||||
com/sun/net/httpserver/SelCacheTest.java generic-all
|
||||
com/sun/net/httpserver/Test1.java generic-all
|
||||
com/sun/net/httpserver/Test12.java generic-all
|
||||
com/sun/net/httpserver/Test13.java generic-all
|
||||
com/sun/net/httpserver/Test6a.java generic-all
|
||||
com/sun/net/httpserver/Test7a.java generic-all
|
||||
com/sun/net/httpserver/Test8a.java generic-all
|
||||
com/sun/net/httpserver/Test9.java generic-all
|
||||
com/sun/net/httpserver/Test9a.java generic-all
|
||||
|
||||
# 10,000 connections, fails on Linux and makes tests&jtreg fail with samevm
|
||||
com/sun/net/httpserver/bugs/B6361557.java generic-all
|
||||
|
||||
# Address already in use with samevm? Always? Solaris sparc, probably ports
|
||||
java/net/Authenticator/B4933582.sh generic-all
|
||||
java/net/DatagramSocket/SendSize.java generic-all
|
||||
|
||||
# Solaris 11: exception wrong address???
|
||||
java/net/Inet6Address/B6558853.java generic-all
|
||||
|
||||
# Not closing stream on file i6a1, windows samevm problem
|
||||
java/net/Inet6Address/serialize/Serialize.java generic-all
|
||||
|
||||
# Linux x64 fails "network unreachable"?
|
||||
java/net/ipv6tests/TcpTest.java generic-all
|
||||
|
||||
# Linux i586, fails with unexpected output
|
||||
java/net/MulticastSocket/NoLoopbackPackets.java linux-i586
|
||||
|
||||
# Address already in use
|
||||
java/net/DatagramSocket/DatagramTimeout.java generic-all
|
||||
|
||||
# Fails on windows, takes too long and fails
|
||||
# Solaris 10 sparcv9, samevm, java.lang.Exception: Takes too long. Dead lock
|
||||
java/net/Socket/DeadlockTest.java generic-all
|
||||
|
||||
# Linux i586 address already in use or connection error, samevm issues
|
||||
java/net/Socket/AccurateTimeout.java generic-all
|
||||
java/net/Socket/asyncClose/BrokenPipe.java generic-all
|
||||
java/net/Socket/CloseAvailable.java generic-all
|
||||
|
||||
# Linux X64 address already in use, samevm issues
|
||||
java/net/Socket/LingerTest.java generic-all
|
||||
java/net/Socket/LinkLocal.java generic-all
|
||||
java/net/Socket/NullHost.java generic-all
|
||||
java/net/Socket/ProxyCons.java generic-all
|
||||
java/net/Socket/ReadTimeout.java generic-all
|
||||
|
||||
# Linux X64 address already in use, samevm issues
|
||||
java/net/Socket/SetReceiveBufferSize.java generic-all
|
||||
|
||||
# Linux i586 address already in use or connection error, samevm issues
|
||||
java/net/Socket/setReuseAddress/Basic.java generic-all
|
||||
java/net/Socket/setReuseAddress/Restart.java generic-all
|
||||
|
||||
# Linux X64 address already in use, samevm issues
|
||||
java/net/Socket/SetSoLinger.java generic-all
|
||||
|
||||
# Address already in use, windows samevm
|
||||
java/net/Socket/Timeout.java generic-all
|
||||
|
||||
# Linux X64 address already in use, samevm issues
|
||||
java/net/Socket/ShutdownBoth.java generic-all
|
||||
java/net/Socket/SoTimeout.java generic-all
|
||||
java/net/Socket/TestClose.java generic-all
|
||||
java/net/Socket/UrgentDataTest.java generic-all
|
||||
java/net/SocketInputStream/SocketClosedException.java generic-all
|
||||
java/net/SocketInputStream/SocketTimeout.java generic-all
|
||||
|
||||
# Linux i586, address already in use or timeout, samevm issues
|
||||
java/net/URLConnection/DisconnectAfterEOF.java generic-all
|
||||
java/net/URLConnection/HandleContentTypeWithAttrs.java generic-all
|
||||
java/net/URLConnection/Responses.java generic-all
|
||||
java/net/URLConnection/TimeoutTest.java generic-all
|
||||
java/net/URLConnection/ZeroContentLength.java generic-all
|
||||
|
||||
# Solaris 11 i586 fails with samevm, not sure why
|
||||
java/net/ResponseCache/B6181108.java generic-all
|
||||
java/net/ResponseCache/ResponseCacheTest.java generic-all
|
||||
java/net/URL/GetContent.java generic-all
|
||||
java/net/URLConnection/HttpContinueStackOverflow.java generic-all
|
||||
java/net/URLConnection/Redirect307Test.java generic-all
|
||||
java/net/URLConnection/RedirectLimit.java generic-all
|
||||
java/net/URLConnection/ResendPostBody.java generic-all
|
||||
java/net/URL/OpenStream.java generic-all
|
||||
java/net/URLClassLoader/ClassLoad.java generic-all
|
||||
java/net/URLConnection/SetIfModifiedSince.java generic-all
|
||||
java/net/URLConnection/URLConnectionHeaders.java generic-all
|
||||
|
||||
# Linux i586 Connection refused or address already in use, samevm issues
|
||||
sun/net/ftp/B6427768.java generic-all
|
||||
sun/net/ftp/FtpGetContent.java generic-all
|
||||
sun/net/ftp/FtpURL.java generic-all
|
||||
|
||||
# Failed on solaris 10 i586, Exception: should have gotten HttpRetryException?
|
||||
sun/net/www/http/ChunkedOutputStream/Test.java generic-all
|
||||
|
||||
# Trouble cleaning up threads in samevm mode on solaris 11 i586
|
||||
sun/net/www/http/HttpClient/ProxyTest.java generic-all
|
||||
sun/net/www/http/ChunkedInputStream/ChunkedEncodingTest.java generic-all
|
||||
sun/net/www/http/ChunkedInputStream/ChunkedEncodingWithProgressMonitorTest.java generic-all
|
||||
sun/net/www/http/HttpClient/B6726695.java generic-all
|
||||
sun/net/www/http/HttpClient/MultiThreadTest.java generic-all
|
||||
sun/net/www/http/KeepAliveCache/KeepAliveTimerThread.java generic-all
|
||||
|
||||
# Connection refused, windows samevm
|
||||
sun/net/www/protocol/http/DigestTest.java generic-all
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_io
|
||||
|
@ -24,17 +24,15 @@
|
||||
/**
|
||||
* @test
|
||||
* @bug 6270015
|
||||
* @run main/othervm Test1
|
||||
* @summary Light weight HTTP server
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.security.cert.*;
|
||||
import javax.net.ssl.*;
|
||||
|
||||
/* basic http/s connectivity test
|
||||
|
@ -28,7 +28,6 @@
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.io.*;
|
||||
import com.sun.net.httpserver.*;
|
||||
@ -52,22 +51,25 @@ public class Test11 {
|
||||
|
||||
public static void main (String[] args) throws Exception {
|
||||
System.out.print ("Test 11: ");
|
||||
HttpServer server = HttpServer.create (new InetSocketAddress(0), 0);
|
||||
HttpContext ctx = server.createContext (
|
||||
"/foo/bar/", new Handler ()
|
||||
);
|
||||
ExecutorService s = Executors.newCachedThreadPool();
|
||||
server.setExecutor (s);
|
||||
server.start ();
|
||||
URL url = new URL ("http://localhost:" + server.getAddress().getPort()+
|
||||
"/Foo/bar/test.html");
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
|
||||
int r = urlc.getResponseCode();
|
||||
System.out.println ("OK");
|
||||
s.shutdown();
|
||||
server.stop(5);
|
||||
if (r == 200) {
|
||||
throw new RuntimeException ("wrong response received");
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
|
||||
ExecutorService s = Executors.newCachedThreadPool();
|
||||
try {
|
||||
HttpContext ctx = server.createContext (
|
||||
"/foo/bar/", new Handler ()
|
||||
);
|
||||
s = Executors.newCachedThreadPool();
|
||||
server.start ();
|
||||
URL url = new URL ("http://localhost:" + server.getAddress().getPort()+
|
||||
"/Foo/bar/test.html");
|
||||
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
|
||||
int r = urlc.getResponseCode();
|
||||
if (r == 200) {
|
||||
throw new RuntimeException ("wrong response received");
|
||||
}
|
||||
System.out.println ("OK");
|
||||
} finally {
|
||||
s.shutdown();
|
||||
server.stop(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,17 +24,15 @@
|
||||
/**
|
||||
* @test
|
||||
* @bug 6270015
|
||||
* @run main/othervm Test12
|
||||
* @summary Light weight HTTP server
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.security.cert.*;
|
||||
import javax.net.ssl.*;
|
||||
|
||||
/* basic http/s connectivity test
|
||||
|
@ -24,17 +24,16 @@
|
||||
/**
|
||||
* @test
|
||||
* @bug 6270015
|
||||
* @run main/othervm Test13
|
||||
* @summary Light weight HTTP server
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.security.cert.*;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
|
||||
/* basic http/s connectivity test
|
||||
|
@ -24,17 +24,15 @@
|
||||
/**
|
||||
* @test
|
||||
* @bug 6270015
|
||||
* @run main/othervm Test6a
|
||||
* @summary Light weight HTTP server
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import javax.security.auth.callback.*;
|
||||
import javax.net.ssl.*;
|
||||
|
||||
/**
|
||||
|
@ -24,18 +24,15 @@
|
||||
/**
|
||||
* @test
|
||||
* @bug 6270015
|
||||
* @run main/othervm Test7a
|
||||
* @summary Light weight HTTP server
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.logging.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import javax.security.auth.callback.*;
|
||||
import javax.net.ssl.*;
|
||||
|
||||
/**
|
||||
|
@ -24,18 +24,15 @@
|
||||
/**
|
||||
* @test
|
||||
* @bug 6270015
|
||||
* @run main/othervm Test8a
|
||||
* @summary Light weight HTTP server
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.logging.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import javax.security.auth.callback.*;
|
||||
import javax.net.ssl.*;
|
||||
|
||||
/**
|
||||
@ -50,46 +47,50 @@ public class Test8a extends Test {
|
||||
//h.setLevel (Level.INFO);
|
||||
//log.addHandler (h);
|
||||
//log.setLevel (Level.INFO);
|
||||
Handler handler = new Handler();
|
||||
InetSocketAddress addr = new InetSocketAddress (0);
|
||||
HttpsServer server = HttpsServer.create (addr, 0);
|
||||
HttpContext ctx = server.createContext ("/test", handler);
|
||||
ExecutorService executor = Executors.newCachedThreadPool();
|
||||
SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();
|
||||
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
|
||||
server.setExecutor (executor);
|
||||
server.start ();
|
||||
HttpsServer server = null;
|
||||
ExecutorService executor = null;
|
||||
try {
|
||||
Handler handler = new Handler();
|
||||
InetSocketAddress addr = new InetSocketAddress (0);
|
||||
server = HttpsServer.create (addr, 0);
|
||||
HttpContext ctx = server.createContext ("/test", handler);
|
||||
executor = Executors.newCachedThreadPool();
|
||||
SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();
|
||||
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
|
||||
server.setExecutor (executor);
|
||||
server.start ();
|
||||
|
||||
URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
|
||||
System.out.print ("Test8a: " );
|
||||
HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
|
||||
urlc.setDoOutput (true);
|
||||
urlc.setRequestMethod ("POST");
|
||||
urlc.setHostnameVerifier (new DummyVerifier());
|
||||
urlc.setSSLSocketFactory (ssl.getSocketFactory());
|
||||
OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000);
|
||||
for (int i=0; i<SIZE; i++) {
|
||||
os.write (i % 250);
|
||||
}
|
||||
os.close();
|
||||
int resp = urlc.getResponseCode();
|
||||
if (resp != 200) {
|
||||
throw new RuntimeException ("test failed response code");
|
||||
}
|
||||
InputStream is = urlc.getInputStream ();
|
||||
for (int i=0; i<SIZE; i++) {
|
||||
int f = is.read();
|
||||
if (f != (i % 250)) {
|
||||
System.out.println ("Setting error(" +f +")("+i+")" );
|
||||
error = true;
|
||||
break;
|
||||
URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
|
||||
System.out.print ("Test8a: " );
|
||||
HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
|
||||
urlc.setDoOutput (true);
|
||||
urlc.setRequestMethod ("POST");
|
||||
urlc.setHostnameVerifier (new DummyVerifier());
|
||||
urlc.setSSLSocketFactory (ssl.getSocketFactory());
|
||||
OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000);
|
||||
for (int i=0; i<SIZE; i++) {
|
||||
os.write (i % 250);
|
||||
}
|
||||
os.close();
|
||||
int resp = urlc.getResponseCode();
|
||||
if (resp != 200) {
|
||||
throw new RuntimeException ("test failed response code");
|
||||
}
|
||||
InputStream is = urlc.getInputStream ();
|
||||
for (int i=0; i<SIZE; i++) {
|
||||
int f = is.read();
|
||||
if (f != (i % 250)) {
|
||||
System.out.println ("Setting error(" +f +")("+i+")" );
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
is.close();
|
||||
} finally {
|
||||
delay();
|
||||
if (server != null) server.stop(2);
|
||||
if (executor != null) executor.shutdown();
|
||||
}
|
||||
is.close();
|
||||
|
||||
delay();
|
||||
server.stop(2);
|
||||
executor.shutdown();
|
||||
if (error) {
|
||||
throw new RuntimeException ("test failed error");
|
||||
}
|
||||
|
@ -24,17 +24,15 @@
|
||||
/**
|
||||
* @test
|
||||
* @bug 6270015
|
||||
* @run main/othervm Test9
|
||||
* @summary Light weight HTTP server
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.security.cert.*;
|
||||
import javax.net.ssl.*;
|
||||
|
||||
/* Same as Test1 but requests run in parallel.
|
||||
|
@ -24,17 +24,15 @@
|
||||
/**
|
||||
* @test
|
||||
* @bug 6270015
|
||||
* @run main/othervm Test9a
|
||||
* @summary Light weight HTTP server
|
||||
*/
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.security.cert.*;
|
||||
import javax.net.ssl.*;
|
||||
|
||||
/* Same as Test1 but requests run in parallel.
|
||||
|
@ -35,12 +35,9 @@ import java.io.*;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.security.cert.*;
|
||||
import javax.net.ssl.*;
|
||||
|
||||
/**
|
||||
* The test simply opens 10,000 separate connections
|
||||
* The test simply opens 1,000 separate connections
|
||||
* and invokes one http request on each. The client does
|
||||
* not close any sockets until after they are closed
|
||||
* by the server. This verifies the basic ability
|
||||
@ -49,6 +46,7 @@ import javax.net.ssl.*;
|
||||
public class B6361557 {
|
||||
|
||||
public static boolean error = false;
|
||||
static final int NUM = 1000;
|
||||
|
||||
static class Handler implements HttpHandler {
|
||||
int invocation = 1;
|
||||
@ -75,7 +73,6 @@ public class B6361557 {
|
||||
server.setExecutor (executor);
|
||||
server.start ();
|
||||
|
||||
final int NUM = 10000;
|
||||
ByteBuffer buf = ByteBuffer.allocate (4096);
|
||||
InetSocketAddress destaddr = new InetSocketAddress (
|
||||
"127.0.0.1", server.getAddress().getPort()
|
||||
|
@ -46,7 +46,7 @@ public class B6373555 {
|
||||
private static Object lock;
|
||||
static HttpServer httpServer;
|
||||
static ExecutorService pool, execs;
|
||||
static int NUM = 4000;
|
||||
static int NUM = 1000;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
@ -125,7 +125,7 @@ public class B6373555 {
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
//e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
System.out.print (".");
|
||||
error = true;
|
||||
}
|
||||
|
@ -27,25 +27,25 @@
|
||||
* @summary test to see if timeout hangs
|
||||
* @run main/timeout=15 DatagramTimeout
|
||||
*/
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
public class DatagramTimeout {
|
||||
|
||||
public static ServerSocket sock;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
boolean success = false;
|
||||
DatagramSocket sock = new DatagramSocket();
|
||||
|
||||
try {
|
||||
DatagramSocket sock;
|
||||
DatagramPacket p;
|
||||
byte[] buffer = new byte[50];
|
||||
p = new DatagramPacket(buffer, buffer.length);
|
||||
sock = new DatagramSocket(2333);
|
||||
sock.setSoTimeout(2);
|
||||
sock.receive(p);
|
||||
} catch (SocketTimeoutException e) {
|
||||
success = true;
|
||||
} finally {
|
||||
sock.close();
|
||||
}
|
||||
if (!success)
|
||||
throw new RuntimeException("Socket timeout failure.");
|
||||
|
@ -32,35 +32,26 @@
|
||||
* @author Benjamin Renaud
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class SendSize {
|
||||
|
||||
static final int clientPort = 8989;
|
||||
static final int serverPort = 9999;
|
||||
static final int bufferLength = 512;
|
||||
static final int packetLength = 256;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new ServerThread().start();
|
||||
new ClientThread().start();
|
||||
DatagramSocket serverSocket = new DatagramSocket();
|
||||
new ServerThread(serverSocket).start();
|
||||
new ClientThread(serverSocket.getLocalPort()).start();
|
||||
}
|
||||
|
||||
|
||||
static class ServerThread extends Thread {
|
||||
|
||||
int port;
|
||||
DatagramSocket server;
|
||||
|
||||
ServerThread(int port) throws IOException {
|
||||
this.port = port;
|
||||
this.server = new DatagramSocket(port);
|
||||
}
|
||||
|
||||
ServerThread() throws IOException {
|
||||
this(SendSize.serverPort);
|
||||
ServerThread(DatagramSocket server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@ -85,33 +76,22 @@ public class SendSize {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("caugth: " + e);
|
||||
} finally {
|
||||
if (server != null) { server.close(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class ClientThread extends Thread {
|
||||
|
||||
int port;
|
||||
int serverPort;
|
||||
int bufferLength;
|
||||
int packetLength;
|
||||
|
||||
DatagramSocket client;
|
||||
InetAddress host;
|
||||
|
||||
ClientThread(int port, int serverPort,
|
||||
int bufferLength, int packetLength) throws IOException {
|
||||
this.port = port;
|
||||
ClientThread(int serverPort)throws IOException {
|
||||
this.serverPort = serverPort;
|
||||
this.host = InetAddress.getLocalHost();
|
||||
this.bufferLength = bufferLength;
|
||||
this.packetLength = packetLength;
|
||||
this.client = new DatagramSocket(port, host);
|
||||
}
|
||||
|
||||
ClientThread() throws IOException {
|
||||
this(SendSize.clientPort, SendSize.serverPort,
|
||||
SendSize.bufferLength, SendSize.packetLength);
|
||||
this.client = new DatagramSocket();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@ -129,6 +109,8 @@ public class SendSize {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("caught: " + e);
|
||||
} finally {
|
||||
if (client != null) { client.close(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,9 @@ public class B6558853 implements Runnable {
|
||||
InetAddress dest = null;
|
||||
while (l.hasMoreElements() && dest == null) {
|
||||
NetworkInterface nif = l.nextElement();
|
||||
if (!nif.isUp())
|
||||
continue;
|
||||
|
||||
for (InterfaceAddress a : nif.getInterfaceAddresses()) {
|
||||
if (a.getAddress() instanceof Inet6Address) {
|
||||
Inet6Address a6 = (Inet6Address) a.getAddress();
|
||||
@ -53,6 +56,7 @@ public class B6558853 implements Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("Using " + dest);
|
||||
if (dest != null) {
|
||||
B6558853 test = new B6558853(dest, port);
|
||||
Thread thread = new Thread(test);
|
||||
|
@ -72,6 +72,7 @@ public class Serialize {
|
||||
File file = new File (System.getProperty("test.src"), "serial1.4.2.ser");
|
||||
ois = new ObjectInputStream(new FileInputStream(file));
|
||||
nobj = (Inet6Address) ois.readObject();
|
||||
ois.close();
|
||||
if (!nobj.equals (InetAddress.getByName ("::1"))) {
|
||||
throw new RuntimeException ("old ::1 not deserialized right");
|
||||
}
|
||||
@ -90,6 +91,8 @@ public class Serialize {
|
||||
nobj = (Inet6Address) ois.readObject();
|
||||
} catch (NullPointerException e) {
|
||||
throw new RuntimeException("6656849 Not fixed: NullPointer when deserializing");
|
||||
} finally {
|
||||
ois.close();
|
||||
}
|
||||
System.out.println(nobj);
|
||||
System.out.println("All tests passed");
|
||||
@ -102,6 +105,7 @@ public class Serialize {
|
||||
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("i6a1.ser"));
|
||||
Inet6Address nobj = (Inet6Address) ois.readObject();
|
||||
ois.close();
|
||||
|
||||
if (nobj.equals(obj)) {
|
||||
return true;
|
||||
|
@ -56,6 +56,8 @@ public class CheckJNI {
|
||||
|
||||
while (ifs.hasMoreElements()) {
|
||||
NetworkInterface nif = (NetworkInterface)ifs.nextElement();
|
||||
if (!nif.isUp())
|
||||
continue;
|
||||
Enumeration addrs = nif.getInetAddresses();
|
||||
while (addrs.hasMoreElements()) {
|
||||
InetAddress addr = (InetAddress) addrs.nextElement();
|
||||
|
@ -76,6 +76,10 @@ public class SetOutgoingIf {
|
||||
|
||||
// now determine what (if any) type of addresses are assigned to this interface
|
||||
for (InetAddress addr : Collections.list(nic.getInetAddresses())) {
|
||||
if (addr.isAnyLocalAddress())
|
||||
continue;
|
||||
|
||||
System.out.println(" addr " + addr);
|
||||
if (addr instanceof Inet4Address) {
|
||||
netIf.ipv4Address(true);
|
||||
} else if (addr instanceof Inet6Address) {
|
||||
|
@ -67,9 +67,10 @@ public class B6181108 implements Runnable {
|
||||
out.flush();
|
||||
|
||||
s.close();
|
||||
ss.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { ss.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,6 +101,7 @@ public class B6181108 implements Runnable {
|
||||
URLConnection urlc = url.openConnection();
|
||||
int i = ((HttpURLConnection)(urlc)).getResponseCode();
|
||||
System.out.println ("response code = " + i);
|
||||
ResponseCache.setDefault(null);
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
|
@ -30,7 +30,6 @@
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
import sun.net.www.ParseUtil;
|
||||
import javax.net.ssl.*;
|
||||
|
||||
@ -43,11 +42,16 @@ public class ResponseCacheTest implements Runnable {
|
||||
static URL url1;
|
||||
static URL url2;
|
||||
static String FNPrefix, OutFNPrefix;
|
||||
static List<Closeable> streams = new ArrayList<>();
|
||||
static List<File> files = new ArrayList<>();
|
||||
|
||||
/*
|
||||
* Our "http" server to return a 404 */
|
||||
public void run() {
|
||||
Socket s = null;
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
Socket s = ss.accept();
|
||||
s = ss.accept();
|
||||
|
||||
InputStream is = s.getInputStream ();
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(is));
|
||||
@ -68,7 +72,7 @@ public class ResponseCacheTest implements Runnable {
|
||||
out.print("Content-Length: "+file2.length()+"\r\n");
|
||||
out.print("Connection: close\r\n");
|
||||
out.print("\r\n");
|
||||
FileInputStream fis = new FileInputStream(file2);
|
||||
fis = new FileInputStream(file2);
|
||||
byte[] buf = new byte[(int)file2.length()];
|
||||
int len;
|
||||
while ((len = fis.read(buf)) != -1) {
|
||||
@ -81,6 +85,10 @@ public class ResponseCacheTest implements Runnable {
|
||||
ss.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { ss.close(); } catch (IOException unused) {}
|
||||
try { s.close(); } catch (IOException unused) {}
|
||||
try { fis.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
static class NameVerifier implements HostnameVerifier {
|
||||
@ -144,11 +152,14 @@ static class NameVerifier implements HostnameVerifier {
|
||||
// assert (headers1 == headers2 && file1 == file2.2)
|
||||
File file1 = new File(OutFNPrefix+"file1");
|
||||
File file2 = new File(OutFNPrefix+"file2.2");
|
||||
files.add(file1);
|
||||
files.add(file2);
|
||||
System.out.println("headers1"+headers1+"\nheaders2="+headers2);
|
||||
if (!headers1.equals(headers2) || file1.length() != file2.length()) {
|
||||
throw new RuntimeException("test failed");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
try {
|
||||
ResponseCache.setDefault(new MyResponseCache());
|
||||
@ -157,6 +168,12 @@ static class NameVerifier implements HostnameVerifier {
|
||||
new ResponseCacheTest();
|
||||
} finally{
|
||||
ResponseCache.setDefault(null);
|
||||
for (Closeable c: streams) {
|
||||
try { c.close(); } catch (IOException unused) {}
|
||||
}
|
||||
for (File f: files) {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,6 +201,7 @@ static class NameVerifier implements HostnameVerifier {
|
||||
public MyCacheResponse(String filename) {
|
||||
try {
|
||||
fis = new FileInputStream(new File(filename));
|
||||
streams.add(fis);
|
||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
headers = (Map<String,List<String>>)ois.readObject();
|
||||
} catch (Exception ex) {
|
||||
@ -206,6 +224,8 @@ static class NameVerifier implements HostnameVerifier {
|
||||
try {
|
||||
File file = new File(filename);
|
||||
fos = new FileOutputStream(file);
|
||||
streams.add(fos);
|
||||
files.add(file);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(rspHeaders);
|
||||
} catch (Exception ex) {
|
||||
|
@ -39,6 +39,7 @@ import java.io.*;
|
||||
public class getResponseCode {
|
||||
static URL url;
|
||||
static String FNPrefix;
|
||||
static List<Closeable> resources = new ArrayList<>();
|
||||
|
||||
getResponseCode() throws Exception {
|
||||
url = new URL("http://localhost/file1.cache");
|
||||
@ -57,6 +58,9 @@ public class getResponseCode {
|
||||
new getResponseCode();
|
||||
} finally{
|
||||
ResponseCache.setDefault(null);
|
||||
for (Closeable c : resources) {
|
||||
try { c.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,6 +81,7 @@ public class getResponseCode {
|
||||
public MyResponse(String filename) {
|
||||
try {
|
||||
fis = new FileInputStream(new File(filename));
|
||||
resources.add(fis);
|
||||
headers = (Map<String,List<String>>)new ObjectInputStream(fis).readObject();
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex.getMessage());
|
||||
|
@ -1,144 +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.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4512028
|
||||
* @summary Check the tolerance on read timeouts.
|
||||
*/
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
public class AccurateTimeout {
|
||||
|
||||
static final int TOLERANCE = 100;
|
||||
|
||||
static boolean skipTest() {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.equals("Windows 95") ||
|
||||
os.equals("Windows 98") ||
|
||||
os.equals("Windows Me")) {
|
||||
|
||||
System.out.println("Due to an OS bug timeout tolerance cannot be tested on this OS");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
|
||||
if (skipTest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int failures = 0;
|
||||
int timeout;
|
||||
|
||||
System.out.println("");
|
||||
System.out.println("Testing Socket.getInputStream().read() ...");
|
||||
System.out.println("");
|
||||
|
||||
ServerSocket ss = new ServerSocket(0);
|
||||
Socket s1 = new Socket(InetAddress.getLocalHost(), ss.getLocalPort());
|
||||
Socket s2 = ss.accept();
|
||||
|
||||
InputStream in = s1.getInputStream();
|
||||
|
||||
timeout = 100;
|
||||
while (timeout < 2500) {
|
||||
s1.setSoTimeout(timeout);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
in.read();
|
||||
} catch (SocketTimeoutException e) {
|
||||
}
|
||||
long actual = System.currentTimeMillis() - startTime;
|
||||
|
||||
System.out.print("excepted: " + timeout + " actual: " + actual);
|
||||
|
||||
if (Math.abs(actual-timeout) > TOLERANCE) {
|
||||
System.out.print(" *** FAIL: outside tolerance");
|
||||
failures++;
|
||||
} else {
|
||||
System.out.print(" PASS.");
|
||||
}
|
||||
|
||||
System.out.println("");
|
||||
timeout += 200;
|
||||
}
|
||||
|
||||
s1.close();
|
||||
s2.close();
|
||||
ss.close();
|
||||
|
||||
|
||||
// ----------
|
||||
|
||||
|
||||
System.out.println("");
|
||||
System.out.println("Testing DatagramSocket.receive ...");
|
||||
System.out.println("");
|
||||
|
||||
byte b[] = new byte[8];
|
||||
DatagramPacket p = new DatagramPacket(b, b.length);
|
||||
|
||||
DatagramSocket ds = new DatagramSocket();
|
||||
|
||||
timeout = 100;
|
||||
while (timeout < 2500) {
|
||||
ds.setSoTimeout(timeout);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
ds.receive(p);
|
||||
} catch (SocketTimeoutException e) {
|
||||
}
|
||||
long actual = System.currentTimeMillis() - startTime;
|
||||
|
||||
System.out.print("excepted: " + timeout + " actual: " + actual);
|
||||
|
||||
if (Math.abs(actual-timeout) > TOLERANCE) {
|
||||
System.out.print(" *** FAIL: outside tolerance");
|
||||
failures++;
|
||||
} else {
|
||||
System.out.print(" PASS.");
|
||||
}
|
||||
|
||||
System.out.println("");
|
||||
timeout += 200;
|
||||
}
|
||||
|
||||
ds.close();
|
||||
|
||||
System.out.println("");
|
||||
|
||||
// ---------
|
||||
|
||||
if (failures > 0) {
|
||||
throw new Exception("Test failed: " + failures +
|
||||
" test(s) outside tolerance");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -47,6 +47,7 @@ public class CloseAvailable implements Runnable {
|
||||
t.start();
|
||||
|
||||
Socket soc = ss.accept();
|
||||
ss.close();
|
||||
|
||||
DataInputStream is = new DataInputStream(soc.getInputStream());
|
||||
is.close();
|
||||
@ -64,7 +65,7 @@ public class CloseAvailable implements Runnable {
|
||||
public void run() {
|
||||
try {
|
||||
Socket s = new Socket(addr, port);
|
||||
|
||||
s.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -33,29 +33,32 @@ import java.io.*;
|
||||
|
||||
public class DeadlockTest {
|
||||
public static void main(String [] argv) throws Exception {
|
||||
ServerSocket ss = new ServerSocket(0);
|
||||
Socket clientSocket = new Socket();
|
||||
|
||||
// Start the server thread
|
||||
Thread s1 = new Thread(new ServerThread());
|
||||
s1.start();
|
||||
try {
|
||||
// Start the server thread
|
||||
Thread s1 = new Thread(new ServerThread(ss));
|
||||
s1.start();
|
||||
|
||||
// Sleep to make sure s1 has created a server socket
|
||||
Thread.sleep(1000);
|
||||
// Start the client thread
|
||||
ClientThread ct = new ClientThread(clientSocket, ss.getLocalPort());
|
||||
Thread c1 = new Thread(ct);
|
||||
c1.start();
|
||||
|
||||
// Start the client thread
|
||||
ClientThread ct = new ClientThread();
|
||||
Thread c1 = new Thread(ct);
|
||||
c1.start();
|
||||
// Wait for the client thread to finish
|
||||
c1.join(20000);
|
||||
|
||||
// Wait for the client thread to finish
|
||||
c1.join(40000);
|
||||
|
||||
// If timeout, we assume there is a deadlock
|
||||
if (c1.isAlive() == true) {
|
||||
// Close the socket to force the server thread
|
||||
// terminate too
|
||||
s1.stop();
|
||||
ct.getSock().close();
|
||||
throw new Exception("Takes too long. Dead lock");
|
||||
// If timeout, we assume there is a deadlock
|
||||
if (c1.isAlive() == true) {
|
||||
// Close the socket to force the server thread
|
||||
// terminate too
|
||||
s1.stop();
|
||||
throw new Exception("Takes too long. Dead lock");
|
||||
}
|
||||
} finally {
|
||||
ss.close();
|
||||
clientSocket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -71,8 +74,8 @@ class ServerThread implements Runnable {
|
||||
|
||||
Socket sock;
|
||||
|
||||
public ServerThread() throws Exception {
|
||||
|
||||
public ServerThread(ServerSocket serverSocket) throws Exception {
|
||||
this.server = serverSocket;
|
||||
}
|
||||
|
||||
public void ping(int cnt) {
|
||||
@ -85,7 +88,6 @@ class ServerThread implements Runnable {
|
||||
|
||||
try {
|
||||
if (Thread.currentThread().getName().startsWith("child") == false) {
|
||||
server = new ServerSocket(4711);
|
||||
sock = server.accept();
|
||||
|
||||
new Thread(this, "child").start();
|
||||
@ -107,6 +109,7 @@ class ServerThread implements Runnable {
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
System.out.println(e);
|
||||
// If anything goes wrong, just quit.
|
||||
}
|
||||
|
||||
@ -141,10 +144,11 @@ class ClientThread implements Runnable {
|
||||
|
||||
Socket sock;
|
||||
|
||||
public ClientThread() throws Exception {
|
||||
public ClientThread(Socket sock, int serverPort) throws Exception {
|
||||
try {
|
||||
System.out.println("About to create a socket");
|
||||
sock = new Socket(InetAddress.getLocalHost().getHostName(), 4711);
|
||||
System.out.println("About to connect the client socket");
|
||||
this.sock = sock;
|
||||
this.sock.connect(new InetSocketAddress("localhost", serverPort));
|
||||
System.out.println("connected");
|
||||
|
||||
out = new ObjectOutputStream(sock.getOutputStream());
|
||||
@ -156,10 +160,6 @@ class ClientThread implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public Socket getSock() {
|
||||
return sock;
|
||||
}
|
||||
|
||||
private int cnt = 1;
|
||||
|
||||
public void run() {
|
||||
@ -213,6 +213,7 @@ class Message implements java.io.Serializable {
|
||||
System.out.println("write message done " + cnt++);
|
||||
} catch (IOException ioe) {
|
||||
// Ignore the exception
|
||||
System.out.println(ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class LingerTest {
|
||||
public void run() {
|
||||
System.out.println ("Another starts");
|
||||
try {
|
||||
Thread.currentThread().sleep(delay);
|
||||
Thread.sleep(delay);
|
||||
Socket s = new Socket("localhost", port);
|
||||
synchronized (this) {
|
||||
connected = true;
|
||||
@ -105,7 +105,6 @@ public class LingerTest {
|
||||
Socket s1 = new Socket("localhost", ss.getLocalPort());
|
||||
Socket s2 = ss.accept();
|
||||
|
||||
|
||||
// setup conditions for untransmitted data and lengthy
|
||||
// linger interval
|
||||
s1.setSendBufferSize(128*1024);
|
||||
@ -122,14 +121,15 @@ public class LingerTest {
|
||||
thr.start();
|
||||
|
||||
// give sender time to queue the data
|
||||
Thread.currentThread().sleep(1000);
|
||||
Thread.sleep(1000);
|
||||
|
||||
// close the socket asynchronously
|
||||
(new Thread(new Closer(s1))).start();
|
||||
|
||||
// give another time to run
|
||||
Thread.currentThread().sleep(10000);
|
||||
Thread.sleep(10000);
|
||||
|
||||
ss.close();
|
||||
// check that another is done
|
||||
if (!another.connected()) {
|
||||
throw new RuntimeException("Another thread is blocked");
|
||||
|
@ -58,11 +58,10 @@ public class LinkLocal {
|
||||
} catch (SocketException e) {
|
||||
failed++;
|
||||
System.out.println("Test failed: " + e);
|
||||
} finally {
|
||||
s.close();
|
||||
ss.close();
|
||||
}
|
||||
|
||||
// clean up
|
||||
s.close();
|
||||
ss.close();
|
||||
}
|
||||
|
||||
static void UdpTest(InetAddress ia, boolean connected) throws Exception {
|
||||
@ -93,16 +92,16 @@ public class LinkLocal {
|
||||
ds1.send(p);
|
||||
System.out.println("Packet has been sent.");
|
||||
|
||||
ds2.setSoTimeout(1000);
|
||||
ds2.setSoTimeout(5000);
|
||||
ds2.receive(p);
|
||||
System.out.println("Test passed - packet received.");
|
||||
} catch (SocketException e) {
|
||||
failed++;
|
||||
System.out.println("Test failed: " + e);
|
||||
} finally {
|
||||
ds1.close();
|
||||
ds2.close();
|
||||
}
|
||||
|
||||
ds1.close();
|
||||
ds2.close();
|
||||
}
|
||||
|
||||
static void TestAddress(InetAddress ia) throws Exception {
|
||||
@ -138,6 +137,9 @@ public class LinkLocal {
|
||||
Enumeration nifs = NetworkInterface.getNetworkInterfaces();
|
||||
while (nifs.hasMoreElements()) {
|
||||
NetworkInterface ni = (NetworkInterface)nifs.nextElement();
|
||||
if (!ni.isUp())
|
||||
continue;
|
||||
|
||||
Enumeration addrs = ni.getInetAddresses();
|
||||
while (addrs.hasMoreElements()) {
|
||||
InetAddress addr = (InetAddress)addrs.nextElement();
|
||||
|
@ -39,6 +39,7 @@ public class ProxyCons {
|
||||
public void run () {
|
||||
try {
|
||||
Socket s = server.accept ();
|
||||
s.close();
|
||||
while (!finished ()) {
|
||||
Thread.sleep (500);
|
||||
}
|
||||
@ -58,10 +59,9 @@ public class ProxyCons {
|
||||
public ProxyCons() {
|
||||
}
|
||||
|
||||
void test() {
|
||||
void test() throws Exception {
|
||||
ServerSocket ss = new ServerSocket(0);
|
||||
try {
|
||||
ServerSocket ss = new ServerSocket();
|
||||
ss.bind(new InetSocketAddress(0));
|
||||
Server s = new Server(ss);
|
||||
s.start();
|
||||
Socket sock = new Socket(Proxy.NO_PROXY);
|
||||
@ -70,10 +70,12 @@ public class ProxyCons {
|
||||
sock.close();
|
||||
} catch (java.io.IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
ss.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ProxyCons c = new ProxyCons();
|
||||
c.test();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class ReadTimeout {
|
||||
sin = InetAddress.getLocalHost();
|
||||
srv = new ServerSocket(port);
|
||||
port = srv.getLocalPort();
|
||||
soc = new Socket(sin, port, true);
|
||||
soc = new Socket(sin, port);
|
||||
soc1 = srv.accept();
|
||||
soc.setSoTimeout(tout);
|
||||
|
||||
@ -53,10 +53,10 @@ public class ReadTimeout {
|
||||
os = soc1.getOutputStream();
|
||||
is.read();
|
||||
} catch(InterruptedIOException e) {
|
||||
} finally {
|
||||
soc.close();
|
||||
soc1.close();
|
||||
srv.close();
|
||||
}
|
||||
|
||||
soc.close();
|
||||
soc1.close();
|
||||
srv.close();
|
||||
}
|
||||
}
|
||||
|
@ -32,29 +32,14 @@ import java.net.Socket;
|
||||
import java.net.ServerSocket;
|
||||
|
||||
public class SetReceiveBufferSize {
|
||||
class Server extends Thread {
|
||||
private ServerSocket ss;
|
||||
public Server(ServerSocket ss) {
|
||||
this.ss = ss;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
ss.accept();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SetReceiveBufferSize s = new SetReceiveBufferSize();
|
||||
}
|
||||
|
||||
public SetReceiveBufferSize() throws Exception {
|
||||
ServerSocket ss = new ServerSocket(0);
|
||||
Server serv = new Server(ss);
|
||||
serv.start();
|
||||
Socket s = new Socket("localhost", ss.getLocalPort());
|
||||
Socket accepted = ss.accept();
|
||||
try {
|
||||
s.setReceiveBufferSize(0);
|
||||
} catch (IllegalArgumentException e) {
|
||||
@ -62,6 +47,8 @@ public class SetReceiveBufferSize {
|
||||
} catch (Exception ex) {
|
||||
} finally {
|
||||
ss.close();
|
||||
s.close();
|
||||
accepted.close();
|
||||
}
|
||||
throw new RuntimeException("IllegalArgumentException not thrown!");
|
||||
}
|
||||
|
@ -30,36 +30,24 @@
|
||||
|
||||
import java.net.*;
|
||||
|
||||
public class SetSoLinger implements Runnable {
|
||||
static ServerSocket ss;
|
||||
static InetAddress addr;
|
||||
static int port;
|
||||
public class SetSoLinger {
|
||||
static final int LINGER = 65546;
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
boolean error = true;
|
||||
int linger = 65546;
|
||||
int value = 0;
|
||||
addr = InetAddress.getLocalHost();
|
||||
ss = new ServerSocket(0);
|
||||
port = ss.getLocalPort();
|
||||
int value;
|
||||
InetAddress addr = InetAddress.getLocalHost();
|
||||
ServerSocket ss = new ServerSocket(0);
|
||||
int port = ss.getLocalPort();
|
||||
|
||||
Thread t = new Thread(new SetSoLinger());
|
||||
t.start();
|
||||
Socket s = new Socket(addr, port);
|
||||
Socket soc = ss.accept();
|
||||
soc.setSoLinger(true, linger);
|
||||
soc.setSoLinger(true, LINGER);
|
||||
value = soc.getSoLinger();
|
||||
soc.close();
|
||||
s.close();
|
||||
ss.close();
|
||||
|
||||
if(value != 65535)
|
||||
throw new RuntimeException("Failed. Value not properly reduced.");
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Socket s = new Socket(addr, port);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,12 +36,14 @@ public class ShutdownBoth {
|
||||
Socket s1 = new Socket(ss.getInetAddress(), ss.getLocalPort());
|
||||
Socket s2 = ss.accept();
|
||||
|
||||
s1.shutdownInput();
|
||||
s1.shutdownOutput(); // failed b55
|
||||
|
||||
s1.close();
|
||||
s2.close();
|
||||
ss.close();
|
||||
try {
|
||||
s1.shutdownInput();
|
||||
s1.shutdownOutput(); // failed b55
|
||||
} finally {
|
||||
s1.close();
|
||||
s2.close();
|
||||
ss.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,9 +52,10 @@ public class SoTimeout implements Runnable {
|
||||
t.start();
|
||||
|
||||
Socket s = serverSocket.accept();
|
||||
serverSocket.close();
|
||||
|
||||
// set a 1 second timeout on the socket
|
||||
s.setSoTimeout(1000);
|
||||
// set a 5 second timeout on the socket
|
||||
s.setSoTimeout(5000);
|
||||
|
||||
s.getInputStream().read(b, 0, b.length);
|
||||
s.close();
|
||||
@ -64,7 +65,7 @@ public class SoTimeout implements Runnable {
|
||||
// this sequence should complete fairly quickly and if it
|
||||
// takes something resembling the the SoTimeout value then
|
||||
// we are probably incorrectly blocking and not waking up
|
||||
if (waited > 500) {
|
||||
if (waited > 2000) {
|
||||
throw new Exception("shouldn't take " + waited + " to complete");
|
||||
}
|
||||
}
|
||||
|
@ -31,18 +31,16 @@ import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Timeout {
|
||||
|
||||
public static ServerSocket sock;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
boolean success = false;
|
||||
ServerSocket sock = new ServerSocket(0);
|
||||
try {
|
||||
ServerSocket sock;
|
||||
sock = new ServerSocket(2333);
|
||||
sock.setSoTimeout(2);
|
||||
sock.accept();
|
||||
} catch (InterruptedIOException e) {
|
||||
success = true;
|
||||
} finally {
|
||||
sock.close();
|
||||
}
|
||||
if (!success)
|
||||
throw new RuntimeException("Socket timeout failure.");
|
||||
|
@ -90,63 +90,64 @@ public class UrgentDataTest {
|
||||
}
|
||||
|
||||
public void run () throws Exception {
|
||||
if (isClient) {
|
||||
client = new Socket (clHost, clPort);
|
||||
clis = client.getInputStream();
|
||||
clos = client.getOutputStream();
|
||||
client.setOOBInline (true);
|
||||
if (client.getOOBInline() != true) {
|
||||
throw new RuntimeException ("Setting OOBINLINE failed");
|
||||
}
|
||||
}
|
||||
if (isServer) {
|
||||
server = listener.accept ();
|
||||
sis = server.getInputStream();
|
||||
sos = server.getOutputStream();
|
||||
}
|
||||
if (isClient) {
|
||||
clos.write ("Hello".getBytes ());
|
||||
client.sendUrgentData (100);
|
||||
clos.write ("world".getBytes ());
|
||||
}
|
||||
// read Hello world from server (during which oob byte must have been dropped)
|
||||
String s = "Helloworld";
|
||||
if (isServer) {
|
||||
for (int y=0; y<s.length(); y++) {
|
||||
int c = sis.read ();
|
||||
if (c != (int)s.charAt (y)) {
|
||||
throw new RuntimeException ("Unexpected character read");
|
||||
try {
|
||||
if (isClient) {
|
||||
client = new Socket (clHost, clPort);
|
||||
clis = client.getInputStream();
|
||||
clos = client.getOutputStream();
|
||||
client.setOOBInline (true);
|
||||
if (client.getOOBInline() != true) {
|
||||
throw new RuntimeException ("Setting OOBINLINE failed");
|
||||
}
|
||||
}
|
||||
// Do the same from server to client
|
||||
sos.write ("Hello".getBytes ());
|
||||
server.sendUrgentData (101);
|
||||
sos.write ("World".getBytes ());
|
||||
}
|
||||
if (isClient) {
|
||||
// read Hello world from client (during which oob byte must have been read)
|
||||
s="Hello";
|
||||
for (int y=0; y<s.length(); y++) {
|
||||
int c = clis.read ();
|
||||
if (c != (int)s.charAt (y)) {
|
||||
throw new RuntimeException ("Unexpected character read");
|
||||
}
|
||||
}
|
||||
if (clis.read() != 101) {
|
||||
throw new RuntimeException ("OOB byte not received");
|
||||
}
|
||||
s="World";
|
||||
for (int y=0; y<s.length(); y++) {
|
||||
int c = clis.read ();
|
||||
if (c != (int)s.charAt (y)) {
|
||||
throw new RuntimeException ("Unexpected character read");
|
||||
if (isServer) {
|
||||
server = listener.accept ();
|
||||
sis = server.getInputStream();
|
||||
sos = server.getOutputStream();
|
||||
}
|
||||
if (isClient) {
|
||||
clos.write ("Hello".getBytes ());
|
||||
client.sendUrgentData (100);
|
||||
clos.write ("world".getBytes ());
|
||||
}
|
||||
// read Hello world from server (during which oob byte must have been dropped)
|
||||
String s = "Helloworld";
|
||||
if (isServer) {
|
||||
for (int y=0; y<s.length(); y++) {
|
||||
int c = sis.read ();
|
||||
if (c != (int)s.charAt (y)) {
|
||||
throw new RuntimeException ("Unexpected character read");
|
||||
}
|
||||
}
|
||||
// Do the same from server to client
|
||||
sos.write ("Hello".getBytes ());
|
||||
server.sendUrgentData (101);
|
||||
sos.write ("World".getBytes ());
|
||||
}
|
||||
if (isClient) {
|
||||
// read Hello world from client (during which oob byte must have been read)
|
||||
s="Hello";
|
||||
for (int y=0; y<s.length(); y++) {
|
||||
int c = clis.read ();
|
||||
if (c != (int)s.charAt (y)) {
|
||||
throw new RuntimeException ("Unexpected character read");
|
||||
}
|
||||
}
|
||||
if (clis.read() != 101) {
|
||||
throw new RuntimeException ("OOB byte not received");
|
||||
}
|
||||
s="World";
|
||||
for (int y=0; y<s.length(); y++) {
|
||||
int c = clis.read ();
|
||||
if (c != (int)s.charAt (y)) {
|
||||
throw new RuntimeException ("Unexpected character read");
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (listener != null) listener.close();
|
||||
if (client != null) client.close ();
|
||||
if (server != null) server.close ();
|
||||
}
|
||||
|
||||
if (isClient)
|
||||
client.close ();
|
||||
if (isServer)
|
||||
server.close ();
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,6 @@ public class BrokenPipe {
|
||||
try {
|
||||
client.getOutputStream().write(new byte[1000000]);
|
||||
} catch (IOException ioe) {
|
||||
|
||||
/*
|
||||
* Check that the exception text doesn't indicate the
|
||||
* socket is closed. In tiger we should be able to
|
||||
@ -71,8 +70,9 @@ public class BrokenPipe {
|
||||
if (text.toLowerCase().indexOf("closed") >= 0) {
|
||||
throw ioe;
|
||||
}
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
server.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,27 +39,28 @@ public class Restart {
|
||||
*/
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
ServerSocket ss = new ServerSocket(0);
|
||||
Socket s1 = null, s2 = null;
|
||||
try {
|
||||
int port = ss.getLocalPort();
|
||||
|
||||
InetSocketAddress isa = new InetSocketAddress(0);
|
||||
ServerSocket ss = new ServerSocket();
|
||||
ss.bind(isa);
|
||||
s1 = new Socket(InetAddress.getLocalHost(), port);
|
||||
s2 = ss.accept();
|
||||
|
||||
int port = ss.getLocalPort();
|
||||
// close server socket and the accepted connection
|
||||
ss.close();
|
||||
s2.close();
|
||||
|
||||
Socket s1 = new Socket(InetAddress.getLocalHost(), port);
|
||||
Socket s2 = ss.accept();
|
||||
ss = new ServerSocket();
|
||||
ss.bind( new InetSocketAddress(port) );
|
||||
ss.close();
|
||||
|
||||
// close server socket and the accepted connection
|
||||
ss.close();
|
||||
s2.close();
|
||||
|
||||
boolean failed = false;
|
||||
|
||||
ss = new ServerSocket();
|
||||
ss.bind( new InetSocketAddress(port) );
|
||||
ss.close();
|
||||
|
||||
// close the client socket
|
||||
s1.close();
|
||||
// close the client socket
|
||||
s1.close();
|
||||
} finally {
|
||||
if (ss != null) ss.close();
|
||||
if (s1 != null) s1.close();
|
||||
if (s2 != null) s2.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,68 +32,37 @@ import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
public class SocketClosedException {
|
||||
|
||||
/*
|
||||
* Is the server ready to serve?
|
||||
*/
|
||||
volatile static boolean serverReady = false;
|
||||
|
||||
/*
|
||||
* Define the server side of the test.
|
||||
*
|
||||
* If the server prematurely exits, serverReady will be set to true
|
||||
* to avoid infinite hangs.
|
||||
*/
|
||||
static void doServerSide() throws Exception {
|
||||
ServerSocket serverSocket = new ServerSocket(serverPort);
|
||||
serverPort = serverSocket.getLocalPort();
|
||||
try {
|
||||
Socket socket = serverSocket.accept();
|
||||
|
||||
/*
|
||||
* Signal Client, we're ready for a connect.
|
||||
*/
|
||||
serverReady = true;
|
||||
OutputStream os = socket.getOutputStream();
|
||||
|
||||
Socket socket = serverSocket.accept();
|
||||
|
||||
InputStream is = socket.getInputStream();
|
||||
OutputStream os = socket.getOutputStream();
|
||||
|
||||
os.write(85);
|
||||
os.flush();
|
||||
socket.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* Define the client side of the test.
|
||||
*
|
||||
* If the server prematurely exits, serverReady will be set to true
|
||||
* to avoid infinite hangs.
|
||||
*/
|
||||
static void doClientSide() throws Exception {
|
||||
|
||||
/*
|
||||
* Wait for server to get started.
|
||||
*/
|
||||
while (!serverReady) {
|
||||
Thread.sleep(5000);
|
||||
os.write(85);
|
||||
os.flush();
|
||||
socket.close();
|
||||
} finally {
|
||||
serverSocket.close();
|
||||
}
|
||||
|
||||
Socket socket = new Socket("localhost", serverPort);
|
||||
InputStream is = socket.getInputStream();
|
||||
OutputStream os = socket.getOutputStream();
|
||||
|
||||
int read = is.read();
|
||||
socket.close();
|
||||
read = is.read();
|
||||
}
|
||||
|
||||
static int serverPort = 0;
|
||||
static void doClientSide(int port) throws Exception {
|
||||
Socket socket = new Socket("localhost", port);
|
||||
InputStream is = socket.getInputStream();
|
||||
|
||||
is.read();
|
||||
socket.close();
|
||||
is.read();
|
||||
}
|
||||
|
||||
static ServerSocket serverSocket;
|
||||
static Exception serverException = null;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
serverSocket = new ServerSocket(0);
|
||||
startServer();
|
||||
try {
|
||||
doClientSide();
|
||||
doClientSide(serverSocket.getLocalPort());
|
||||
} catch (SocketException e) {
|
||||
if (!e.getMessage().equalsIgnoreCase("Socket closed")) {
|
||||
throw new Exception("Received a wrong exception message: " +
|
||||
@ -108,21 +77,14 @@ public class SocketClosedException {
|
||||
}
|
||||
|
||||
static void startServer() {
|
||||
Thread serverThread = new Thread() {
|
||||
(new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
doServerSide();
|
||||
} catch (Exception e) {
|
||||
/*
|
||||
* server thread just died.
|
||||
* Release the client, if not active already...
|
||||
*/
|
||||
System.err.println("Server died...");
|
||||
serverReady = true;
|
||||
serverException = e;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
serverThread.start();
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
@ -31,26 +31,24 @@ import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
public class SocketTimeout {
|
||||
static final int TIMEOUT = 1000;
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
InetAddress sin = null;
|
||||
InetAddress sin = InetAddress.getLocalHost();
|
||||
Socket soc = null,soc1 = null;
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
ServerSocket srv = null;
|
||||
int port = 0;
|
||||
int tout = 1000;
|
||||
|
||||
sin = InetAddress.getLocalHost();
|
||||
srv = new ServerSocket(port);
|
||||
srv = new ServerSocket(0);
|
||||
port = srv.getLocalPort();
|
||||
soc = new Socket(sin, port);
|
||||
soc1 = srv.accept();
|
||||
soc.setSoTimeout(tout);
|
||||
srv.setSoTimeout(tout);
|
||||
soc.setSoTimeout(TIMEOUT);
|
||||
srv.setSoTimeout(TIMEOUT);
|
||||
|
||||
try {
|
||||
is = soc.getInputStream();
|
||||
os = soc1.getOutputStream();
|
||||
is.read();
|
||||
} catch(InterruptedIOException e) {
|
||||
try {
|
||||
@ -59,6 +57,9 @@ public class SocketTimeout {
|
||||
} catch(NoClassDefFoundError e1) {
|
||||
throw new Exception ("SocketTimeoutException: not found");
|
||||
}
|
||||
} finally {
|
||||
soc.close();
|
||||
soc1.close();
|
||||
}
|
||||
|
||||
// now check accept
|
||||
@ -72,12 +73,14 @@ public class SocketTimeout {
|
||||
} catch(NoClassDefFoundError e1) {
|
||||
throw new Exception ("SocketTimeoutException: not found");
|
||||
}
|
||||
} finally {
|
||||
srv.close();
|
||||
}
|
||||
|
||||
// Now check DatagramSocket.receive()
|
||||
|
||||
DatagramSocket dg = new DatagramSocket ();
|
||||
dg.setSoTimeout (tout);
|
||||
dg.setSoTimeout (TIMEOUT);
|
||||
|
||||
try {
|
||||
dg.receive (new DatagramPacket (new byte [64], 64));
|
||||
@ -88,11 +91,8 @@ public class SocketTimeout {
|
||||
} catch(NoClassDefFoundError e1) {
|
||||
throw new Exception ("SocketTimeoutException: not found");
|
||||
}
|
||||
} finally {
|
||||
dg.close();
|
||||
}
|
||||
|
||||
soc.close();
|
||||
soc1.close();
|
||||
srv.close();
|
||||
dg.close();
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +53,13 @@ public class GetContent implements Runnable {
|
||||
|
||||
// wait for client to read response - otherwise http
|
||||
// client get error and re-establish connection
|
||||
Thread.currentThread().sleep(2000);
|
||||
Thread.sleep(2000);
|
||||
|
||||
s.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { ss.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,8 +83,6 @@ public class GetContent implements Runnable {
|
||||
error = false;
|
||||
}
|
||||
|
||||
ss.close();
|
||||
|
||||
if (error)
|
||||
throw new RuntimeException("No IOException generated.");
|
||||
}
|
||||
|
@ -27,20 +27,45 @@
|
||||
* @summary Test for FileNotFoundException when loading bogus class
|
||||
*/
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
public class ClassLoad {
|
||||
public static void main(String[] args) throws Exception {
|
||||
boolean error = true;
|
||||
|
||||
// Start a dummy server to return 404
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
|
||||
HttpHandler handler = new HttpHandler() {
|
||||
public void handle(HttpExchange t) throws IOException {
|
||||
InputStream is = t.getRequestBody();
|
||||
while (is.read() != -1);
|
||||
t.sendResponseHeaders (404, -1);
|
||||
t.close();
|
||||
}
|
||||
};
|
||||
server.createContext("/", handler);
|
||||
server.start();
|
||||
|
||||
// Client request
|
||||
try {
|
||||
URL url = new URL(args.length >= 1 ? args[0] : "http://jini.east/");
|
||||
URL url = new URL("http://localhost:" + server.getAddress().getPort());
|
||||
String name = args.length >= 2 ? args[1] : "foo.bar.Baz";
|
||||
ClassLoader loader = new URLClassLoader(new URL[] { url });
|
||||
System.out.println(url);
|
||||
Class c = loader.loadClass(name);
|
||||
System.out.println("Loaded class \"" + c.getName() + "\".");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
System.out.println(ex);
|
||||
error = false;
|
||||
} finally {
|
||||
server.stop(0);
|
||||
}
|
||||
if (error)
|
||||
throw new RuntimeException("No ClassNotFoundException generated");
|
||||
|
@ -56,7 +56,6 @@ public class DisconnectAfterEOF {
|
||||
int cl = -1;
|
||||
int remaining = -1;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Random r = new Random();
|
||||
boolean close = false;
|
||||
|
||||
boolean inBody = false;
|
||||
@ -239,8 +238,6 @@ public class DisconnectAfterEOF {
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
Random r = new Random();
|
||||
|
||||
// start server
|
||||
ServerSocket ss = new ServerSocket(0);
|
||||
Server svr = new Server(ss);
|
||||
@ -273,7 +270,7 @@ public class DisconnectAfterEOF {
|
||||
URLConnection uc1 = doRequest(uri);
|
||||
doResponse(uc1);
|
||||
|
||||
Thread.currentThread().sleep(2000);
|
||||
Thread.sleep(2000);
|
||||
|
||||
URLConnection uc2 = doRequest(uri);
|
||||
|
||||
|
@ -111,9 +111,8 @@ class myHttpServer implements Runnable, Cloneable {
|
||||
} catch(Exception e) {
|
||||
System.out.print("Server failure\n");
|
||||
e.printStackTrace();
|
||||
try {
|
||||
serverSocket.close();
|
||||
} catch(IOException e2) {}
|
||||
} finally {
|
||||
try { serverSocket.close(); } catch(IOException unused) {}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
@ -127,10 +126,9 @@ class myHttpServer implements Runnable, Cloneable {
|
||||
} catch(Exception e) {
|
||||
// System.out.print("Service handler failure\n");
|
||||
// e.printStackTrace();
|
||||
} finally {
|
||||
try { close(); } catch(IOException unused) {}
|
||||
}
|
||||
try {
|
||||
close();
|
||||
} catch(IOException e2) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
*/
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
@ -41,61 +41,56 @@ public class HttpContinueStackOverflow {
|
||||
|
||||
static class Server implements Runnable {
|
||||
int port;
|
||||
ServerSocket serverSock ;
|
||||
|
||||
Server(int port) {
|
||||
this.port = port;
|
||||
Server() throws IOException {
|
||||
serverSock = new ServerSocket(0);
|
||||
}
|
||||
|
||||
int getLocalPort() {
|
||||
return serverSock.getLocalPort();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Socket sock = null;
|
||||
try {
|
||||
/* bind to port and wait for connection */
|
||||
ServerSocket serverSock = new ServerSocket( port );
|
||||
serverSock.setSoTimeout(10000);
|
||||
Socket sock = serverSock.accept();
|
||||
sock = serverSock.accept();
|
||||
|
||||
/* setup streams and read http request */
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(sock.getInputStream()));
|
||||
PrintStream out = new PrintStream( sock.getOutputStream() );
|
||||
String request = in.readLine();
|
||||
in.readLine();
|
||||
|
||||
/* send continue followed by invalid response */
|
||||
out.println("HTTP/1.1 100 Continue\r");
|
||||
out.println("\r");
|
||||
out.println("junk junk junk");
|
||||
out.flush();
|
||||
|
||||
sock.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { serverSock.close(); } catch (IOException unused) {}
|
||||
try { sock.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HttpContinueStackOverflow(int port) throws Exception {
|
||||
HttpContinueStackOverflow() throws Exception {
|
||||
/* create the server */
|
||||
Server s = new Server(port);
|
||||
Thread thr = new Thread(s);
|
||||
thr.start();
|
||||
|
||||
/* wait for server to bind to port */
|
||||
try {
|
||||
Thread.currentThread().sleep(2000);
|
||||
} catch (Exception e) { }
|
||||
Server s = new Server();
|
||||
(new Thread(s)).start();
|
||||
|
||||
/* connect to server, connect to server and get response code */
|
||||
URL url = new URL("http", "localhost", port, "anything.html");
|
||||
URL url = new URL("http", "localhost", s.getLocalPort(), "anything.html");
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
int respCode = conn.getResponseCode();
|
||||
conn.getResponseCode();
|
||||
System.out.println("TEST PASSED");
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
int port = 4090;
|
||||
if (args.length > 0) {
|
||||
port = Integer.parseInt(args[0]);
|
||||
}
|
||||
System.out.println("Testing 100-Continue");
|
||||
new HttpContinueStackOverflow(port);
|
||||
new HttpContinueStackOverflow();
|
||||
}
|
||||
}
|
||||
|
@ -37,11 +37,11 @@ class RedirServer extends Thread {
|
||||
OutputStream os;
|
||||
int port;
|
||||
|
||||
String reply1 = "HTTP/1.1 307 Temporary Redirect\r\n" +
|
||||
String reply1Part1 = "HTTP/1.1 307 Temporary Redirect\r\n" +
|
||||
"Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
|
||||
"Server: Apache/1.3.14 (Unix)\r\n" +
|
||||
"Location: http://localhost:";
|
||||
String reply2 = "/redirected.html\r\n" +
|
||||
String reply1Part2 = "/redirected.html\r\n" +
|
||||
"Connection: close\r\n" +
|
||||
"Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
|
||||
"<html>Hello</html>";
|
||||
@ -49,9 +49,10 @@ class RedirServer extends Thread {
|
||||
RedirServer (ServerSocket y) {
|
||||
s = y;
|
||||
port = s.getLocalPort();
|
||||
System.out.println("Server created listening on " + port);
|
||||
}
|
||||
|
||||
String reply3 = "HTTP/1.1 200 Ok\r\n" +
|
||||
String reply2 = "HTTP/1.1 200 Ok\r\n" +
|
||||
"Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
|
||||
"Server: Apache/1.3.14 (Unix)\r\n" +
|
||||
"Connection: close\r\n" +
|
||||
@ -64,16 +65,24 @@ class RedirServer extends Thread {
|
||||
is = s1.getInputStream ();
|
||||
os = s1.getOutputStream ();
|
||||
is.read ();
|
||||
String reply = reply1 + port + reply2;
|
||||
String reply = reply1Part1 + port + reply1Part2;
|
||||
os.write (reply.getBytes());
|
||||
os.close();
|
||||
/* wait for redirected connection */
|
||||
s.setSoTimeout (5000);
|
||||
s1 = s.accept ();
|
||||
is = s1.getInputStream ();
|
||||
os = s1.getOutputStream ();
|
||||
os.write (reply3.getBytes());
|
||||
is.read();
|
||||
os.write (reply2.getBytes());
|
||||
os.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
/* Just need thread to terminate */
|
||||
System.out.println("Server: caught " + e);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { s.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -84,10 +93,7 @@ public class Redirect307Test {
|
||||
public static final int DELAY = 10;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
int nLoops = 1;
|
||||
int nSize = 10;
|
||||
int port, n =0;
|
||||
byte b[] = new byte[nSize];
|
||||
int port;
|
||||
RedirServer server;
|
||||
ServerSocket sock;
|
||||
|
||||
@ -119,7 +125,8 @@ public class Redirect307Test {
|
||||
}
|
||||
}
|
||||
catch(IOException e) {
|
||||
throw new RuntimeException ("Exception caught");
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException ("Exception caught + " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,15 +76,19 @@ class RedirLimitServer extends Thread {
|
||||
is.read ();
|
||||
String reply = reply1 + port + "/redirect" + i + reply2;
|
||||
os.write (reply.getBytes());
|
||||
os.close();
|
||||
}
|
||||
s1 = s.accept ();
|
||||
is = s1.getInputStream ();
|
||||
os = s1.getOutputStream ();
|
||||
is.read ();
|
||||
os.write (reply3.getBytes());
|
||||
os.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
/* Just need thread to terminate */
|
||||
} finally {
|
||||
try { s.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -109,8 +109,11 @@ public class ResendPostBody {
|
||||
while (!finished()) {
|
||||
Thread.sleep (1000);
|
||||
}
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
System.err.println ("Server Exception: " + e);
|
||||
} finally {
|
||||
try { server.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -134,7 +137,7 @@ public class ResendPostBody {
|
||||
|
||||
public void execute () throws Exception {
|
||||
|
||||
byte b[] = "X=ABCDEFGHZZZ".getBytes();
|
||||
byte b[] = "X=ABCDEFGHZZZ".getBytes();
|
||||
|
||||
ss = new ServerSocket (0);
|
||||
server = new Server (ss);
|
||||
@ -163,8 +166,9 @@ public class ResendPostBody {
|
||||
/* Read the response */
|
||||
|
||||
int resp = conURL.getResponseCode ();
|
||||
server.setFinished (true);
|
||||
|
||||
if (resp != 200)
|
||||
throw new RuntimeException ("Response code was not 200: " + resp);
|
||||
server.setFinished (true);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/* @test
|
||||
* @bug 4397096
|
||||
* @run main SetIfModifiedSince
|
||||
* @run main/othervm SetIfModifiedSince
|
||||
* @summary setIfModifiedSince() of HttpURLConnection sets invalid date of default locale
|
||||
*/
|
||||
|
||||
|
@ -43,8 +43,9 @@ public class TimeoutTest {
|
||||
try {
|
||||
Socket s = server.accept ();
|
||||
while (!finished ()) {
|
||||
Thread.sleep (2000);
|
||||
Thread.sleep (1000);
|
||||
}
|
||||
s.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
@ -70,9 +71,12 @@ public class TimeoutTest {
|
||||
URL url = new URL ("http://127.0.0.1:"+ss.getLocalPort());
|
||||
URLConnection urlc = url.openConnection ();
|
||||
InputStream is = urlc.getInputStream ();
|
||||
throw new RuntimeException("Should have received timeout");
|
||||
} catch (SocketTimeoutException e) {
|
||||
s.done ();
|
||||
return;
|
||||
} finally {
|
||||
s.done();
|
||||
ss.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,8 +70,10 @@ public class URLConnectionHeaders {
|
||||
w.newLine();
|
||||
w.flush();
|
||||
s.close ();
|
||||
srv.close (); // or else the HTTPURLConnection will retry
|
||||
} catch (IOException e) { e.printStackTrace();}
|
||||
} catch (IOException e) { e.printStackTrace();
|
||||
} finally {
|
||||
try { srv.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,14 @@ public class ZeroContentLength {
|
||||
contentLength = cl;
|
||||
}
|
||||
|
||||
static synchronized String getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
static synchronized int getContentLength() {
|
||||
return contentLength;
|
||||
}
|
||||
|
||||
/*
|
||||
* Worker thread to service single connection - can service
|
||||
* multiple http requests on same connection.
|
||||
@ -71,25 +79,44 @@ public class ZeroContentLength {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
final int CR = '\r';
|
||||
final int LF = '\n';
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
s.setSoTimeout(2000);
|
||||
int max = 100;
|
||||
int max = 20; // there should only be 20 connections
|
||||
InputStream in = new BufferedInputStream(s.getInputStream());
|
||||
|
||||
for (;;) {
|
||||
|
||||
// read entire request from client
|
||||
byte b[] = new byte[100];
|
||||
InputStream in = s.getInputStream();
|
||||
int n, total=0;
|
||||
// read entire request from client, until CR LF CR LF
|
||||
int c, total=0;
|
||||
|
||||
try {
|
||||
do {
|
||||
n = in.read(b);
|
||||
if (n > 0) total += n;
|
||||
} while (n > 0);
|
||||
} catch (SocketTimeoutException e) { }
|
||||
while ((c = in.read()) > 0) {
|
||||
total++;
|
||||
if (c == CR) {
|
||||
if ((c = in.read()) > 0) {
|
||||
total++;
|
||||
if (c == LF) {
|
||||
if ((c = in.read()) > 0) {
|
||||
total++;
|
||||
if (c == CR) {
|
||||
if ((c = in.read()) > 0) {
|
||||
total++;
|
||||
if (c == LF) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (SocketTimeoutException e) {}
|
||||
|
||||
debug("worker " + id +
|
||||
": Read request from client " +
|
||||
@ -105,19 +132,20 @@ public class ZeroContentLength {
|
||||
new BufferedOutputStream(
|
||||
s.getOutputStream() ));
|
||||
|
||||
out.print("HTTP/1.1 " + response + "\r\n");
|
||||
if (contentLength >= 0) {
|
||||
out.print("Content-Length: " + contentLength +
|
||||
out.print("HTTP/1.1 " + getResponse() + "\r\n");
|
||||
int clen = getContentLength();
|
||||
if (clen >= 0) {
|
||||
out.print("Content-Length: " + clen +
|
||||
"\r\n");
|
||||
}
|
||||
out.print("\r\n");
|
||||
for (int i=0; i<contentLength; i++) {
|
||||
for (int i=0; i<clen; i++) {
|
||||
out.write( (byte)'.' );
|
||||
}
|
||||
out.flush();
|
||||
|
||||
debug("worked " + id +
|
||||
": Sent response to client, length: " + contentLength);
|
||||
": Sent response to client, length: " + clen);
|
||||
|
||||
if (--max == 0) {
|
||||
s.close();
|
||||
|
@ -58,6 +58,8 @@ public class B6521014 {
|
||||
Enumeration e = NetworkInterface.getNetworkInterfaces();
|
||||
while (e.hasMoreElements()) {
|
||||
NetworkInterface ifc = (NetworkInterface) e.nextElement();
|
||||
if (!ifc.isUp())
|
||||
continue;
|
||||
Enumeration addrs = ifc.getInetAddresses();
|
||||
while (addrs.hasMoreElements()) {
|
||||
InetAddress a = (InetAddress)addrs.nextElement();
|
||||
|
@ -38,7 +38,6 @@ public class TcpTest extends Tests {
|
||||
static InetAddress ia4any;
|
||||
static InetAddress ia6any;
|
||||
static Inet6Address ia6addr;
|
||||
static InetAddress ia6bad; /* a global 6to4 IPv6 address, which cant be connected to */
|
||||
static Inet4Address ia4addr;
|
||||
|
||||
static {
|
||||
@ -47,14 +46,6 @@ public class TcpTest extends Tests {
|
||||
try {
|
||||
ia4any = InetAddress.getByName ("0.0.0.0");
|
||||
ia6any = InetAddress.getByName ("::0");
|
||||
if (ia6addr != null) {
|
||||
int scope = ia6addr.getScopeId();
|
||||
if (scope != 0) {
|
||||
ia6bad = InetAddress.getByName ("fe80::1:2:3:4:5:6%"+scope);
|
||||
}
|
||||
} else {
|
||||
ia6bad = InetAddress.getByName ("fe80::1:2:3:4:5:6");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -69,7 +60,6 @@ public class TcpTest extends Tests {
|
||||
dprintln ("Local Addresses");
|
||||
dprintln (ia4addr.toString());
|
||||
dprintln (ia6addr.toString());
|
||||
dprintln ("Bad address: " + ia6bad);
|
||||
test1 (0);
|
||||
test1 (5100);
|
||||
test2();
|
||||
@ -224,19 +214,6 @@ public class TcpTest extends Tests {
|
||||
c1.close (); c2.close();
|
||||
s1.close (); s2.close();
|
||||
|
||||
/* check if connect() timesout when connecting to unknown dest. */
|
||||
|
||||
c1 = new Socket();
|
||||
t1 = System.currentTimeMillis();
|
||||
InetSocketAddress ad1 = new InetSocketAddress (ia6bad, 2500);
|
||||
try {
|
||||
c1.connect (ad1, 5000);
|
||||
throw new RuntimeException ("timeout exception was expected");
|
||||
} catch (SocketTimeoutException e) {
|
||||
t1 = System.currentTimeMillis() - t1;
|
||||
checkTime (t1, 5000);
|
||||
} catch (NoRouteToHostException e1) {
|
||||
}
|
||||
System.out.println ("Test3: OK");
|
||||
}
|
||||
|
||||
|
@ -134,11 +134,11 @@ public class Tests {
|
||||
}
|
||||
}
|
||||
|
||||
/* check the time got is within 20% of the time expected */
|
||||
/* check the time got is within 50% of the time expected */
|
||||
public static void checkTime (long got, long expected) {
|
||||
dprintln ("checkTime: got " + got + " expected " + expected);
|
||||
long upper = expected + (expected / 5);
|
||||
long lower = expected - (expected / 5);
|
||||
long upper = expected + (expected / 2);
|
||||
long lower = expected - (expected / 2);
|
||||
if (got > upper || got < lower) {
|
||||
throw new RuntimeException ("checkTime failed: got " + got + " expected " + expected);
|
||||
}
|
||||
|
@ -391,6 +391,10 @@ public class FtpGetContent {
|
||||
done = true;
|
||||
}
|
||||
|
||||
synchronized boolean done() {
|
||||
return done;
|
||||
}
|
||||
|
||||
synchronized public void setPortEnabled(boolean ok) {
|
||||
portEnabled = ok;
|
||||
}
|
||||
@ -431,12 +435,13 @@ public class FtpGetContent {
|
||||
public void run() {
|
||||
try {
|
||||
Socket client;
|
||||
while (!done) {
|
||||
while (!done()) {
|
||||
client = server.accept();
|
||||
(new FtpServerHandler(client)).start();
|
||||
}
|
||||
server.close();
|
||||
} catch(Exception e) {
|
||||
} finally {
|
||||
try { server.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -463,18 +468,13 @@ public class FtpGetContent {
|
||||
bytesRead = stream.read(buffer);
|
||||
}
|
||||
stream.close();
|
||||
server.terminate();
|
||||
server.interrupt();
|
||||
if (totalBytes != filesize)
|
||||
throw new RuntimeException("wrong file size!");
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
server.terminate();
|
||||
server.interrupt();
|
||||
} catch (Exception e2) {
|
||||
}
|
||||
throw new RuntimeException(e.getMessage());
|
||||
} finally {
|
||||
server.terminate();
|
||||
server.server.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -438,8 +438,9 @@ public class FtpURL {
|
||||
client = server.accept();
|
||||
(new FtpServerHandler(client)).run();
|
||||
}
|
||||
server.close();
|
||||
} catch(Exception e) {
|
||||
} finally {
|
||||
try { server.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -448,10 +449,9 @@ public class FtpURL {
|
||||
}
|
||||
|
||||
public FtpURL() throws Exception {
|
||||
FtpServer server = null;
|
||||
FtpServer server = new FtpServer(0);
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
server = new FtpServer(0);
|
||||
server.start();
|
||||
int port = server.getPort();
|
||||
|
||||
@ -497,17 +497,14 @@ public class FtpURL {
|
||||
throw new RuntimeException("Incorrect filename received");
|
||||
if (! "/usr".equals(server.pwd()))
|
||||
throw new RuntimeException("Incorrect pwd received");
|
||||
in.close();
|
||||
// We're done!
|
||||
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
in.close();
|
||||
server.terminate();
|
||||
server.interrupt();
|
||||
} catch(Exception ex) {
|
||||
}
|
||||
throw new RuntimeException("FTP support error: " + e.getMessage());
|
||||
} finally {
|
||||
try { in.close(); } catch (IOException unused) {}
|
||||
server.terminate();
|
||||
server.server.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,7 @@
|
||||
* @summary ChunkedEncoding unit test; MeteredStream/ProgressData problem
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.*;
|
||||
import java.util.BitSet;
|
||||
import sun.net.ProgressMeteringPolicy;
|
||||
import sun.net.ProgressMonitor;
|
||||
@ -42,8 +40,10 @@ import sun.net.ProgressEvent;
|
||||
public class ChunkedEncodingWithProgressMonitorTest {
|
||||
public static void main (String[] args) throws Exception {
|
||||
ProgressMonitor.setMeteringPolicy(new MyProgressMeteringPolicy());
|
||||
ProgressMonitor.getDefault().addProgressListener(new MyProgressListener());
|
||||
ProgressListener listener = new MyProgressListener();
|
||||
ProgressMonitor.getDefault().addProgressListener(listener);
|
||||
ChunkedEncodingTest.test();
|
||||
ProgressMonitor.getDefault().removeProgressListener(listener);
|
||||
|
||||
if (flag.cardinality() != 3) {
|
||||
throw new RuntimeException("All three methods in ProgressListener"+
|
||||
|
@ -34,7 +34,7 @@ import com.sun.net.httpserver.*;
|
||||
|
||||
public class Test implements HttpHandler {
|
||||
|
||||
static int count = 0;
|
||||
static volatile int count = 0;
|
||||
|
||||
static final String str1 = "Helloworld1234567890abcdefghijklmnopqrstuvwxyz"+
|
||||
"1234567890abcdefkjsdlkjflkjsldkfjlsdkjflkj"+
|
||||
@ -46,9 +46,9 @@ public class Test implements HttpHandler {
|
||||
public void handle(HttpExchange exchange) {
|
||||
String reqbody;
|
||||
try {
|
||||
switch (count) {
|
||||
case 0: /* test1 -- keeps conn alive */
|
||||
case 1: /* test2 -- closes conn */
|
||||
switch (exchange.getRequestURI().toString()) {
|
||||
case "/test/test1": /* test1 -- keeps conn alive */
|
||||
case "/test/test2": /* test2 -- closes conn */
|
||||
printRequestURI(exchange);
|
||||
reqbody = read(exchange.getRequestBody());
|
||||
if (!reqbody.equals(str1)) {
|
||||
@ -72,7 +72,7 @@ public class Test implements HttpHandler {
|
||||
resHeaders.set("Connection", "close");
|
||||
}
|
||||
break;
|
||||
case 2: /* test 3 */
|
||||
case "/test/test3": /* test 3 */
|
||||
printRequestURI(exchange);
|
||||
reqbody = read(exchange.getRequestBody());
|
||||
|
||||
@ -93,19 +93,19 @@ public class Test implements HttpHandler {
|
||||
exchange.sendResponseHeaders(200, reqbody.length());
|
||||
write(exchange.getResponseBody(), reqbody);
|
||||
break;
|
||||
case 3: /* test 4 */
|
||||
case 4: /* test 5 */
|
||||
case "/test/test4": /* test 4 */
|
||||
case "/test/test5": /* test 5 */
|
||||
printRequestURI(exchange);
|
||||
break;
|
||||
case 5: /* test 6 */
|
||||
case "/test/test6": /* test 6 */
|
||||
printRequestURI(exchange);
|
||||
resHeaders = exchange.getResponseHeaders() ;
|
||||
resHeaders.set("Location", "http://foo.bar/");
|
||||
resHeaders.set("Connection", "close");
|
||||
exchange.sendResponseHeaders(307, 0);
|
||||
break;
|
||||
case 6: /* test 7 */
|
||||
case 7: /* test 8 */
|
||||
case "/test/test7": /* test 7 */
|
||||
case "/test/test8": /* test 8 */
|
||||
printRequestURI(exchange);
|
||||
reqbody = read(exchange.getRequestBody());
|
||||
if (reqbody != null && !"".equals(reqbody)) {
|
||||
@ -116,7 +116,7 @@ public class Test implements HttpHandler {
|
||||
resHeaders.set("Connection", "close");
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
break;
|
||||
case 8: /* test 9 */
|
||||
case "/test/test9": /* test 9 */
|
||||
printRequestURI(exchange);
|
||||
reqbody = read(exchange.getRequestBody());
|
||||
if (!reqbody.equals(str1)) {
|
||||
@ -134,7 +134,7 @@ public class Test implements HttpHandler {
|
||||
exchange.sendResponseHeaders(200, reqbody.length());
|
||||
write(exchange.getResponseBody(), reqbody);
|
||||
break;
|
||||
case 9: /* test10 */
|
||||
case "/test/test10": /* test10 */
|
||||
printRequestURI(exchange);
|
||||
InputStream is = exchange.getRequestBody();
|
||||
String s = read (is, str1.length());
|
||||
@ -158,7 +158,7 @@ public class Test implements HttpHandler {
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
}
|
||||
break;
|
||||
case 10: /* test11 */
|
||||
case "/test/test11": /* test11 */
|
||||
printRequestURI(exchange);
|
||||
is = exchange.getRequestBody();
|
||||
s = read (is, str1.length());
|
||||
@ -182,7 +182,7 @@ public class Test implements HttpHandler {
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
}
|
||||
break;
|
||||
case 11: /* test12 */
|
||||
case "/test/test12": /* test12 */
|
||||
printRequestURI(exchange);
|
||||
is = exchange.getRequestBody();
|
||||
|
||||
@ -203,8 +203,8 @@ public class Test implements HttpHandler {
|
||||
}
|
||||
break;
|
||||
}
|
||||
exchange.close();
|
||||
count ++;
|
||||
exchange.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -147,6 +147,8 @@ public class B6726695 extends Thread {
|
||||
serverIgnore(s);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { server.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,11 +100,12 @@ public class MultiThreadTest extends Thread {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException (e.getMessage());
|
||||
}
|
||||
synchronized (threadlock) {
|
||||
threadCounter --;
|
||||
if (threadCounter == 0) {
|
||||
threadlock.notifyAll();
|
||||
} finally {
|
||||
synchronized (threadlock) {
|
||||
threadCounter --;
|
||||
if (threadCounter == 0) {
|
||||
threadlock.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class ProxyTest {
|
||||
private class HttpProxyServer extends Thread {
|
||||
private ServerSocket server;
|
||||
private int port;
|
||||
private boolean done = false;
|
||||
private volatile boolean done = false;
|
||||
private String askedUrl;
|
||||
|
||||
/**
|
||||
@ -125,12 +125,8 @@ public class ProxyTest {
|
||||
}
|
||||
}
|
||||
|
||||
public HttpProxyServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public HttpProxyServer() {
|
||||
this(0);
|
||||
public HttpProxyServer() throws IOException {
|
||||
server = new ServerSocket(0);
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
@ -148,51 +144,49 @@ public class ProxyTest {
|
||||
*/
|
||||
synchronized public void terminate() {
|
||||
done = true;
|
||||
try { server.close(); } catch (IOException unused) {}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
server = new ServerSocket(port);
|
||||
Socket client;
|
||||
while (!done) {
|
||||
client = server.accept();
|
||||
(new HttpProxyHandler(client)).start();
|
||||
}
|
||||
server.close();
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
try { server.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ProxyTest test = new ProxyTest();
|
||||
}
|
||||
|
||||
public ProxyTest() {
|
||||
public ProxyTest() throws Exception {
|
||||
BufferedReader in = null;
|
||||
String testURL = "ftp://anonymous:password@myhost.mydomain/index.html";
|
||||
HttpProxyServer server = new HttpProxyServer();
|
||||
try {
|
||||
server.start();
|
||||
int port = 0;
|
||||
while (port == 0) {
|
||||
Thread.sleep(500);
|
||||
port = server.getPort();
|
||||
}
|
||||
server.start();
|
||||
int port = server.getPort();
|
||||
|
||||
System.setProperty("ftp.proxyHost","localhost");
|
||||
System.setProperty("ftp.proxyPort", String.valueOf(port));
|
||||
URL url = new URL(testURL);
|
||||
InputStream ins = url.openStream();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(ins));
|
||||
String line;
|
||||
do {
|
||||
line = in.readLine();
|
||||
} while (line != null);
|
||||
in.close();
|
||||
server.terminate();
|
||||
server.interrupt();
|
||||
Proxy ftpProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", port));
|
||||
URL url = new URL(testURL);
|
||||
InputStream ins = (url.openConnection(ftpProxy)).getInputStream();
|
||||
in = new BufferedReader(new InputStreamReader(ins));
|
||||
String line;
|
||||
do {
|
||||
line = in.readLine();
|
||||
} while (line != null);
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
server.terminate();
|
||||
try { in.close(); } catch (IOException unused) {}
|
||||
}
|
||||
/*
|
||||
* If the URLs don't match, we've got a bug!
|
||||
|
@ -91,9 +91,10 @@ public class KeepAliveTimerThread {
|
||||
out.flush();
|
||||
|
||||
s.close();
|
||||
server.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { server.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -118,6 +119,8 @@ public class KeepAliveTimerThread {
|
||||
if (grp.activeCount() > 0) {
|
||||
throw new RuntimeException("Keep-alive thread started in wrong thread group");
|
||||
}
|
||||
|
||||
grp.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,10 +43,6 @@ public class KeepAliveStreamCloseWithWrongContentLength {
|
||||
srv = s;
|
||||
}
|
||||
|
||||
Socket getSocket () {
|
||||
return (s);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
s = srv.accept ();
|
||||
@ -57,7 +53,7 @@ public class KeepAliveStreamCloseWithWrongContentLength {
|
||||
is.read();
|
||||
}
|
||||
OutputStreamWriter ow =
|
||||
new OutputStreamWriter(s.getOutputStream());
|
||||
new OutputStreamWriter((os = s.getOutputStream()));
|
||||
ow.write("HTTP/1.0 200 OK\n");
|
||||
|
||||
// Note: The client expects 10 bytes.
|
||||
@ -71,19 +67,16 @@ public class KeepAliveStreamCloseWithWrongContentLength {
|
||||
// Note: The (buggy) server only sends 9 bytes.
|
||||
ow.write("123456789");
|
||||
ow.flush();
|
||||
ow.close();
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
try {if (os != null) { os.close(); }} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
public static void main (String[] args) {
|
||||
public static void main (String[] args) throws Exception {
|
||||
ServerSocket serversocket = new ServerSocket (0);
|
||||
try {
|
||||
ServerSocket serversocket = new ServerSocket (0);
|
||||
int port = serversocket.getLocalPort ();
|
||||
XServer server = new XServer (serversocket);
|
||||
server.start ();
|
||||
@ -100,11 +93,12 @@ public class KeepAliveStreamCloseWithWrongContentLength {
|
||||
}
|
||||
}
|
||||
is.close();
|
||||
server.getSocket().close ();
|
||||
} catch (IOException e) {
|
||||
return;
|
||||
} catch (NullPointerException e) {
|
||||
throw new RuntimeException (e);
|
||||
} finally {
|
||||
if (serversocket != null) serversocket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -188,6 +188,7 @@ public class HttpServer {
|
||||
sock.configureBlocking (false);
|
||||
sock.register (selector, SelectionKey.OP_READ);
|
||||
nconn ++;
|
||||
System.out.println("SERVER: new connection. chan[" + sock + "]");
|
||||
if (nconn == maxconn) {
|
||||
/* deregister */
|
||||
listenerKey.cancel ();
|
||||
@ -197,7 +198,9 @@ public class HttpServer {
|
||||
if (key.isReadable()) {
|
||||
boolean closed;
|
||||
SocketChannel chan = (SocketChannel) key.channel();
|
||||
System.out.println("SERVER: connection readable. chan[" + chan + "]");
|
||||
if (key.attachment() != null) {
|
||||
System.out.println("Server: comsume");
|
||||
closed = consume (chan);
|
||||
} else {
|
||||
closed = read (chan, key);
|
||||
@ -375,6 +378,7 @@ public class HttpServer {
|
||||
|
||||
synchronized void orderlyCloseChannel (SelectionKey key) throws IOException {
|
||||
SocketChannel ch = (SocketChannel)key.channel ();
|
||||
System.out.println("SERVER: orderlyCloseChannel chan[" + ch + "]");
|
||||
ch.socket().shutdownOutput();
|
||||
key.attach (this);
|
||||
clist.add (key);
|
||||
@ -382,6 +386,8 @@ public class HttpServer {
|
||||
|
||||
synchronized void abortiveCloseChannel (SelectionKey key) throws IOException {
|
||||
SocketChannel ch = (SocketChannel)key.channel ();
|
||||
System.out.println("SERVER: abortiveCloseChannel chan[" + ch + "]");
|
||||
|
||||
Socket s = ch.socket ();
|
||||
s.setSoLinger (true, 0);
|
||||
ch.close();
|
||||
|
@ -95,10 +95,11 @@ class DigestServer extends Thread {
|
||||
os.write (reply.getBytes());
|
||||
Thread.sleep (2000);
|
||||
s1.close ();
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
System.out.println (e);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try { s.close(); } catch (IOException unused) {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,15 +205,12 @@ public class DigestTest {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
int nLoops = 1;
|
||||
int nSize = 10;
|
||||
int port, n =0;
|
||||
byte b[] = new byte[nSize];
|
||||
int port;
|
||||
DigestServer server;
|
||||
ServerSocket sock;
|
||||
|
||||
try {
|
||||
sock = new ServerSocket (5000);
|
||||
sock = new ServerSocket (0);
|
||||
port = sock.getLocalPort ();
|
||||
}
|
||||
catch (Exception e) {
|
||||
@ -225,21 +223,18 @@ public class DigestTest {
|
||||
boolean passed = false;
|
||||
|
||||
try {
|
||||
|
||||
Authenticator.setDefault (new MyAuthenticator ());
|
||||
String s = "http://localhost:" + port + DigestServer.uri;
|
||||
URL url = new URL(s);
|
||||
java.net.URLConnection conURL = url.openConnection();
|
||||
|
||||
InputStream in = conURL.getInputStream();
|
||||
int c;
|
||||
while ((c = in.read ()) != -1) {
|
||||
}
|
||||
while (in.read () != -1) {}
|
||||
in.close ();
|
||||
}
|
||||
catch(ProtocolException e) {
|
||||
} catch(ProtocolException e) {
|
||||
passed = true;
|
||||
}
|
||||
|
||||
if (!passed) {
|
||||
throw new RuntimeException ("Expected a ProtocolException from wrong password");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user