-
Notifications
You must be signed in to change notification settings - Fork 1
/
HttpUtils.groovy
30 lines (25 loc) · 955 Bytes
/
HttpUtils.groovy
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
27
28
29
30
package helloService
import groovy.json.JsonSlurper
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpGet
import org.apache.http.client.methods.HttpUriRequest
import org.apache.http.impl.client.HttpClients
class HttpUtils {
def static doGetRequest(String path) {
def HttpGet get = new HttpGet(pathToURL(path));
doHttpRequest(get)
}
def static doHttpRequest(HttpUriRequest request) {
HttpClients.custom()
.build().withCloseable() { client ->
CloseableHttpResponse response = client.execute(request)
response.getEntity().content.withCloseable { i ->
return new JsonSlurper().parse(new InputStreamReader(i))
}
}
}
def static pathToURL(String path){
String urlRoot = System.getProperty("HELLO_SERVICE_ROOT") ?: "http://localhost:8080"
return "$urlRoot$path"
}
}