Replace com.sun.net.httpserver.Http/Https server usages with MockHttpServer. (elastic/elasticsearch#4476)

Original commit: elastic/x-pack-elasticsearch@4b2d184f53
This commit is contained in:
Tim B 2017-01-05 11:29:31 -06:00 committed by GitHub
parent b72dd8a2d1
commit f71733ec4d
2 changed files with 4 additions and 2 deletions

View File

@ -52,6 +52,7 @@ dependencies {
// common test deps
testCompile 'org.elasticsearch:securemock:1.2'
testCompile "org.elasticsearch:mocksocket:${versions.mocksocket}"
testCompile 'org.slf4j:slf4j-log4j12:1.6.2'
testCompile 'org.slf4j:slf4j-api:1.6.2'
}

View File

@ -19,6 +19,7 @@ import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.mocksocket.MockHttpServer;
import javax.net.ssl.SSLContext;
import java.io.Closeable;
@ -83,11 +84,11 @@ public class MockWebServer implements Closeable {
public void start() throws IOException {
InetSocketAddress address = new InetSocketAddress(InetAddress.getLoopbackAddress().getHostAddress(), 0);
if (sslContext != null) {
HttpsServer httpsServer = HttpsServer.create(address, 0);
HttpsServer httpsServer = MockHttpServer.createHttps(address, 0);
httpsServer.setHttpsConfigurator(new CustomHttpsConfigurator(sslContext, needClientAuth));
server = httpsServer;
} else {
server = HttpServer.create(address, 0);
server = MockHttpServer.createHttp(address, 0);
}
server.start();