24
24
import java .net .Proxy ;
25
25
import java .net .URI ;
26
26
import java .util .Collections ;
27
- import java .util .List ;
27
+ import java .util .Map ;
28
28
import lombok .extern .slf4j .Slf4j ;
29
- import org .javatuples .Pair ;
30
29
import software .amazon .cloudwatchlogs .emf .exception .EMFClientException ;
31
30
import software .amazon .cloudwatchlogs .emf .util .IOUtils ;
32
31
import software .amazon .cloudwatchlogs .emf .util .Jackson ;
@@ -36,21 +35,21 @@ public class ResourceFetcher {
36
35
37
36
/** Fetch a json object from a given uri and deserialize it to the specified class: clazz. */
38
37
<T > T fetch (URI endpoint , Class <T > clazz ) {
39
- String response = doReadResource (endpoint , "GET" , Collections .emptyList ());
38
+ String response = doReadResource (endpoint , "GET" , Collections .emptyMap ());
40
39
return Jackson .fromJsonString (response , clazz );
41
40
}
42
41
43
42
/**
44
43
* Request a json object from a given uri with the provided headers and deserialize it to the
45
44
* specified class: clazz.
46
45
*/
47
- <T > T fetch (URI endpoint , String method , Class <T > clazz , List < Pair < String , String > > headers ) {
46
+ <T > T fetch (URI endpoint , String method , Class <T > clazz , Map < String , String > headers ) {
48
47
String response = doReadResource (endpoint , method , headers );
49
48
return Jackson .fromJsonString (response , clazz );
50
49
}
51
50
52
51
/** Request a string from a given uri with the provided headers */
53
- String fetch (URI endpoint , String method , List < Pair < String , String > > headers ) {
52
+ String fetch (URI endpoint , String method , Map < String , String > headers ) {
54
53
return doReadResource (endpoint , method , headers );
55
54
}
56
55
@@ -59,11 +58,11 @@ String fetch(URI endpoint, String method, List<Pair<String, String>> headers) {
59
58
* Jackson ObjectMapper.
60
59
*/
61
60
<T > T fetch (URI endpoint , ObjectMapper objectMapper , Class <T > clazz ) {
62
- String response = doReadResource (endpoint , "GET" , Collections .emptyList ());
61
+ String response = doReadResource (endpoint , "GET" , Collections .emptyMap ());
63
62
return Jackson .fromJsonString (response , objectMapper , clazz );
64
63
}
65
64
66
- private String doReadResource (URI endpoint , String method , List < Pair < String , String > > headers ) {
65
+ private String doReadResource (URI endpoint , String method , Map < String , String > headers ) {
67
66
InputStream inputStream = null ;
68
67
try {
69
68
HttpURLConnection connection = connectToEndpoint (endpoint , method , headers );
@@ -122,15 +121,17 @@ private void handleErrorResponse(InputStream errorStream, String responseMessage
122
121
}
123
122
124
123
private HttpURLConnection connectToEndpoint (
125
- URI endpoint , String method , List < Pair < String , String > > headers ) throws IOException {
124
+ URI endpoint , String method , Map < String , String > headers ) throws IOException {
126
125
HttpURLConnection connection =
127
126
(HttpURLConnection ) endpoint .toURL ().openConnection (Proxy .NO_PROXY );
128
127
connection .setConnectTimeout (1000 );
129
128
connection .setReadTimeout (1000 );
130
129
connection .setRequestMethod (method );
131
130
connection .setDoOutput (true );
132
- headers .forEach (
133
- header -> connection .setRequestProperty (header .getValue0 (), header .getValue1 ()));
131
+
132
+ for (Map .Entry <String , String > header : headers .entrySet ()) {
133
+ connection .setRequestProperty (header .getKey (), header .getValue ());
134
+ }
134
135
135
136
connection .connect ();
136
137
0 commit comments