From 8dfe230b7cd3a15f9cc701222c57da0d250fca6d Mon Sep 17 00:00:00 2001 From: sidhantgoyal Date: Mon, 29 Aug 2016 14:01:49 +0530 Subject: [PATCH] [android] volley socket timeout configurable (#3646) * [android] volley socket timeout configurable * Updated Android Volley Petstore sample --- .../android/libraries/volley/apiInvoker.mustache | 8 +++++++- samples/client/petstore/android/volley/README.md | 12 ++++++------ .../client/petstore/android/volley/docs/PetApi.md | 2 +- .../src/main/java/io/swagger/client/ApiInvoker.java | 10 ++++++++-- .../src/main/java/io/swagger/client/api/PetApi.java | 4 ++-- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/android/libraries/volley/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/android/libraries/volley/apiInvoker.mustache index 76019d7c45..94b6be4586 100644 --- a/modules/swagger-codegen/src/main/resources/android/libraries/volley/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/android/libraries/volley/apiInvoker.mustache @@ -2,6 +2,7 @@ package {{invokerPackage}}; import com.android.volley.Cache; +import com.android.volley.DefaultRetryPolicy; import com.android.volley.Network; import com.android.volley.Request; import com.android.volley.RequestQueue; @@ -486,7 +487,12 @@ public class ApiInvoker { } else { request = new PatchRequest(url, headers, null, null, stringRequest, errorListener); } - } + } + + if (request != null) { + request.setRetryPolicy(new DefaultRetryPolicy((int)TimeUnit.SECONDS.toMillis(this.connectionTimeout), DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); + } + return request; } diff --git a/samples/client/petstore/android/volley/README.md b/samples/client/petstore/android/volley/README.md index c92f468b12..7693866ff6 100644 --- a/samples/client/petstore/android/volley/README.md +++ b/samples/client/petstore/android/volley/README.md @@ -116,12 +116,6 @@ Class | Method | HTTP request | Description ## Documentation for Authorization Authentication schemes defined for the API: -### api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - ### petstore_auth - **Type**: OAuth @@ -131,6 +125,12 @@ Authentication schemes defined for the API: - write:pets: modify pets in your account - read:pets: read your pets +### api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + ## Recommendation diff --git a/samples/client/petstore/android/volley/docs/PetApi.md b/samples/client/petstore/android/volley/docs/PetApi.md index e7b393c8ea..ff596b3d91 100644 --- a/samples/client/petstore/android/volley/docs/PetApi.md +++ b/samples/client/petstore/android/volley/docs/PetApi.md @@ -222,7 +222,7 @@ Name | Type | Description | Notes ### Authorization -[api_key](../README.md#api_key), [petstore_auth](../README.md#petstore_auth) +[petstore_auth](../README.md#petstore_auth), [api_key](../README.md#api_key) ### HTTP request headers diff --git a/samples/client/petstore/android/volley/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/android/volley/src/main/java/io/swagger/client/ApiInvoker.java index 5867d0a314..ec17f4582d 100644 --- a/samples/client/petstore/android/volley/src/main/java/io/swagger/client/ApiInvoker.java +++ b/samples/client/petstore/android/volley/src/main/java/io/swagger/client/ApiInvoker.java @@ -25,6 +25,7 @@ package io.swagger.client; import com.android.volley.Cache; +import com.android.volley.DefaultRetryPolicy; import com.android.volley.Network; import com.android.volley.Request; import com.android.volley.RequestQueue; @@ -213,9 +214,9 @@ public class ApiInvoker { // Setup authentications (key: authentication name, value: authentication). INSTANCE.authentications = new HashMap(); - INSTANCE.authentications.put("api_key", new ApiKeyAuth("header", "api_key")); // TODO: comment out below as OAuth does not exist //INSTANCE.authentications.put("petstore_auth", new OAuth()); + INSTANCE.authentications.put("api_key", new ApiKeyAuth("header", "api_key")); // Prevent the authentications from being modified. INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications); } @@ -500,7 +501,12 @@ public class ApiInvoker { } else { request = new PatchRequest(url, headers, null, null, stringRequest, errorListener); } - } + } + + if (request != null) { + request.setRetryPolicy(new DefaultRetryPolicy((int)TimeUnit.SECONDS.toMillis(this.connectionTimeout), DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); + } + return request; } diff --git a/samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java index ae9bcead7c..5ef1079981 100644 --- a/samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/android/volley/src/main/java/io/swagger/client/api/PetApi.java @@ -623,7 +623,7 @@ public class PetApi { // normal form params } - String[] authNames = new String[] { "api_key", "petstore_auth" }; + String[] authNames = new String[] { "petstore_auth", "api_key" }; try { String localVarResponse = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames); @@ -693,7 +693,7 @@ public class PetApi { // normal form params } - String[] authNames = new String[] { "api_key", "petstore_auth" }; + String[] authNames = new String[] { "petstore_auth", "api_key" }; try { apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames,