package com.mavlushechka.a1qa.driverUtils; import com.mavlushechka.a1qa.constants.RequestMethod; 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, RequestMethod requestMethod, boolean doOutput) throws IOException { HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(JSONParser.parseData("config", "browser.url") + spec).openConnection(); httpURLConnection.setRequestMethod(requestMethod.name()); 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; } }