From f96cd95a94f1244fffc7ca7b4f44b559ffbe77a9 Mon Sep 17 00:00:00 2001 From: Simon Stewart Date: Tue, 11 Apr 2017 22:43:58 +0100 Subject: [PATCH] Revert cabc6b34e53863afdea856c7157f4698ed0f49c0 Restore the use of our own abstractions and keep the visibility of the httpcomponents as limited as possible. --- .../test/org/openqa/selenium/environment/BUCK | 2 +- .../environment/webserver/JettyAppServer.java | 25 +++++++++++-------- third_party/java/httpcomponents/BUCK | 2 -- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/java/client/test/org/openqa/selenium/environment/BUCK b/java/client/test/org/openqa/selenium/environment/BUCK index a0cc37f909714..677623c760108 100644 --- a/java/client/test/org/openqa/selenium/environment/BUCK +++ b/java/client/test/org/openqa/selenium/environment/BUCK @@ -2,12 +2,12 @@ java_library(name = 'environment', srcs = glob(['*.java', 'webserver/*.java'], excludes = ['**/*Test.java']), deps = [ '//java/client/src/org/openqa/selenium:selenium', + '//java/client/src/org/openqa/selenium/remote:remote', '//java/client/test/org/openqa/selenium/testing:helpers', '//third_party/java/commons-fileupload:commons-fileupload', '//third_party/java/gson:gson', '//third_party/java/guava:guava', '//third_party/java/httpcomponents:httpclient', - '//third_party/java/httpcomponents:httpcore', '//third_party/java/jetty:jetty', '//third_party/java/servlet:servlet-api', ], diff --git a/java/client/test/org/openqa/selenium/environment/webserver/JettyAppServer.java b/java/client/test/org/openqa/selenium/environment/webserver/JettyAppServer.java index 2c04b6399a7c4..9279fe95d69fb 100644 --- a/java/client/test/org/openqa/selenium/environment/webserver/JettyAppServer.java +++ b/java/client/test/org/openqa/selenium/environment/webserver/JettyAppServer.java @@ -18,6 +18,7 @@ package org.openqa.selenium.environment.webserver; import static com.google.common.base.Charsets.UTF_8; +import static com.google.common.net.HttpHeaders.CONTENT_LENGTH; import static com.google.common.net.HttpHeaders.CONTENT_TYPE; import static com.google.common.net.MediaType.JSON_UTF_8; import static org.openqa.selenium.net.PortProber.findFreePort; @@ -26,14 +27,13 @@ import com.google.common.collect.ImmutableList; import com.google.gson.JsonObject; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; import org.openqa.selenium.io.TemporaryFilesystem; import org.openqa.selenium.net.NetworkUtils; +import org.openqa.selenium.remote.http.HttpClient; +import org.openqa.selenium.remote.http.HttpMethod; +import org.openqa.selenium.remote.http.HttpRequest; +import org.openqa.selenium.remote.http.HttpResponse; +import org.openqa.selenium.remote.internal.ApacheHttpClient; import org.openqa.selenium.testing.InProject; import org.seleniumhq.jetty9.http.HttpVersion; import org.seleniumhq.jetty9.http.MimeTypes; @@ -54,7 +54,10 @@ import org.seleniumhq.jetty9.util.ssl.SslContextFactory; import java.io.File; +import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; +import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.util.EnumSet; @@ -199,12 +202,12 @@ public String create(Page page) { converted.addProperty("content", page.toString()); byte[] data = converted.toString().getBytes(UTF_8); - CloseableHttpClient client = HttpClients.createDefault(); - HttpPost request = new HttpPost(whereIs("/common/createPage")); - request.setEntity(new ByteArrayEntity(data)); + HttpClient client = new ApacheHttpClient.Factory().createClient(new URL(whereIs("/"))); + HttpRequest request = new HttpRequest(HttpMethod.POST, "/common/createPage"); request.setHeader(CONTENT_TYPE, JSON_UTF_8.toString()); - CloseableHttpResponse response = client.execute(request); - return EntityUtils.toString(response.getEntity()); + request.setContent(data); + HttpResponse response = client.execute(request, true); + return response.getContentString(); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/third_party/java/httpcomponents/BUCK b/third_party/java/httpcomponents/BUCK index 1e291a3ba9ea3..e30e1d04cce6f 100644 --- a/third_party/java/httpcomponents/BUCK +++ b/third_party/java/httpcomponents/BUCK @@ -25,8 +25,6 @@ prebuilt_jar( visibility = [ # Only made visible because of a bug in prebuilt_jar not exporting deps '//java/client/src/org/openqa/selenium/remote:remote-lib', - '//java/client/test/...', - '//java/server/test/...', ], )