summaryrefslogtreecommitdiff
path: root/src/main/java/com/mavlushechka/a1qa/driverUtils/HttpURLConnectionFactory.java
blob: 13145c49d9df8006031cf00f82df90ffb58b6bff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
    }

}