/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 4636331
* @summary Check that URLClassLoader doesn't create excessive http
* connections
*/
public class HttpTest {
/*
* Simple http server to service http requests. Auto shutdown
* if "idle" (no requests) for 10 seconds. Forks worker thread
* to service persistent connections. Work threads shutdown if
* "idle" for 5 seconds.
*/
Socket s;
this.s = s;
}
public void run() {
try {
in = s.getInputStream();
for (;;) {
// read entire request from client
byte b[] = new byte[1024];
int n, total=0;
// max 5 seconds to wait for new request
s.setSoTimeout(5000);
try {
do {
// max 0.5 seconds between each segment
// of request.
s.setSoTimeout(500);
if (n > 0) total += n;
} while (n > 0);
} catch (SocketTimeoutException e) { }
if (total == 0) {
s.close();
return;
}
boolean getRequest = false;
if (b[0] == 'G' && b[1] == 'E' && b[2] == 'T')
getRequest = true;
synchronized (counterLock) {
if (getRequest)
getCount++;
else
headCount++;
}
// response to client
new BufferedOutputStream(
s.getOutputStream() ));
if (getRequest) {
for (int i=0; i<75*1000; i++) {
}
}
} // for
} catch (Exception e) {
unexpected(e);
} finally {
}
}
}
}
public void run() {
try {
// shutdown if no request in 10 seconds.
for (;;) {
}
} catch (Exception e) {
}
}
e.printStackTrace();
}
return svr;
svr = new HttpServer();
return svr;
}
}
}
public int port() {
return ss.getLocalPort();
}
public static class Counters {
public void reset() {
synchronized (counterLock) {
getCount = 0;
headCount = 0;
}
}
public int getCount() {
synchronized (counterLock) {
return getCount;
}
}
public int headCount() {
synchronized (counterLock) {
return headCount;
}
}
synchronized (counterLock) {
"HEAD count: " + headCount;
}
}
}
return cnts;
}
}
boolean failed = false;
// create http server
// create class loader
// Test 1 - check that getResource does single HEAD request
failed = true;
}
// Test 2 - check that getResourceAsStream does at most
// one GET request
failed = true;
}
// Test 3 - check that getResources only does HEAD requests
try {
for (;;) {
e.nextElement();
}
} catch (NoSuchElementException exc) { }
failed = true;
}
// shutdown http server
if (failed) {
throw new Exception("Excessive http connections established - Test failed");
}
}
}