File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed
src/main/java/com/ericsson/eiffelcommons/utils Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public final class HttpExecutor {
30
30
private CloseableHttpClient client = HttpClientBuilder .create ()
31
31
.build ();
32
32
33
- private HttpExecutor () {
33
+ public HttpExecutor () {
34
34
35
35
}
36
36
Original file line number Diff line number Diff line change 41
41
public class HttpRequest {
42
42
43
43
private HttpRequestBase request ;
44
- private HttpExecutor executor = HttpExecutor . getInstance () ;
44
+ private HttpExecutor executor ;
45
45
46
46
public enum HttpMethod {
47
47
GET , POST , DELETE , PUT
@@ -57,6 +57,10 @@ public enum HttpMethod {
57
57
protected Map <String , String > params ;
58
58
59
59
public HttpRequest (HttpMethod method ) {
60
+ this (method , false );
61
+ }
62
+
63
+ public HttpRequest (HttpMethod method , boolean persistentClient ) {
60
64
params = new HashMap <>();
61
65
62
66
switch (method ) {
@@ -73,6 +77,16 @@ public HttpRequest(HttpMethod method) {
73
77
request = new HttpPut ();
74
78
break ;
75
79
}
80
+
81
+ initExecutor (persistentClient );
82
+ }
83
+
84
+ private void initExecutor (boolean persistentClient ) {
85
+ if (persistentClient ) {
86
+ executor = HttpExecutor .getInstance ();
87
+ } else {
88
+ executor = new HttpExecutor ();
89
+ }
76
90
}
77
91
78
92
/**
Original file line number Diff line number Diff line change 29
29
public class ResponseEntity {
30
30
31
31
private int statusCode ;
32
- private String body ;
32
+ private String body = "" ;
33
33
private Header [] headers ;
34
34
35
35
/**
@@ -42,7 +42,9 @@ public class ResponseEntity {
42
42
public ResponseEntity (HttpResponse httpResponse ) throws ParseException , IOException {
43
43
this .statusCode = httpResponse .getStatusLine ()
44
44
.getStatusCode ();
45
- this .body = EntityUtils .toString (httpResponse .getEntity (), "utf-8" );
45
+ if (httpResponse .getEntity () != null ) {
46
+ this .body = EntityUtils .toString (httpResponse .getEntity (), "utf-8" );
47
+ }
46
48
this .headers = httpResponse .getAllHeaders ();
47
49
}
48
50
You can’t perform that action at this time.
0 commit comments