|
18 | 18 | package org.openqa.selenium.environment.webserver; |
19 | 19 |
|
20 | 20 | import static com.google.common.base.Charsets.UTF_8; |
21 | | -import static com.google.common.net.HttpHeaders.CONTENT_LENGTH; |
22 | 21 | import static com.google.common.net.HttpHeaders.CONTENT_TYPE; |
23 | 22 | import static com.google.common.net.MediaType.JSON_UTF_8; |
24 | 23 | import static org.openqa.selenium.net.PortProber.findFreePort; |
|
27 | 26 | import com.google.common.collect.ImmutableList; |
28 | 27 | import com.google.gson.JsonObject; |
29 | 28 |
|
| 29 | +import org.apache.http.client.methods.CloseableHttpResponse; |
| 30 | +import org.apache.http.client.methods.HttpPost; |
| 31 | +import org.apache.http.entity.ByteArrayEntity; |
| 32 | +import org.apache.http.impl.client.CloseableHttpClient; |
| 33 | +import org.apache.http.impl.client.HttpClients; |
| 34 | +import org.apache.http.util.EntityUtils; |
30 | 35 | import org.openqa.selenium.io.TemporaryFilesystem; |
31 | 36 | import org.openqa.selenium.net.NetworkUtils; |
32 | | -import org.openqa.selenium.remote.http.HttpClient; |
33 | | -import org.openqa.selenium.remote.http.HttpMethod; |
34 | | -import org.openqa.selenium.remote.http.HttpRequest; |
35 | | -import org.openqa.selenium.remote.http.HttpResponse; |
36 | | -import org.openqa.selenium.remote.internal.ApacheHttpClient; |
37 | 37 | import org.openqa.selenium.testing.InProject; |
38 | 38 | import org.seleniumhq.jetty9.http.HttpVersion; |
39 | 39 | import org.seleniumhq.jetty9.http.MimeTypes; |
|
54 | 54 | import org.seleniumhq.jetty9.util.ssl.SslContextFactory; |
55 | 55 |
|
56 | 56 | import java.io.File; |
57 | | -import java.io.FileWriter; |
58 | 57 | import java.io.IOException; |
59 | | -import java.io.Writer; |
60 | | -import java.net.URL; |
61 | 58 | import java.nio.file.Files; |
62 | 59 | import java.nio.file.Path; |
63 | 60 | import java.util.EnumSet; |
@@ -200,16 +197,14 @@ public String create(Page page) { |
200 | 197 | try { |
201 | 198 | JsonObject converted = new JsonObject(); |
202 | 199 | converted.addProperty("content", page.toString()); |
203 | | - HttpClient |
204 | | - client = |
205 | | - new ApacheHttpClient.Factory().createClient(new URL(whereIs("/"))); |
206 | | - HttpRequest request = new HttpRequest(HttpMethod.POST, "/common/createPage"); |
207 | 200 | byte[] data = converted.toString().getBytes(UTF_8); |
208 | | - request.setHeader(CONTENT_LENGTH, String.valueOf(data.length)); |
| 201 | + |
| 202 | + CloseableHttpClient client = HttpClients.createDefault(); |
| 203 | + HttpPost request = new HttpPost(whereIs("/common/createPage")); |
| 204 | + request.setEntity(new ByteArrayEntity(data)); |
209 | 205 | request.setHeader(CONTENT_TYPE, JSON_UTF_8.toString()); |
210 | | - request.setContent(data); |
211 | | - HttpResponse response = client.execute(request, true); |
212 | | - return response.getContentString(); |
| 206 | + CloseableHttpResponse response = client.execute(request); |
| 207 | + return EntityUtils.toString(response.getEntity()); |
213 | 208 | } catch (IOException ex) { |
214 | 209 | throw new RuntimeException(ex); |
215 | 210 | } |
|
0 commit comments