summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMavlushechka <mavlushechka@gmail.com>2022-09-28 21:23:19 +0500
committerMavlushechka <mavlushechka@gmail.com>2022-09-28 21:23:19 +0500
commitde2f539bbc7fb40822f3bc05db54fe4f50800f8a (patch)
treee13762a88111d9c3d9e59c661fd4a1a838f16732 /src/main
parent9895c7f4fdddd3ab8f4723c2696bdf190c8cf554 (diff)
Create HttpURLConnectionFactory driver utility class
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/mavlushechka/a1qa/driverUtils/HttpURLConnectionFactory.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/driverUtils/HttpURLConnectionFactory.java b/src/main/java/com/mavlushechka/a1qa/driverUtils/HttpURLConnectionFactory.java
new file mode 100644
index 0000000..6b60b64
--- /dev/null
+++ b/src/main/java/com/mavlushechka/a1qa/driverUtils/HttpURLConnectionFactory.java
@@ -0,0 +1,25 @@
+package com.mavlushechka.a1qa.driverUtils;
+
+import com.mavlushechka.a1qa.utils.JSONParser;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class HttpURLConnectionFactory {
+
+ private HttpURLConnectionFactory() {
+ }
+
+ public static HttpURLConnection createHttpURLConnection(String spec, String requestMethod, boolean doOutput) throws IOException {
+ HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(JSONParser.parseData("config", "browser.url") + spec).openConnection();
+
+ httpURLConnection.setRequestMethod(requestMethod);
+ httpURLConnection.setConnectTimeout(Integer.parseInt(JSONParser.parseData("config", "httpURLConnection.connectTimeout")));
+ httpURLConnection.setReadTimeout(Integer.parseInt(JSONParser.parseData("config", "httpURLConnection.readTimeout")));
+ httpURLConnection.setDoOutput(doOutput);
+ httpURLConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
+ return httpURLConnection;
+ }
+
+}