Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8286962: java/net/httpclient/ServerCloseTest.java failed once with ConnectException #1698

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions test/jdk/java/net/httpclient/ServerCloseTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, 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
Expand Down Expand Up @@ -287,35 +287,45 @@ public void run() {
try {
while(!stopped) {
Socket clientConnection = ss.accept();
connections.add(clientConnection);
System.out.println(now() + getName() + ": Client accepted");
StringBuilder headers = new StringBuilder();
Socket targetConnection = null;
InputStream ccis = clientConnection.getInputStream();
OutputStream ccos = clientConnection.getOutputStream();
Writer w = new OutputStreamWriter(
clientConnection.getOutputStream(), "UTF-8");
clientConnection.getOutputStream(), UTF_8);
PrintWriter pw = new PrintWriter(w);
System.out.println(now() + getName() + ": Reading request line");
String requestLine = readLine(ccis);
System.out.println(now() + getName() + ": Request line: " + requestLine);

StringTokenizer tokenizer = new StringTokenizer(requestLine);
String method = tokenizer.nextToken();
assert method.equalsIgnoreCase("POST")
|| method.equalsIgnoreCase("GET");
if (!method.equals("GET") && !method.equals("POST")) {
System.err.println(now() + getName() + ": Unexpected request method. Method: " + method);
clientConnection.close();
continue;
}

String path = tokenizer.nextToken();
if (!path.contains("/dummy/x")) {
System.err.println(now() + getName() + ": Unexpected request path. Path: " + path);
clientConnection.close();
continue;
}

URI uri;
try {
String hostport = serverAuthority();
uri = new URI((secure ? "https" : "http") +"://" + hostport + path);
uri = new URI((secure ? "https" : "http") + "://" + hostport + path);
} catch (Throwable x) {
System.err.printf("Bad target address: \"%s\" in \"%s\"%n",
System.err.printf(now() + getName() + ": Bad target address: \"%s\" in \"%s\"%n",
path, requestLine);
clientConnection.close();
continue;
}

// Method, path and URI are valid. Add to connections list
connections.add(clientConnection);
// Read all headers until we find the empty line that
// signals the end of all headers.
String line = requestLine;
Expand Down