From 5a3867dd62a5105f2accd1b14fa4be32f4d5a68f Mon Sep 17 00:00:00 2001 From: Rubini Date: Fri, 1 Dec 2023 21:20:31 +0530 Subject: [PATCH 01/12] Implementing retry logic to restTemplate --- .../libraries/resttemplate/ApiClient.mustache | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index 383a4904c8ec..f080b62695bb 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -721,7 +721,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { RequestEntity requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); - ResponseEntity responseEntity = restTemplate.exchange(requestEntity, returnType); + ResponseEntity responseEntity = makeServiceCallWithRetry(requestEntity, returnType, 3, 10); if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity; @@ -873,5 +873,27 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { bufferedReader.close(); return builder.toString(); } + + public ResponseEntity makeServiceCallWithRetry(RequestEntity requestEntity, ParameterizedTypeReference returnType, int maxAttempts, long waitTimeMillis) { + int attempts = 0; + ResponseEntity response = null; + + while (attempts < maxAttempts) { + try { + response = restTemplate.exchange(requestEntity, returnType); + break; + } + catch (HttpServerErrorException ex) { + if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { + throw ex; + } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } } } From 2674ac4dd6456e8702a3184e991714e4c0190bbb Mon Sep 17 00:00:00 2001 From: Rubini Date: Fri, 1 Dec 2023 22:06:09 +0530 Subject: [PATCH 02/12] Fixing the issue --- .../libraries/resttemplate/ApiClient.mustache | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index f080b62695bb..12ff4db10d97 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -874,26 +874,29 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { return builder.toString(); } - public ResponseEntity makeServiceCallWithRetry(RequestEntity requestEntity, ParameterizedTypeReference returnType, int maxAttempts, long waitTimeMillis) { - int attempts = 0; - ResponseEntity response = null; - - while (attempts < maxAttempts) { - try { - response = restTemplate.exchange(requestEntity, returnType); - break; - } - catch (HttpServerErrorException ex) { - if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; - } - attempts++; - if (attempts < maxAttempts) { - try { - Thread.sleep(waitTimeMillis); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } + public ResponseEntity makeServiceCallWithRetry(RequestEntity requestEntity, ParameterizedTypeReference returnType, int maxAttempts, long waitTimeMillis) { + int attempts = 0; + ResponseEntity response = null; + while (attempts < maxAttempts) { + try { + response = restTemplate.exchange(requestEntity, returnType); + break; + } + catch (HttpServerErrorException ex) { + if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { + throw ex; + } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } + } } } From af72aca92f4b0827eea85ffdc1c4fe343f79f455 Mon Sep 17 00:00:00 2001 From: Rubini Date: Fri, 1 Dec 2023 22:48:42 +0530 Subject: [PATCH 03/12] Adding import --- .../libraries/resttemplate/ApiClient.mustache | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index 12ff4db10d97..eabf7793a5f1 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -31,6 +31,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -721,7 +722,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { RequestEntity requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); - ResponseEntity responseEntity = makeServiceCallWithRetry(requestEntity, returnType, 3, 10); + ResponseEntity responseEntity = makeServiceCallWithRetry(requestEntity, returnType, 3, 10l); if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity; @@ -874,7 +875,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { return builder.toString(); } - public ResponseEntity makeServiceCallWithRetry(RequestEntity requestEntity, ParameterizedTypeReference returnType, int maxAttempts, long waitTimeMillis) { + private ResponseEntity makeServiceCallWithRetry(RequestEntity requestEntity, ParameterizedTypeReference returnType, int maxAttempts, long waitTimeMillis) { int attempts = 0; ResponseEntity response = null; while (attempts < maxAttempts) { @@ -884,17 +885,17 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { } catch (HttpServerErrorException ex) { if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; - } - attempts++; - if (attempts < maxAttempts) { - try { - Thread.sleep(waitTimeMillis); - } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } + throw ex; } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } } } } From 0aa4c6f7ce70b6c988634e4565b231ae1b6d7203 Mon Sep 17 00:00:00 2001 From: Rubini Date: Fri, 8 Dec 2023 20:05:11 +0530 Subject: [PATCH 04/12] Fix --- .../libraries/resttemplate/ApiClient.mustache | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index eabf7793a5f1..5587882f885f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -722,7 +722,30 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { RequestEntity requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); - ResponseEntity responseEntity = makeServiceCallWithRetry(requestEntity, returnType, 3, 10l); + ResponseEntity responseEntity = null; + int attempts = 0; + int maxAttempts = 3; + int waitTimeMillis = 10l; + while (attempts < maxAttempts) { + try { + responseEntity = restTemplate.exchange(requestEntity, returnType); + break; + } + catch (HttpServerErrorException ex) { + if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { + throw ex; + } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity; @@ -874,30 +897,5 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { bufferedReader.close(); return builder.toString(); } - - private ResponseEntity makeServiceCallWithRetry(RequestEntity requestEntity, ParameterizedTypeReference returnType, int maxAttempts, long waitTimeMillis) { - int attempts = 0; - ResponseEntity response = null; - while (attempts < maxAttempts) { - try { - response = restTemplate.exchange(requestEntity, returnType); - break; - } - catch (HttpServerErrorException ex) { - if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; - } - attempts++; - if (attempts < maxAttempts) { - try { - Thread.sleep(waitTimeMillis); - } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - } - } } } From 96ebabdf70fb886e27796af1e420019eae7e9eee Mon Sep 17 00:00:00 2001 From: Rubini Date: Fri, 8 Dec 2023 21:08:27 +0530 Subject: [PATCH 05/12] Fix --- .../resources/Java/libraries/resttemplate/ApiClient.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index 5587882f885f..4701763cde62 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -725,7 +725,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { ResponseEntity responseEntity = null; int attempts = 0; int maxAttempts = 3; - int waitTimeMillis = 10l; + long waitTimeMillis = 10l; while (attempts < maxAttempts) { try { responseEntity = restTemplate.exchange(requestEntity, returnType); From 598a8fc590cfdf9cd55a16fa69bc0b1e07b18a24 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 10 Dec 2023 16:18:51 +0800 Subject: [PATCH 06/12] minor update, add tests --- .../libraries/resttemplate/ApiClient.mustache | 55 +++++++++++++-- .../org/openapitools/client/ApiClient.java | 67 ++++++++++++++++++- .../org/openapitools/client/CustomTest.java | 54 +++++++++++++++ .../org/openapitools/client/ApiClient.java | 67 ++++++++++++++++++- .../org/openapitools/client/ApiClient.java | 67 ++++++++++++++++++- .../org/openapitools/client/ApiClient.java | 67 ++++++++++++++++++- .../org/openapitools/client/ApiClient.java | 67 ++++++++++++++++++- .../org/openapitools/client/ApiClient.java | 67 ++++++++++++++++++- .../org/openapitools/client/ApiClient.java | 67 ++++++++++++++++++- 9 files changed, 564 insertions(+), 14 deletions(-) create mode 100644 samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/CustomTest.java diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index 4701763cde62..09d814882c5c 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -114,6 +114,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { private DateFormat dateFormat; + private int maxAttempts = 3; + + private long waitTimeMillis = 10l; + public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -168,6 +172,46 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { return this; } + /** + * Get the max attempts for retry + * + * @return int the max attempts + */ + public int getMaxAttempts() { + return maxAttempts; + } + + /** + * Set the max attemtps for retry + * + * @param maxAttempts the max attempts for retry + * @return ApiClient this client + */ + public ApiClient setMaxAttempts(int maxAttempts) { + this.maxAttempts = maxAttempts; + return this; + } + + /** + * Get the wait time in milliseconds + * + * @return long wait time in milliseconds + */ + public long getWaitTimeMillis() { + return waitTimeMillis; + } + + /** + * Set the wait time in milliseconds + * + * @param waitTimeMillis the wait time in milliseconds + * @return ApiClient this client + */ + public ApiClient setWaitTimeMillis(long waitTimeMillis) { + this.waitTimeMillis = waitTimeMillis; + return this; + } + /** * Get authentications (key: authentication name, value: authentication). * @@ -724,14 +768,12 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { ResponseEntity responseEntity = null; int attempts = 0; - int maxAttempts = 3; - long waitTimeMillis = 10l; while (attempts < maxAttempts) { try { responseEntity = restTemplate.exchange(requestEntity, returnType); + // request succeeded, no need to retry break; - } - catch (HttpServerErrorException ex) { + } catch (HttpServerErrorException ex) { if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { throw ex; } @@ -739,10 +781,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { if (attempts < maxAttempts) { try { Thread.sleep(waitTimeMillis); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { Thread.currentThread().interrupt(); - } + } } } } diff --git a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index 220e61461c76..7b3ae79576f4 100644 --- a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -22,6 +22,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -87,6 +88,10 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; + private int maxAttempts = 3; + + private long waitTimeMillis = 10l; + public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -136,6 +141,46 @@ public ApiClient setBasePath(String basePath) { return this; } + /** + * Get the max attempts for retry + * + * @return int the max attempts + */ + public int getMaxAttempts() { + return maxAttempts; + } + + /** + * Set the max attemtps for retry + * + * @param maxAttempts the max attempts for retry + * @return ApiClient this client + */ + public ApiClient setMaxAttempts(int maxAttempts) { + this.maxAttempts = maxAttempts; + return this; + } + + /** + * Get the wait time in milliseconds + * + * @return long wait time in milliseconds + */ + public long getWaitTimeMillis() { + return waitTimeMillis; + } + + /** + * Set the wait time in milliseconds + * + * @param waitTimeMillis the wait time in milliseconds + * @return ApiClient this client + */ + public ApiClient setWaitTimeMillis(long waitTimeMillis) { + this.waitTimeMillis = waitTimeMillis; + return this; + } + /** * Get authentications (key: authentication name, value: authentication). * @@ -637,7 +682,27 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); - ResponseEntity responseEntity = restTemplate.exchange(requestEntity, returnType); + ResponseEntity responseEntity = null; + int attempts = 0; + while (attempts < maxAttempts) { + try { + responseEntity = restTemplate.exchange(requestEntity, returnType); + // request succeeded, no need to retry + break; + } catch (HttpServerErrorException ex) { + if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { + throw ex; + } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity; diff --git a/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/CustomTest.java b/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/CustomTest.java new file mode 100644 index 000000000000..0b3827baf4fd --- /dev/null +++ b/samples/client/echo_api/java/resttemplate/src/test/java/org/openapitools/client/CustomTest.java @@ -0,0 +1,54 @@ +/* + * Echo Server API + * Echo Server API + * + * The version of the OpenAPI document: 0.1.0 + * Contact: team@openapitools.oprg + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package org.openapitools.client; + +import org.junit.Assert; +import org.openapitools.client.api.*; +import org.openapitools.client.model.*; +import org.junit.Test; +import org.junit.Ignore; + +import java.io.IOException; +import java.util.*; + + +/** + * API tests + */ +public class CustomTest { + + private final QueryApi api = new QueryApi(); + private final BodyApi bodyApi = new BodyApi(); + + /** + * Test body parameter(s) + *

+ * Test body parameter(s) + * + */ + @Test + public void testEchoBodyPet() { + Pet pet = new Pet().id(12345L).name("Hello World"). + photoUrls(Arrays.asList(new String[]{"http://a.com", "http://b.com"})).category(new Category().id(987L).name("new category")); + + Pet p = bodyApi.testEchoBodyPet(pet); + Assert.assertNotNull(p); + Assert.assertEquals("Hello World", p.getName()); + Assert.assertEquals(Long.valueOf(12345L), p.getId()); + + // response is empty body + Pet p2 = bodyApi.testEchoBodyPet(null); + Assert.assertNull(p2); + } +} diff --git a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java index 6fb215e298d6..639664948a15 100644 --- a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java @@ -22,6 +22,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -85,6 +86,10 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; + private maxAttempts = 3; + + long waitTimeMillis = 10l; + public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -132,6 +137,46 @@ public ApiClient setBasePath(String basePath) { return this; } + /** + * Get the max attempts for retry + * + * @return int the max attempts + */ + public int getMaxAttempts() { + return maxAttempts; + } + + /** + * Set the max attemtps for retry + * + * @param maxAttempts the max attempts for retry + * @return ApiClient this client + */ + public ApiClient setMaxAttempts(int maxAttempts) { + this.maxAttempts = maxAttempts; + return this; + } + + /** + * Get the wait time in milliseconds + * + * @return long wait time in milliseconds + */ + public long getWaitTimeMillis() { + return waitTimeMillis; + } + + /** + * Set the wait time in milliseconds + * + * @param waitTimeMillis the wait time in milliseconds + * @return ApiClient this client + */ + public ApiClient setWaitTimeMillis(long waitTimeMillis) { + this.waitTimeMillis = waitTimeMillis; + return this; + } + /** * Get authentications (key: authentication name, value: authentication). * @@ -580,7 +625,27 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); - ResponseEntity responseEntity = restTemplate.exchange(requestEntity, returnType); + ResponseEntity responseEntity = null; + int attempts = 0; + while (attempts < maxAttempts) { + try { + responseEntity = restTemplate.exchange(requestEntity, returnType); + // request succeeded, no need to retry + break; + } catch (HttpServerErrorException ex) { + if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { + throw ex; + } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity; diff --git a/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java index a58613e725a7..f861126732c1 100644 --- a/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java @@ -22,6 +22,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -87,6 +88,10 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; + private maxAttempts = 3; + + long waitTimeMillis = 10l; + public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -136,6 +141,46 @@ public ApiClient setBasePath(String basePath) { return this; } + /** + * Get the max attempts for retry + * + * @return int the max attempts + */ + public int getMaxAttempts() { + return maxAttempts; + } + + /** + * Set the max attemtps for retry + * + * @param maxAttempts the max attempts for retry + * @return ApiClient this client + */ + public ApiClient setMaxAttempts(int maxAttempts) { + this.maxAttempts = maxAttempts; + return this; + } + + /** + * Get the wait time in milliseconds + * + * @return long wait time in milliseconds + */ + public long getWaitTimeMillis() { + return waitTimeMillis; + } + + /** + * Set the wait time in milliseconds + * + * @param waitTimeMillis the wait time in milliseconds + * @return ApiClient this client + */ + public ApiClient setWaitTimeMillis(long waitTimeMillis) { + this.waitTimeMillis = waitTimeMillis; + return this; + } + /** * Get authentications (key: authentication name, value: authentication). * @@ -629,7 +674,27 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); - ResponseEntity responseEntity = restTemplate.exchange(requestEntity, returnType); + ResponseEntity responseEntity = null; + int attempts = 0; + while (attempts < maxAttempts) { + try { + responseEntity = restTemplate.exchange(requestEntity, returnType); + // request succeeded, no need to retry + break; + } catch (HttpServerErrorException ex) { + if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { + throw ex; + } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity; diff --git a/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java index cfa530eaca27..fa6a922ecfbf 100644 --- a/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java @@ -22,6 +22,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -87,6 +88,10 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; + private maxAttempts = 3; + + long waitTimeMillis = 10l; + public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -136,6 +141,46 @@ public ApiClient setBasePath(String basePath) { return this; } + /** + * Get the max attempts for retry + * + * @return int the max attempts + */ + public int getMaxAttempts() { + return maxAttempts; + } + + /** + * Set the max attemtps for retry + * + * @param maxAttempts the max attempts for retry + * @return ApiClient this client + */ + public ApiClient setMaxAttempts(int maxAttempts) { + this.maxAttempts = maxAttempts; + return this; + } + + /** + * Get the wait time in milliseconds + * + * @return long wait time in milliseconds + */ + public long getWaitTimeMillis() { + return waitTimeMillis; + } + + /** + * Set the wait time in milliseconds + * + * @param waitTimeMillis the wait time in milliseconds + * @return ApiClient this client + */ + public ApiClient setWaitTimeMillis(long waitTimeMillis) { + this.waitTimeMillis = waitTimeMillis; + return this; + } + /** * Get authentications (key: authentication name, value: authentication). * @@ -629,7 +674,27 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); - ResponseEntity responseEntity = restTemplate.exchange(requestEntity, returnType); + ResponseEntity responseEntity = null; + int attempts = 0; + while (attempts < maxAttempts) { + try { + responseEntity = restTemplate.exchange(requestEntity, returnType); + // request succeeded, no need to retry + break; + } catch (HttpServerErrorException ex) { + if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { + throw ex; + } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity; diff --git a/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java index cfa530eaca27..fa6a922ecfbf 100644 --- a/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java @@ -22,6 +22,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -87,6 +88,10 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; + private maxAttempts = 3; + + long waitTimeMillis = 10l; + public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -136,6 +141,46 @@ public ApiClient setBasePath(String basePath) { return this; } + /** + * Get the max attempts for retry + * + * @return int the max attempts + */ + public int getMaxAttempts() { + return maxAttempts; + } + + /** + * Set the max attemtps for retry + * + * @param maxAttempts the max attempts for retry + * @return ApiClient this client + */ + public ApiClient setMaxAttempts(int maxAttempts) { + this.maxAttempts = maxAttempts; + return this; + } + + /** + * Get the wait time in milliseconds + * + * @return long wait time in milliseconds + */ + public long getWaitTimeMillis() { + return waitTimeMillis; + } + + /** + * Set the wait time in milliseconds + * + * @param waitTimeMillis the wait time in milliseconds + * @return ApiClient this client + */ + public ApiClient setWaitTimeMillis(long waitTimeMillis) { + this.waitTimeMillis = waitTimeMillis; + return this; + } + /** * Get authentications (key: authentication name, value: authentication). * @@ -629,7 +674,27 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); - ResponseEntity responseEntity = restTemplate.exchange(requestEntity, returnType); + ResponseEntity responseEntity = null; + int attempts = 0; + while (attempts < maxAttempts) { + try { + responseEntity = restTemplate.exchange(requestEntity, returnType); + // request succeeded, no need to retry + break; + } catch (HttpServerErrorException ex) { + if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { + throw ex; + } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity; diff --git a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java index 6de08db3168b..9c31b53ed7bc 100644 --- a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java @@ -27,6 +27,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -94,6 +95,10 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; + private maxAttempts = 3; + + long waitTimeMillis = 10l; + public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -146,6 +151,46 @@ public ApiClient setBasePath(String basePath) { return this; } + /** + * Get the max attempts for retry + * + * @return int the max attempts + */ + public int getMaxAttempts() { + return maxAttempts; + } + + /** + * Set the max attemtps for retry + * + * @param maxAttempts the max attempts for retry + * @return ApiClient this client + */ + public ApiClient setMaxAttempts(int maxAttempts) { + this.maxAttempts = maxAttempts; + return this; + } + + /** + * Get the wait time in milliseconds + * + * @return long wait time in milliseconds + */ + public long getWaitTimeMillis() { + return waitTimeMillis; + } + + /** + * Set the wait time in milliseconds + * + * @param waitTimeMillis the wait time in milliseconds + * @return ApiClient this client + */ + public ApiClient setWaitTimeMillis(long waitTimeMillis) { + this.waitTimeMillis = waitTimeMillis; + return this; + } + /** * Get authentications (key: authentication name, value: authentication). * @@ -692,7 +737,27 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); - ResponseEntity responseEntity = restTemplate.exchange(requestEntity, returnType); + ResponseEntity responseEntity = null; + int attempts = 0; + while (attempts < maxAttempts) { + try { + responseEntity = restTemplate.exchange(requestEntity, returnType); + // request succeeded, no need to retry + break; + } catch (HttpServerErrorException ex) { + if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { + throw ex; + } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity; diff --git a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index 1dbc33b8f2d5..eb52f3b4703f 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -22,6 +22,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -89,6 +90,10 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; + private maxAttempts = 3; + + long waitTimeMillis = 10l; + public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -141,6 +146,46 @@ public ApiClient setBasePath(String basePath) { return this; } + /** + * Get the max attempts for retry + * + * @return int the max attempts + */ + public int getMaxAttempts() { + return maxAttempts; + } + + /** + * Set the max attemtps for retry + * + * @param maxAttempts the max attempts for retry + * @return ApiClient this client + */ + public ApiClient setMaxAttempts(int maxAttempts) { + this.maxAttempts = maxAttempts; + return this; + } + + /** + * Get the wait time in milliseconds + * + * @return long wait time in milliseconds + */ + public long getWaitTimeMillis() { + return waitTimeMillis; + } + + /** + * Set the wait time in milliseconds + * + * @param waitTimeMillis the wait time in milliseconds + * @return ApiClient this client + */ + public ApiClient setWaitTimeMillis(long waitTimeMillis) { + this.waitTimeMillis = waitTimeMillis; + return this; + } + /** * Get authentications (key: authentication name, value: authentication). * @@ -687,7 +732,27 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); - ResponseEntity responseEntity = restTemplate.exchange(requestEntity, returnType); + ResponseEntity responseEntity = null; + int attempts = 0; + while (attempts < maxAttempts) { + try { + responseEntity = restTemplate.exchange(requestEntity, returnType); + // request succeeded, no need to retry + break; + } catch (HttpServerErrorException ex) { + if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { + throw ex; + } + attempts++; + if (attempts < maxAttempts) { + try { + Thread.sleep(waitTimeMillis); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } if (responseEntity.getStatusCode().is2xxSuccessful()) { return responseEntity; From 6722d4af384ebcee1c4d26b7ede8381a9476458f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 10 Dec 2023 16:22:29 +0800 Subject: [PATCH 07/12] fix --- .../src/main/java/org/openapitools/client/ApiClient.java | 4 ++-- .../src/main/java/org/openapitools/client/ApiClient.java | 4 ++-- .../src/main/java/org/openapitools/client/ApiClient.java | 4 ++-- .../src/main/java/org/openapitools/client/ApiClient.java | 4 ++-- .../src/main/java/org/openapitools/client/ApiClient.java | 4 ++-- .../src/main/java/org/openapitools/client/ApiClient.java | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java index 639664948a15..523784e6cb6e 100644 --- a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java @@ -86,9 +86,9 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private maxAttempts = 3; + private int maxAttempts = 3; - long waitTimeMillis = 10l; + private long waitTimeMillis = 10l; public ApiClient() { this.restTemplate = buildRestTemplate(); diff --git a/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java index f861126732c1..7ff4b47d62d7 100644 --- a/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java @@ -88,9 +88,9 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private maxAttempts = 3; + private int maxAttempts = 3; - long waitTimeMillis = 10l; + private long waitTimeMillis = 10l; public ApiClient() { this.restTemplate = buildRestTemplate(); diff --git a/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java index fa6a922ecfbf..2104aca661fc 100644 --- a/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java @@ -88,9 +88,9 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private maxAttempts = 3; + private int maxAttempts = 3; - long waitTimeMillis = 10l; + private long waitTimeMillis = 10l; public ApiClient() { this.restTemplate = buildRestTemplate(); diff --git a/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java index fa6a922ecfbf..2104aca661fc 100644 --- a/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java @@ -88,9 +88,9 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private maxAttempts = 3; + private int maxAttempts = 3; - long waitTimeMillis = 10l; + private long waitTimeMillis = 10l; public ApiClient() { this.restTemplate = buildRestTemplate(); diff --git a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java index 9c31b53ed7bc..7aae283fb641 100644 --- a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java @@ -95,9 +95,9 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private maxAttempts = 3; + private int maxAttempts = 3; - long waitTimeMillis = 10l; + private long waitTimeMillis = 10l; public ApiClient() { this.restTemplate = buildRestTemplate(); diff --git a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index eb52f3b4703f..c7b73ed4766b 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -90,9 +90,9 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private maxAttempts = 3; + private int maxAttempts = 3; - long waitTimeMillis = 10l; + private long waitTimeMillis = 10l; public ApiClient() { this.restTemplate = buildRestTemplate(); From 3f826f3502408bb1af5df23b9ba190fae4007493 Mon Sep 17 00:00:00 2001 From: Rubini Date: Tue, 12 Dec 2023 12:42:59 +0530 Subject: [PATCH 08/12] Adding the maxRetryAttempt, threadWaitTime as additionalProperty --- .../codegen/CodegenConstants.java | 4 ++ .../codegen/languages/JavaClientCodegen.java | 25 +++++++++ .../libraries/resttemplate/ApiClient.mustache | 53 +++---------------- 3 files changed, 36 insertions(+), 46 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java index 670529a733aa..bbf61339e15b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java @@ -436,4 +436,8 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case, public static final String GENERATE_MARSHAL_JSON = "generateMarshalJSON"; public static final String GENERATE_MARSHAL_JSON_DESC = "Generate MarshalJSON method"; + + public static final String MAX_ATTEMPTS_FOR_RETRY = "maxAttemptsForRetry"; + + public static final String WAIT_TIME_OF_THREAD = "waitTimeMillis"; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 36d1646b18a3..8dfa3cbee3ed 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -139,6 +139,9 @@ public class JavaClientCodegen extends AbstractJavaCodegen protected boolean generateClientAsBean = false; protected boolean useEnumCaseInsensitive = false; + protected int maxAttemptsForRetry = 1; + protected long waitTimeMillis = 10l; + private static class MpRestClientVersion { public final String rootPackage; public final String pomTemplate; @@ -465,6 +468,20 @@ public void processOpts() { if (additionalProperties.containsKey(USE_ENUM_CASE_INSENSITIVE)) { this.setUseEnumCaseInsensitive(Boolean.parseBoolean(additionalProperties.get(USE_ENUM_CASE_INSENSITIVE).toString())); } + + if (additionalProperties.containsKey(CodegenConstants.MAX_ATTEMPTS_FOR_RETRY)) { + this.setMaxAttemptsForRetry(Integer.parseInt(additionalProperties.get(CodegenConstants.MAX_ATTEMPTS_FOR_RETRY).toString())); + } + else { + additionalProperties.put(CodegenConstants.MAX_ATTEMPTS_FOR_RETRY, maxAttemptsForRetry); + } + + if (additionalProperties.containsKey(CodegenConstants.WAIT_TIME_OF_THREAD)) { + this.setWaitTimeMillis(Long.parseLong((additionalProperties.get(CodegenConstants.WAIT_TIME_OF_THREAD).toString()))); + } + else { + additionalProperties.put(CodegenConstants.WAIT_TIME_OF_THREAD, waitTimeMillis); + } writePropertyBack(USE_ENUM_CASE_INSENSITIVE, useEnumCaseInsensitive); final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/"); @@ -1240,6 +1257,14 @@ public void setUseEnumCaseInsensitive(boolean useEnumCaseInsensitive) { this.useEnumCaseInsensitive = useEnumCaseInsensitive; } + public void setMaxAttemptsForRetry(int maxAttemptsForRetry) { + this.maxAttemptsForRetry= maxAttemptsForRetry; + } + + public void setWaitTimeMillis(long waitTimeMillis) { + this.waitTimeMillis= waitTimeMillis; + } + /** * Serialization library. * diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index 09d814882c5c..7ca2c1cbe41f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -106,6 +106,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); + private int maxAttemptsForRetry = {{maxAttemptsForRetry}}; + + private long waitTimeMillis = {{waitTimeMillis}}; + private String basePath = "{{basePath}}"; private RestTemplate restTemplate; @@ -172,46 +176,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { return this; } - /** - * Get the max attempts for retry - * - * @return int the max attempts - */ - public int getMaxAttempts() { - return maxAttempts; - } - - /** - * Set the max attemtps for retry - * - * @param maxAttempts the max attempts for retry - * @return ApiClient this client - */ - public ApiClient setMaxAttempts(int maxAttempts) { - this.maxAttempts = maxAttempts; - return this; - } - - /** - * Get the wait time in milliseconds - * - * @return long wait time in milliseconds - */ - public long getWaitTimeMillis() { - return waitTimeMillis; - } - - /** - * Set the wait time in milliseconds - * - * @param waitTimeMillis the wait time in milliseconds - * @return ApiClient this client - */ - public ApiClient setWaitTimeMillis(long waitTimeMillis) { - this.waitTimeMillis = waitTimeMillis; - return this; - } - /** * Get authentications (key: authentication name, value: authentication). * @@ -768,17 +732,14 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { ResponseEntity responseEntity = null; int attempts = 0; - while (attempts < maxAttempts) { + while (attempts < maxAttemptsForRetry) { try { responseEntity = restTemplate.exchange(requestEntity, returnType); - // request succeeded, no need to retry break; - } catch (HttpServerErrorException ex) { - if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; } + catch (HttpServerErrorException ex) { attempts++; - if (attempts < maxAttempts) { + if (attempts < maxAttemptsForRetry) { try { Thread.sleep(waitTimeMillis); } catch (InterruptedException e) { From 72dddb4e0325284efd333b2e5949b8224db9dcb4 Mon Sep 17 00:00:00 2001 From: Rubini Date: Tue, 12 Dec 2023 15:23:02 +0530 Subject: [PATCH 09/12] Updating the apiClient --- .../libraries/resttemplate/ApiClient.mustache | 47 ++++++++++++++++--- .../org/openapitools/client/ApiClient.java | 31 +++++------- .../org/openapitools/client/ApiClient.java | 24 +++++----- .../org/openapitools/client/ApiClient.java | 28 +++++------ .../org/openapitools/client/ApiClient.java | 28 +++++------ .../org/openapitools/client/ApiClient.java | 28 +++++------ .../org/openapitools/client/ApiClient.java | 28 +++++------ .../org/openapitools/client/ApiClient.java | 28 +++++------ 8 files changed, 126 insertions(+), 116 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index 7ca2c1cbe41f..122d534dc634 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -118,10 +118,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { private DateFormat dateFormat; - private int maxAttempts = 3; - - private long waitTimeMillis = 10l; - public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -176,6 +172,46 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { return this; } + /** + * Get the max attempts for retry + * + * @return int the max attempts + */ + public int getMaxAttemptsForRetry() { + return maxAttemptsForRetry; + } + + /** + * Set the max attempts for retry + * + * @param getMaxAttemptsForRetry the max attempts for retry + * @return ApiClient this client + */ + public ApiClient setMaxAttemptsForRetry(int maxAttemptsForRetry) { + this.maxAttemptsForRetry = maxAttemptsForRetry; + return this; + } + + /** + * Get the wait time in milliseconds + * + * @return long wait time in milliseconds + */ + public long getWaitTimeMillis() { + return waitTimeMillis; + } + + /** + * Set the wait time in milliseconds + * + * @param waitTimeMillis the wait time in milliseconds + * @return ApiClient this client + */ + public ApiClient setWaitTimeMillis(long waitTimeMillis) { + this.waitTimeMillis = waitTimeMillis; + return this; + } + /** * Get authentications (key: authentication name, value: authentication). * @@ -736,8 +772,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { try { responseEntity = restTemplate.exchange(requestEntity, returnType); break; - } - catch (HttpServerErrorException ex) { + } catch (HttpServerErrorException ex) { attempts++; if (attempts < maxAttemptsForRetry) { try { diff --git a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index 7b3ae79576f4..631d60760d8d 100644 --- a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -80,6 +80,10 @@ private String collectionToString(Collection collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); + private int maxAttemptsForRetry = 3; + + private long waitTimeMillis = 10l; + private String basePath = "http://localhost:3000"; private RestTemplate restTemplate; @@ -88,10 +92,6 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private int maxAttempts = 3; - - private long waitTimeMillis = 10l; - public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -146,18 +146,18 @@ public ApiClient setBasePath(String basePath) { * * @return int the max attempts */ - public int getMaxAttempts() { - return maxAttempts; + public int getMaxAttemptsForRetry() { + return maxAttemptsForRetry; } /** - * Set the max attemtps for retry + * Set the max attempts for retry * - * @param maxAttempts the max attempts for retry + * @param getMaxAttemptsForRetry the max attempts for retry * @return ApiClient this client */ - public ApiClient setMaxAttempts(int maxAttempts) { - this.maxAttempts = maxAttempts; + public ApiClient setMaxAttemptsForRetry(int maxAttemptsForRetry) { + this.maxAttemptsForRetry = maxAttemptsForRetry; return this; } @@ -180,7 +180,6 @@ public ApiClient setWaitTimeMillis(long waitTimeMillis) { this.waitTimeMillis = waitTimeMillis; return this; } - /** * Get authentications (key: authentication name, value: authentication). * @@ -684,17 +683,13 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map responseEntity = null; int attempts = 0; - while (attempts < maxAttempts) { + while (attempts < maxAttemptsForRetry) { try { responseEntity = restTemplate.exchange(requestEntity, returnType); - // request succeeded, no need to retry break; - } catch (HttpServerErrorException ex) { - if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; - } + } catch (HttpServerErrorException ex) { attempts++; - if (attempts < maxAttempts) { + if (attempts < maxAttemptsForRetry) { try { Thread.sleep(waitTimeMillis); } catch (InterruptedException e) { diff --git a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java index 523784e6cb6e..e396ea408d67 100644 --- a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java @@ -78,6 +78,10 @@ private String collectionToString(Collection collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); + private int maxAttemptsForRetry = 3; + + private long waitTimeMillis = 10l; + private String basePath = "http://localhost"; private RestTemplate restTemplate; @@ -142,18 +146,18 @@ public ApiClient setBasePath(String basePath) { * * @return int the max attempts */ - public int getMaxAttempts() { - return maxAttempts; + public int getMaxAttemptsForRetry() { + return maxAttemptsForRetry; } /** - * Set the max attemtps for retry + * Set the max attempts for retry * - * @param maxAttempts the max attempts for retry + * @param getMaxAttemptsForRetry the max attempts for retry * @return ApiClient this client */ - public ApiClient setMaxAttempts(int maxAttempts) { - this.maxAttempts = maxAttempts; + public ApiClient setMaxAttemptsForRetry(int maxAttemptsForRetry) { + this.maxAttemptsForRetry = maxAttemptsForRetry; return this; } @@ -627,17 +631,13 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map responseEntity = null; int attempts = 0; - while (attempts < maxAttempts) { + while (attempts < maxAttemptsForRetry) { try { responseEntity = restTemplate.exchange(requestEntity, returnType); - // request succeeded, no need to retry break; } catch (HttpServerErrorException ex) { - if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; - } attempts++; - if (attempts < maxAttempts) { + if (attempts < maxAttemptsForRetry) { try { Thread.sleep(waitTimeMillis); } catch (InterruptedException e) { diff --git a/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java index 7ff4b47d62d7..5d1b43c255b7 100644 --- a/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-jakarta/src/main/java/org/openapitools/client/ApiClient.java @@ -80,6 +80,10 @@ private String collectionToString(Collection collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); + private int maxAttemptsForRetry = 3; + + private long waitTimeMillis = 10l; + private String basePath = "http://petstore.swagger.io/v2"; private RestTemplate restTemplate; @@ -88,10 +92,6 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private int maxAttempts = 3; - - private long waitTimeMillis = 10l; - public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -146,18 +146,18 @@ public ApiClient setBasePath(String basePath) { * * @return int the max attempts */ - public int getMaxAttempts() { - return maxAttempts; + public int getMaxAttemptsForRetry() { + return maxAttemptsForRetry; } /** - * Set the max attemtps for retry + * Set the max attempts for retry * - * @param maxAttempts the max attempts for retry + * @param getMaxAttemptsForRetry the max attempts for retry * @return ApiClient this client */ - public ApiClient setMaxAttempts(int maxAttempts) { - this.maxAttempts = maxAttempts; + public ApiClient setMaxAttemptsForRetry(int maxAttemptsForRetry) { + this.maxAttemptsForRetry = maxAttemptsForRetry; return this; } @@ -676,17 +676,13 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map responseEntity = null; int attempts = 0; - while (attempts < maxAttempts) { + while (attempts < maxAttemptsForRetry) { try { responseEntity = restTemplate.exchange(requestEntity, returnType); - // request succeeded, no need to retry break; } catch (HttpServerErrorException ex) { - if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; - } attempts++; - if (attempts < maxAttempts) { + if (attempts < maxAttemptsForRetry) { try { Thread.sleep(waitTimeMillis); } catch (InterruptedException e) { diff --git a/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java index 2104aca661fc..d47ce3f32b9b 100644 --- a/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-swagger1/src/main/java/org/openapitools/client/ApiClient.java @@ -80,6 +80,10 @@ private String collectionToString(Collection collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); + private int maxAttemptsForRetry = 3; + + private long waitTimeMillis = 10l; + private String basePath = "http://petstore.swagger.io/v2"; private RestTemplate restTemplate; @@ -88,10 +92,6 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private int maxAttempts = 3; - - private long waitTimeMillis = 10l; - public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -146,18 +146,18 @@ public ApiClient setBasePath(String basePath) { * * @return int the max attempts */ - public int getMaxAttempts() { - return maxAttempts; + public int getMaxAttemptsForRetry() { + return maxAttemptsForRetry; } /** - * Set the max attemtps for retry + * Set the max attempts for retry * - * @param maxAttempts the max attempts for retry + * @param getMaxAttemptsForRetry the max attempts for retry * @return ApiClient this client */ - public ApiClient setMaxAttempts(int maxAttempts) { - this.maxAttempts = maxAttempts; + public ApiClient setMaxAttemptsForRetry(int maxAttemptsForRetry) { + this.maxAttemptsForRetry = maxAttemptsForRetry; return this; } @@ -676,17 +676,13 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map responseEntity = null; int attempts = 0; - while (attempts < maxAttempts) { + while (attempts < maxAttemptsForRetry) { try { responseEntity = restTemplate.exchange(requestEntity, returnType); - // request succeeded, no need to retry break; } catch (HttpServerErrorException ex) { - if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; - } attempts++; - if (attempts < maxAttempts) { + if (attempts < maxAttemptsForRetry) { try { Thread.sleep(waitTimeMillis); } catch (InterruptedException e) { diff --git a/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java index 2104aca661fc..d47ce3f32b9b 100644 --- a/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-swagger2/src/main/java/org/openapitools/client/ApiClient.java @@ -80,6 +80,10 @@ private String collectionToString(Collection collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); + private int maxAttemptsForRetry = 3; + + private long waitTimeMillis = 10l; + private String basePath = "http://petstore.swagger.io/v2"; private RestTemplate restTemplate; @@ -88,10 +92,6 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private int maxAttempts = 3; - - private long waitTimeMillis = 10l; - public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -146,18 +146,18 @@ public ApiClient setBasePath(String basePath) { * * @return int the max attempts */ - public int getMaxAttempts() { - return maxAttempts; + public int getMaxAttemptsForRetry() { + return maxAttemptsForRetry; } /** - * Set the max attemtps for retry + * Set the max attempts for retry * - * @param maxAttempts the max attempts for retry + * @param getMaxAttemptsForRetry the max attempts for retry * @return ApiClient this client */ - public ApiClient setMaxAttempts(int maxAttempts) { - this.maxAttempts = maxAttempts; + public ApiClient setMaxAttemptsForRetry(int maxAttemptsForRetry) { + this.maxAttemptsForRetry = maxAttemptsForRetry; return this; } @@ -676,17 +676,13 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map responseEntity = null; int attempts = 0; - while (attempts < maxAttempts) { + while (attempts < maxAttemptsForRetry) { try { responseEntity = restTemplate.exchange(requestEntity, returnType); - // request succeeded, no need to retry break; } catch (HttpServerErrorException ex) { - if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; - } attempts++; - if (attempts < maxAttempts) { + if (attempts < maxAttemptsForRetry) { try { Thread.sleep(waitTimeMillis); } catch (InterruptedException e) { diff --git a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java index 7aae283fb641..68827f80ff66 100644 --- a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/ApiClient.java @@ -87,6 +87,10 @@ private String collectionToString(Collection collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); + private int maxAttemptsForRetry = 3; + + private long waitTimeMillis = 10l; + private String basePath = "http://petstore.swagger.io:80/v2"; private RestTemplate restTemplate; @@ -95,10 +99,6 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private int maxAttempts = 3; - - private long waitTimeMillis = 10l; - public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -156,18 +156,18 @@ public ApiClient setBasePath(String basePath) { * * @return int the max attempts */ - public int getMaxAttempts() { - return maxAttempts; + public int getMaxAttemptsForRetry() { + return maxAttemptsForRetry; } /** - * Set the max attemtps for retry + * Set the max attempts for retry * - * @param maxAttempts the max attempts for retry + * @param getMaxAttemptsForRetry the max attempts for retry * @return ApiClient this client */ - public ApiClient setMaxAttempts(int maxAttempts) { - this.maxAttempts = maxAttempts; + public ApiClient setMaxAttemptsForRetry(int maxAttemptsForRetry) { + this.maxAttemptsForRetry = maxAttemptsForRetry; return this; } @@ -739,17 +739,13 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map responseEntity = null; int attempts = 0; - while (attempts < maxAttempts) { + while (attempts < maxAttemptsForRetry) { try { responseEntity = restTemplate.exchange(requestEntity, returnType); - // request succeeded, no need to retry break; } catch (HttpServerErrorException ex) { - if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; - } attempts++; - if (attempts < maxAttempts) { + if (attempts < maxAttemptsForRetry) { try { Thread.sleep(waitTimeMillis); } catch (InterruptedException e) { diff --git a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index c7b73ed4766b..d50999dc4ffe 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -82,6 +82,10 @@ private String collectionToString(Collection collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); + private int maxAttemptsForRetry = 3; + + private long waitTimeMillis = 10l; + private String basePath = "http://petstore.swagger.io:80/v2"; private RestTemplate restTemplate; @@ -90,10 +94,6 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private int maxAttempts = 3; - - private long waitTimeMillis = 10l; - public ApiClient() { this.restTemplate = buildRestTemplate(); init(); @@ -151,18 +151,18 @@ public ApiClient setBasePath(String basePath) { * * @return int the max attempts */ - public int getMaxAttempts() { - return maxAttempts; + public int getMaxAttemptsForRetry() { + return maxAttemptsForRetry; } /** - * Set the max attemtps for retry + * Set the max attempts for retry * - * @param maxAttempts the max attempts for retry + * @param getMaxAttemptsForRetry the max attempts for retry * @return ApiClient this client */ - public ApiClient setMaxAttempts(int maxAttempts) { - this.maxAttempts = maxAttempts; + public ApiClient setMaxAttemptsForRetry(int maxAttemptsForRetry) { + this.maxAttemptsForRetry = maxAttemptsForRetry; return this; } @@ -734,17 +734,13 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map responseEntity = null; int attempts = 0; - while (attempts < maxAttempts) { + while (attempts < maxAttemptsForRetry) { try { responseEntity = restTemplate.exchange(requestEntity, returnType); - // request succeeded, no need to retry break; } catch (HttpServerErrorException ex) { - if (ex.getStatusCode() != HttpStatus.SERVICE_UNAVAILABLE) { - throw ex; - } attempts++; - if (attempts < maxAttempts) { + if (attempts < maxAttemptsForRetry) { try { Thread.sleep(waitTimeMillis); } catch (InterruptedException e) { From ce6fed5bb405c2b607e3083a7b32007b8dd7f497 Mon Sep 17 00:00:00 2001 From: Rubini Date: Tue, 12 Dec 2023 15:26:04 +0530 Subject: [PATCH 10/12] Removing reduntant variable --- .../src/main/java/org/openapitools/client/ApiClient.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java index e396ea408d67..8856fc5966a9 100644 --- a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java @@ -90,10 +90,6 @@ private String collectionToString(Collection collection) { private DateFormat dateFormat; - private int maxAttempts = 3; - - private long waitTimeMillis = 10l; - public ApiClient() { this.restTemplate = buildRestTemplate(); init(); From 0bb8b29f4817ac2f7f95f5b5ae093709a13c8418 Mon Sep 17 00:00:00 2001 From: Rubini Date: Tue, 12 Dec 2023 15:48:22 +0530 Subject: [PATCH 11/12] Generating samples --- .../src/main/java/org/openapitools/client/ApiClient.java | 5 +++-- .../src/main/java/org/openapitools/client/ApiClient.java | 6 +++--- .../src/main/java/org/openapitools/client/ApiClient.java | 6 +++--- .../src/main/java/org/openapitools/client/ApiClient.java | 6 +++--- .../src/main/java/org/openapitools/client/ApiClient.java | 6 +++--- .../src/main/java/org/openapitools/client/ApiClient.java | 6 +++--- .../src/main/java/org/openapitools/client/ApiClient.java | 6 +++--- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index 631d60760d8d..5d86fc199905 100644 --- a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -80,9 +80,9 @@ private String collectionToString(Collection collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); - private int maxAttemptsForRetry = 3; + private int maxAttemptsForRetry = 1; - private long waitTimeMillis = 10l; + private long waitTimeMillis = 10; private String basePath = "http://localhost:3000"; @@ -180,6 +180,7 @@ public ApiClient setWaitTimeMillis(long waitTimeMillis) { this.waitTimeMillis = waitTimeMillis; return this; } + /** * Get authentications (key: authentication name, value: authentication). * diff --git a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java index 8856fc5966a9..c07817f020a5 100644 --- a/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/resttemplate-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java @@ -78,9 +78,9 @@ private String collectionToString(Collection collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); - private int maxAttemptsForRetry = 3; + private int maxAttemptsForRetry = 1; - private long waitTimeMillis = 10l; + private long waitTimeMillis = 10; private String basePath = "http://localhost"; @@ -631,7 +631,7 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); - private int maxAttemptsForRetry = 3; + private int maxAttemptsForRetry = 1; - private long waitTimeMillis = 10l; + private long waitTimeMillis = 10; private String basePath = "http://petstore.swagger.io/v2"; @@ -680,7 +680,7 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); - private int maxAttemptsForRetry = 3; + private int maxAttemptsForRetry = 1; - private long waitTimeMillis = 10l; + private long waitTimeMillis = 10; private String basePath = "http://petstore.swagger.io/v2"; @@ -680,7 +680,7 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); - private int maxAttemptsForRetry = 3; + private int maxAttemptsForRetry = 1; - private long waitTimeMillis = 10l; + private long waitTimeMillis = 10; private String basePath = "http://petstore.swagger.io/v2"; @@ -680,7 +680,7 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); - private int maxAttemptsForRetry = 3; + private int maxAttemptsForRetry = 1; - private long waitTimeMillis = 10l; + private long waitTimeMillis = 10; private String basePath = "http://petstore.swagger.io:80/v2"; @@ -743,7 +743,7 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map collection) { private HttpHeaders defaultHeaders = new HttpHeaders(); private MultiValueMap defaultCookies = new LinkedMultiValueMap(); - private int maxAttemptsForRetry = 3; + private int maxAttemptsForRetry = 1; - private long waitTimeMillis = 10l; + private long waitTimeMillis = 10; private String basePath = "http://petstore.swagger.io:80/v2"; @@ -738,7 +738,7 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map Date: Tue, 12 Dec 2023 16:23:18 +0530 Subject: [PATCH 12/12] Fixing format --- .../resources/Java/libraries/resttemplate/ApiClient.mustache | 2 +- .../src/main/java/org/openapitools/client/ApiClient.java | 2 +- .../src/main/java/org/openapitools/client/ApiClient.java | 2 +- .../src/main/java/org/openapitools/client/ApiClient.java | 2 +- .../src/main/java/org/openapitools/client/ApiClient.java | 2 +- .../src/main/java/org/openapitools/client/ApiClient.java | 2 +- .../src/main/java/org/openapitools/client/ApiClient.java | 2 +- .../src/main/java/org/openapitools/client/ApiClient.java | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index 122d534dc634..f641d8e16d96 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -772,7 +772,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { try { responseEntity = restTemplate.exchange(requestEntity, returnType); break; - } catch (HttpServerErrorException ex) { + } catch (HttpServerErrorException ex) { attempts++; if (attempts < maxAttemptsForRetry) { try { diff --git a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java index 5d86fc199905..cd4196b5c211 100644 --- a/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/resttemplate/src/main/java/org/openapitools/client/ApiClient.java @@ -688,7 +688,7 @@ public ResponseEntity invokeAPI(String path, HttpMethod method, Map ResponseEntity invokeAPI(String path, HttpMethod method, Map ResponseEntity invokeAPI(String path, HttpMethod method, Map ResponseEntity invokeAPI(String path, HttpMethod method, Map ResponseEntity invokeAPI(String path, HttpMethod method, Map ResponseEntity invokeAPI(String path, HttpMethod method, Map ResponseEntity invokeAPI(String path, HttpMethod method, Map