in wagon-provider-test/src/main/java/org/apache/maven/wagon/http/HttpWagonTestCase.java [1077:1129]
private void runTestProxiedRequestWithProvider(ProxyInfoProvider proxyInfoProvider, TestHeaderHandler handler)
throws Exception {
// what an UGLY hack!
// but apparently jetty needs some time to free up resources
// <5s: broken test :(
// CHECKSTYLE_OFF: MagicNumber
Thread.sleep(5001L);
// CHECKSTYLE_ON: MagicNumber
Server proxyServer = new Server();
ServerConnector serverConnector =
new ServerConnector(proxyServer, new HttpConnectionFactory(new HttpConfiguration()));
proxyServer.addConnector(serverConnector);
proxyServer.setHandler(handler);
proxyServer.start();
proxyInfoProvider.getProxyInfo(null).setPort(getLocalPort(proxyServer));
System.out.println("start proxy on host/port "
+ proxyInfoProvider.getProxyInfo(null).getHost() + "/"
+ proxyInfoProvider.getProxyInfo(null).getPort() + " with non proxyHosts "
+ proxyInfoProvider.getProxyInfo(null).getNonProxyHosts());
while (!proxyServer.isRunning() || !proxyServer.isStarted()) {
Thread.sleep(10);
}
try {
StreamingWagon wagon = (StreamingWagon) getWagon();
Repository testRepository = new Repository("id", "http://www.example.com/");
String localRepositoryPath = FileTestUtils.getTestOutputDir().toString();
File sourceFile = new File(localRepositoryPath, "test-proxied-resource");
FileUtils.fileWrite(sourceFile.getAbsolutePath(), "content");
wagon.connect(testRepository, proxyInfoProvider);
try {
wagon.getToStream("test-proxied-resource", new ByteArrayOutputStream());
assertTrue(handler.headers.containsKey("Proxy-Connection"));
} finally {
System.setProperty("http.proxyHost", "");
System.setProperty("http.proxyPort", "");
wagon.disconnect();
}
} finally {
proxyServer.stop();
}
}