summaryrefslogtreecommitdiff
path: root/src/main/java/com/mavlushechka/a1qa/utils/HttpUrlConnectionFactory.java
blob: 25d3a909b1713814c036e191af59a90a9ad4ec9e (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
package com.mavlushechka.a1qa.utils;

import com.mavlushechka.a1qa.constants.RequestMethod;

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(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;
    }

}