Skip to content

Commit 3cc5564

Browse files
committedApr 5, 2022
Create a new connection on every request
1 parent dd29d3c commit 3cc5564

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed
 

‎src/main/java/com/yosep/client/CallerController.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import org.springframework.web.bind.annotation.GetMapping;
77
import org.springframework.web.bind.annotation.RestController;
88
import org.springframework.web.client.RestTemplate;
9+
import org.springframework.http.HttpHeaders;
10+
import org.springframework.http.HttpEntity;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.http.HttpMethod;
913

1014
import java.text.SimpleDateFormat;
1115
import java.util.Calendar;
@@ -26,7 +30,14 @@ public String call() {
2630

2731
System.out.println("URL: " + backendUrl);
2832

29-
String response = restTemplate.getForObject(backendUrl + "/hello", String.class);
33+
HttpHeaders headers = new HttpHeaders();
34+
headers.set("Keep-Alive", "timeout=0");
35+
headers.set("Connection", "close");
36+
HttpEntity<Void> requestEntity = new HttpEntity<>(headers);
37+
38+
ResponseEntity<String> response = restTemplate.exchange(
39+
backendUrl + "/hello", HttpMethod.GET, requestEntity, String.class);
40+
3041
return new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime()) + ", " + env.getProperty("vcap.application.instance_id") + ", " + response;
3142
}
32-
}
43+
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#backend.url=http://backend-app.apps.internal:8080
2-
backend.url=https://backend-app.apps.dhaka.cf-app.com
1+
backend.url=http://c2c-backend.apps.internal:8080
2+
#backend.url=https://backend-app.apps.dhaka.cf-app.com

0 commit comments

Comments
 (0)
Please sign in to comment.