forked from loafle/openapi-generator-original
[ANDROID][volley] Handle UnsupportedEncodingException in invokeAPI (#6436)
* [ANDROID][volley] Handle UnsupportedEncodingException in invokeAPI (Issue #6432) The constructor of StringEntity can throw UnsupportedEncodingException, which is not catch nor thrown by createRequest method. Therefore the build of android client fails with: ApiInvoker.java:448: error: unreported exception UnsupportedEncodingException; must be caught or declared to be thrown This commit adds a try ... catch on UnsupportedEncodingException in invokeAPI methods and declare this exception to be thrown in createRequest * [ANDROID][volley] Handle UnsupportedEncodingException in invokeAPI (Issue #6432) The constructor of StringEntity can throw UnsupportedEncodingException, which is not catch nor thrown by createRequest method. Therefore the build of android client fails with: ApiInvoker.java:448: error: unreported exception UnsupportedEncodingException; must be caught or declared to be thrown This commit adds a try ... catch on UnsupportedEncodingException in invokeAPI methods and declare this exception to be thrown in createRequest * [ANDROID][Volley] Handle UnsupportedEncodingException (Issue #6432) Throw more precise ApiException
This commit is contained in:
parent
0cf82d7ae3
commit
3cd3b907f6
@ -363,24 +363,32 @@ public class ApiInvoker {
|
||||
}
|
||||
|
||||
public String invokeAPI(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames) throws ApiException, InterruptedException, ExecutionException, TimeoutException {
|
||||
RequestFuture<String> future = RequestFuture.newFuture();
|
||||
Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, future, future);
|
||||
if(request != null) {
|
||||
mRequestQueue.add(request);
|
||||
return future.get(connectionTimeout, TimeUnit.SECONDS);
|
||||
} else {
|
||||
return "no data";
|
||||
try {
|
||||
RequestFuture<String> future = RequestFuture.newFuture();
|
||||
Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, future, future);
|
||||
if(request != null) {
|
||||
mRequestQueue.add(request);
|
||||
return future.get(connectionTimeout, TimeUnit.SECONDS);
|
||||
} else {
|
||||
return "no data";
|
||||
}
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new ApiException(0, "UnsupportedEncodingException");
|
||||
}
|
||||
}
|
||||
|
||||
public void invokeAPI(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames, Response.Listener<String> stringRequest, Response.ErrorListener errorListener) throws ApiException {
|
||||
Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, stringRequest, errorListener);
|
||||
if (request != null) {
|
||||
mRequestQueue.add(request);
|
||||
try {
|
||||
Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, stringRequest, errorListener);
|
||||
if (request != null) {
|
||||
mRequestQueue.add(request);
|
||||
}
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new ApiException(0, "UnsupportedEncodingException");
|
||||
}
|
||||
}
|
||||
|
||||
public Request<String> createRequest(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames, Response.Listener<String> stringRequest, Response.ErrorListener errorListener) throws ApiException {
|
||||
public Request<String> createRequest(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames, Response.Listener<String> stringRequest, Response.ErrorListener errorListener) throws ApiException, UnsupportedEncodingException {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("?");
|
||||
|
||||
|
@ -80,7 +80,7 @@ This endpoint does not need any parameter.
|
||||
|
||||
### Return type
|
||||
|
||||
[**Map<String, Integer>**](Map.md)
|
||||
**Map<String, Integer>**
|
||||
|
||||
### Authorization
|
||||
|
||||
|
@ -365,24 +365,32 @@ public class ApiInvoker {
|
||||
}
|
||||
|
||||
public String invokeAPI(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames) throws ApiException, InterruptedException, ExecutionException, TimeoutException {
|
||||
RequestFuture<String> future = RequestFuture.newFuture();
|
||||
Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, future, future);
|
||||
if(request != null) {
|
||||
mRequestQueue.add(request);
|
||||
return future.get(connectionTimeout, TimeUnit.SECONDS);
|
||||
} else {
|
||||
return "no data";
|
||||
try {
|
||||
RequestFuture<String> future = RequestFuture.newFuture();
|
||||
Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, future, future);
|
||||
if(request != null) {
|
||||
mRequestQueue.add(request);
|
||||
return future.get(connectionTimeout, TimeUnit.SECONDS);
|
||||
} else {
|
||||
return "no data";
|
||||
}
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new ApiException(0, "UnsupportedEncodingException");
|
||||
}
|
||||
}
|
||||
|
||||
public void invokeAPI(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames, Response.Listener<String> stringRequest, Response.ErrorListener errorListener) throws ApiException {
|
||||
Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, stringRequest, errorListener);
|
||||
if (request != null) {
|
||||
mRequestQueue.add(request);
|
||||
try {
|
||||
Request request = createRequest(host, path, method, queryParams, body, headerParams, formParams, contentType, authNames, stringRequest, errorListener);
|
||||
if (request != null) {
|
||||
mRequestQueue.add(request);
|
||||
}
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new ApiException(0, "UnsupportedEncodingException");
|
||||
}
|
||||
}
|
||||
|
||||
public Request<String> createRequest(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames, Response.Listener<String> stringRequest, Response.ErrorListener errorListener) throws ApiException {
|
||||
public Request<String> createRequest(String host, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames, Response.Listener<String> stringRequest, Response.ErrorListener errorListener) throws ApiException, UnsupportedEncodingException {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("?");
|
||||
|
||||
|
@ -214,7 +214,7 @@ public class StoreApi {
|
||||
try {
|
||||
String localVarResponse = apiInvoker.invokeAPI (basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType, authNames);
|
||||
if (localVarResponse != null) {
|
||||
return (Map<String, Integer>) ApiInvoker.deserialize(localVarResponse, "map", Map.class);
|
||||
return (Map<String, Integer>) ApiInvoker.deserialize(localVarResponse, "map", Integer.class);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -280,7 +280,7 @@ public class StoreApi {
|
||||
@Override
|
||||
public void onResponse(String localVarResponse) {
|
||||
try {
|
||||
responseListener.onResponse((Map<String, Integer>) ApiInvoker.deserialize(localVarResponse, "map", Map.class));
|
||||
responseListener.onResponse((Map<String, Integer>) ApiInvoker.deserialize(localVarResponse, "map", Integer.class));
|
||||
} catch (ApiException exception) {
|
||||
errorListener.onErrorResponse(new VolleyError(exception));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user