Skip to content

Commit 22722f6

Browse files
author
Frank Oh
committed
added retry httpclient example
1 parent 3f32f2e commit 22722f6

3 files changed

Lines changed: 27 additions & 28 deletions

File tree

httpclient/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@
102102
<artifactId>fluent-hc</artifactId>
103103
<version>4.3.2</version>
104104
</dependency>
105-
<dependency>
106-
<groupId>org.mock-server</groupId>
107-
<artifactId>mockserver-netty</artifactId>
108-
<version>5.5.1</version>
109-
</dependency>
105+
<!--<dependency>-->
106+
<!--<groupId>org.mock-server</groupId>-->
107+
<!--<artifactId>mockserver-netty</artifactId>-->
108+
<!--<version>5.5.1</version>-->
109+
<!--</dependency>-->
110110
<dependency>
111111
<groupId>org.hamcrest</groupId>
112112
<artifactId>hamcrest-core</artifactId>

httpclient/src/main/java/com/examples/RetryableHttpFetcher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ public long getRetryInterval() {
4949
log.info("[FRANK] retryRequest(): exception={}, executionCount={}, maxRetries={}", e.getClass(), executionCount, MAX_RETRIES);
5050

5151
if (executionCount > MAX_RETRIES) {
52-
log.info("[FRANK] give up: {0}", executionCount);
52+
log.info("[FRANK] give up: {}", executionCount);
5353
return false;
5454
}
5555

5656
if (e instanceof java.net.SocketTimeoutException) {
57-
log.info("[FRANK] retry: {0}", e.getMessage());
57+
log.info("[FRANK] retry: {}", e.getMessage());
5858
return true;
5959
}
6060

61-
log.info("[FRANK] not retry: {0}", e.getMessage());
61+
log.info("[FRANK] not retry: {}", e.getMessage());
6262
return false;
6363
};
6464

httpclient/src/test/java/com/concretepage/controller/HttpClientTest.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.apache.http.impl.client.CloseableHttpClient;
1111
import org.apache.http.impl.client.HttpClients;
1212
import org.junit.Test;
13-
import org.mockserver.integration.ClientAndServer;
1413

1514
import java.io.BufferedReader;
1615
import java.io.IOException;
@@ -25,24 +24,24 @@
2524

2625
@Slf4j
2726
public class HttpClientTest {
28-
private ClientAndServer mockServer;
29-
30-
// @Before
31-
// public void startMockServer() {
32-
// startClientAndServer(1080)
33-
// .when(request("POST")
34-
// .withMethod("/data/saveJson/123")
35-
// )
36-
// .respond(
37-
// response()
38-
// .withBody("sdf")
39-
// );
40-
// }
41-
//
42-
// @After
43-
// public void stopMockServer() {
44-
// mockServer.stop();
45-
// }
27+
// private ClientAndServer mockServer;
28+
29+
// @Before
30+
// public void startMockServer() {
31+
// startClientAndServer(1080)
32+
// .when(request("POST")
33+
// .withMethod("/data/saveJson/123")
34+
// )
35+
// .respond(
36+
// response()
37+
// .withBody("sdf")
38+
// );
39+
// }
40+
//
41+
// @After
42+
// public void stopMockServer() {
43+
// mockServer.stop();
44+
// }
4645

4746
@Test
4847
public void testHttpUrlConnection() {
@@ -92,7 +91,7 @@ public void testHttpClient() throws IOException {
9291

9392
HttpPost httpPost = new HttpPost(requestUrl);
9493

95-
String requestBody = "{ \"status\": \"finished\", \"cdnUrl\": \"http://localhost:8080/cdn\"}";
94+
String requestBody = "{ \"transStatus\": \"finished\", \"cdnUrl\": \"http://localhost:8080/cdn\"}";
9695
StringEntity entity = new StringEntity(requestBody);
9796

9897
httpPost.setEntity(entity);

0 commit comments

Comments
 (0)