diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiCallback.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiCallback.java index d75713c9a01..fcf2d289fbf 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiCallback.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiCallback.java @@ -28,4 +28,22 @@ public interface ApiCallback { * @param responseHeaders Headers of the response */ void onSuccess(T result, int statusCode, Map> responseHeaders); + + /** + * This is called when the API upload processing. + * + * @param bytesWritten bytes Written + * @param contentLength content length of request body + * @param done write end + */ + void onUploadProgress(long bytesWritten, long contentLength, boolean done); + + /** + * This is called when the API downlond processing. + * + * @param bytesRead bytes Read + * @param contentLength content lenngth of the response + * @param done Read end + */ + void onDownloadProgress(long bytesRead, long contentLength, boolean done); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java index 6e4e299ad3a..43df2643cd3 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -143,8 +143,8 @@ public class ApiClient { // Setup authentications (key: authentication name, value: authentication). authentications = new HashMap(); - authentications.put("petstore_auth", new OAuth()); authentications.put("api_key", new ApiKeyAuth("header", "api_key")); + authentications.put("petstore_auth", new OAuth()); // Prevent the authentications from being modified. authentications = Collections.unmodifiableMap(authentications); } @@ -820,7 +820,7 @@ public class ApiClient { * @param authNames The authentications to apply * @return The HTTP call */ - public Call buildCall(String path, String method, List queryParams, Object body, Map headerParams, Map formParams, String[] authNames) throws ApiException { + public Call buildCall(String path, String method, List queryParams, Object body, Map headerParams, Map formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { updateParamsForAuth(authNames, queryParams, headerParams); final String url = buildUrl(path, queryParams); @@ -850,7 +850,15 @@ public class ApiClient { reqBody = RequestBody.create(MediaType.parse(contentType), serialize(body, contentType)); } - Request request = reqBuilder.method(method, reqBody).build(); + Request request = null; + + if(progressRequestListener != null) { + ProgressRequestBody progressRequestBody = new ProgressRequestBody(reqBody, progressRequestListener); + request = reqBuilder.method(method, progressRequestBody).build(); + } else { + request = reqBuilder.method(method, reqBody).build(); + } + return httpClient.newCall(request); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiException.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiException.java index 0bdd5bd17c6..3df58b0b4d1 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiException.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiException.java @@ -3,7 +3,7 @@ package io.swagger.client; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T11:42:25.339-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-21T19:41:14.431+08:00") public class ApiException extends Exception { private int code = 0; private Map> responseHeaders = null; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Configuration.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Configuration.java index a63382fc05b..084020d501a 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Configuration.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Configuration.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T11:42:25.339-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-21T19:41:14.431+08:00") public class Configuration { private static ApiClient defaultApiClient = new ApiClient(); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Pair.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Pair.java index 533d318cb5c..91ae60aa14b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Pair.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Pair.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T11:42:25.339-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-21T19:41:14.431+08:00") public class Pair { private String name = ""; private String value = ""; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ProgressRequestBody.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ProgressRequestBody.java new file mode 100644 index 00000000000..71f34ed1140 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ProgressRequestBody.java @@ -0,0 +1,70 @@ +package io.swagger.client; + +import com.squareup.okhttp.MediaType; +import com.squareup.okhttp.RequestBody; + +import java.io.IOException; + +import okio.Buffer; +import okio.BufferedSink; +import okio.ForwardingSink; +import okio.Okio; +import okio.Sink; + +public class ProgressRequestBody extends RequestBody { + + public interface ProgressRequestListener { + void onRequestProgress(long bytesWritten, long contentLength, boolean done); + } + + private final RequestBody requestBody; + + private final ProgressRequestListener progressListener; + + private BufferedSink bufferedSink; + + public ProgressRequestBody(RequestBody requestBody, ProgressRequestListener progressListener) { + this.requestBody = requestBody; + this.progressListener = progressListener; + } + + @Override + public MediaType contentType() { + return requestBody.contentType(); + } + + @Override + public long contentLength() throws IOException { + return requestBody.contentLength(); + } + + @Override + public void writeTo(BufferedSink sink) throws IOException { + if (bufferedSink == null) { + bufferedSink = Okio.buffer(sink(sink)); + } + + requestBody.writeTo(bufferedSink); + bufferedSink.flush(); + + } + + private Sink sink(Sink sink) { + return new ForwardingSink(sink) { + + long bytesWritten = 0L; + long contentLength = 0L; + + @Override + public void write(Buffer source, long byteCount) throws IOException { + super.write(source, byteCount); + if (contentLength == 0) { + contentLength = contentLength(); + } + + bytesWritten += byteCount; + progressListener.onRequestProgress(bytesWritten, contentLength, bytesWritten == contentLength); + } + }; + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ProgressResponseBody.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ProgressResponseBody.java new file mode 100644 index 00000000000..138da3f2106 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ProgressResponseBody.java @@ -0,0 +1,63 @@ +package io.swagger.client; + +import com.squareup.okhttp.MediaType; +import com.squareup.okhttp.ResponseBody; + +import java.io.IOException; + +import okio.Buffer; +import okio.BufferedSource; +import okio.ForwardingSource; +import okio.Okio; +import okio.Source; + +public class ProgressResponseBody extends ResponseBody { + + public interface ProgressListener { + void update(long bytesRead, long contentLength, boolean done); + } + + private final ResponseBody responseBody; + private final ProgressListener progressListener; + private BufferedSource bufferedSource; + + public ProgressResponseBody(ResponseBody responseBody, ProgressListener progressListener) { + this.responseBody = responseBody; + this.progressListener = progressListener; + } + + @Override + public MediaType contentType() { + return responseBody.contentType(); + } + + @Override + public long contentLength() throws IOException { + return responseBody.contentLength(); + } + + @Override + public BufferedSource source() throws IOException { + if (bufferedSource == null) { + bufferedSource = Okio.buffer(source(responseBody.source())); + } + return bufferedSource; + } + + private Source source(Source source) { + return new ForwardingSource(source) { + long totalBytesRead = 0L; + + @Override + public long read(Buffer sink, long byteCount) throws IOException { + long bytesRead = super.read(sink, byteCount); + // read() returns the number of bytes read, or -1 if this source is exhausted. + totalBytesRead += bytesRead != -1 ? bytesRead : 0; + progressListener.update(totalBytesRead, responseBody.contentLength(), bytesRead == -1); + return bytesRead; + } + }; + } +} + + diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/StringUtil.java index 42d453c31ef..bd4fefc651a 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/StringUtil.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/StringUtil.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T11:42:25.339-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-21T19:41:14.431+08:00") public class StringUtil { /** * Check if the given array contains the given value (with case-insensitive comparison). diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java index 39154cf855e..d1982566bf9 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java @@ -5,10 +5,16 @@ import io.swagger.client.ApiClient; import io.swagger.client.ApiException; import io.swagger.client.Configuration; import io.swagger.client.Pair; +import io.swagger.client.ProgressRequestBody; +import io.swagger.client.ProgressResponseBody; import com.google.gson.reflect.TypeToken; import com.squareup.okhttp.Call; +import com.squareup.okhttp.Interceptor; +import com.squareup.okhttp.Response; + +import java.io.IOException; import io.swagger.client.model.Pet; import java.io.File; @@ -37,7 +43,7 @@ public class PetApi { /* Build call for updatePet */ - private Call updatePetCall(Pet body) throws ApiException { + private Call updatePetCall(Pet body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = body; @@ -62,8 +68,20 @@ public class PetApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { "petstore_auth" }; - return apiClient.buildCall(path, "PUT", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "PUT", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -72,7 +90,7 @@ public class PetApi { * @param body Pet object that needs to be added to the store */ public void updatePet(Pet body) throws ApiException { - Call call = updatePetCall(body); + Call call = updatePetCall(body, null, null); apiClient.execute(call); } @@ -83,14 +101,34 @@ public class PetApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call updatePetAsync(Pet body, ApiCallback callback) throws ApiException { - Call call = updatePetCall(body); + public Call updatePetAsync(Pet body, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = updatePetCall(body, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for addPet */ - private Call addPetCall(Pet body) throws ApiException { + private Call addPetCall(Pet body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = body; @@ -115,8 +153,20 @@ public class PetApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { "petstore_auth" }; - return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -125,7 +175,7 @@ public class PetApi { * @param body Pet object that needs to be added to the store */ public void addPet(Pet body) throws ApiException { - Call call = addPetCall(body); + Call call = addPetCall(body, null, null); apiClient.execute(call); } @@ -136,14 +186,34 @@ public class PetApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call addPetAsync(Pet body, ApiCallback callback) throws ApiException { - Call call = addPetCall(body); + public Call addPetAsync(Pet body, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = addPetCall(body, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for findPetsByStatus */ - private Call findPetsByStatusCall(List status) throws ApiException { + private Call findPetsByStatusCall(List status, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; @@ -170,8 +240,20 @@ public class PetApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { "petstore_auth" }; - return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -181,7 +263,7 @@ public class PetApi { * @return List */ public List findPetsByStatus(List status) throws ApiException { - Call call = findPetsByStatusCall(status); + Call call = findPetsByStatusCall(status, null, null); Type returnType = new TypeToken>(){}.getType(); return apiClient.execute(call, returnType); } @@ -193,15 +275,35 @@ public class PetApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call findPetsByStatusAsync(List status, ApiCallback> callback) throws ApiException { - Call call = findPetsByStatusCall(status); + public Call findPetsByStatusAsync(List status, final ApiCallback> callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = findPetsByStatusCall(status, progressListener, progressRequestListener); Type returnType = new TypeToken>(){}.getType(); apiClient.executeAsync(call, returnType, callback); return call; } /* Build call for findPetsByTags */ - private Call findPetsByTagsCall(List tags) throws ApiException { + private Call findPetsByTagsCall(List tags, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; @@ -228,8 +330,20 @@ public class PetApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { "petstore_auth" }; - return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -239,7 +353,7 @@ public class PetApi { * @return List */ public List findPetsByTags(List tags) throws ApiException { - Call call = findPetsByTagsCall(tags); + Call call = findPetsByTagsCall(tags, null, null); Type returnType = new TypeToken>(){}.getType(); return apiClient.execute(call, returnType); } @@ -251,15 +365,35 @@ public class PetApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call findPetsByTagsAsync(List tags, ApiCallback> callback) throws ApiException { - Call call = findPetsByTagsCall(tags); + public Call findPetsByTagsAsync(List tags, final ApiCallback> callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = findPetsByTagsCall(tags, progressListener, progressRequestListener); Type returnType = new TypeToken>(){}.getType(); apiClient.executeAsync(call, returnType, callback); return call; } /* Build call for getPetById */ - private Call getPetByIdCall(Long petId) throws ApiException { + private Call getPetByIdCall(Long petId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -290,8 +424,20 @@ public class PetApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { "api_key" }; - return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -301,7 +447,7 @@ public class PetApi { * @return Pet */ public Pet getPetById(Long petId) throws ApiException { - Call call = getPetByIdCall(petId); + Call call = getPetByIdCall(petId, null, null); Type returnType = new TypeToken(){}.getType(); return apiClient.execute(call, returnType); } @@ -313,15 +459,35 @@ public class PetApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call getPetByIdAsync(Long petId, ApiCallback callback) throws ApiException { - Call call = getPetByIdCall(petId); + public Call getPetByIdAsync(Long petId, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = getPetByIdCall(petId, progressListener, progressRequestListener); Type returnType = new TypeToken(){}.getType(); apiClient.executeAsync(call, returnType, callback); return call; } /* Build call for updatePetWithForm */ - private Call updatePetWithFormCall(String petId, String name, String status) throws ApiException { + private Call updatePetWithFormCall(String petId, String name, String status, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -356,8 +522,20 @@ public class PetApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { "petstore_auth" }; - return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -368,7 +546,7 @@ public class PetApi { * @param status Updated status of the pet */ public void updatePetWithForm(String petId, String name, String status) throws ApiException { - Call call = updatePetWithFormCall(petId, name, status); + Call call = updatePetWithFormCall(petId, name, status, null, null); apiClient.execute(call); } @@ -381,14 +559,34 @@ public class PetApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call updatePetWithFormAsync(String petId, String name, String status, ApiCallback callback) throws ApiException { - Call call = updatePetWithFormCall(petId, name, status); + public Call updatePetWithFormAsync(String petId, String name, String status, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = updatePetWithFormCall(petId, name, status, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for deletePet */ - private Call deletePetCall(Long petId, String apiKey) throws ApiException { + private Call deletePetCall(Long petId, String apiKey, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -421,8 +619,20 @@ public class PetApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { "petstore_auth" }; - return apiClient.buildCall(path, "DELETE", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "DELETE", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -432,7 +642,7 @@ public class PetApi { * @param apiKey */ public void deletePet(Long petId, String apiKey) throws ApiException { - Call call = deletePetCall(petId, apiKey); + Call call = deletePetCall(petId, apiKey, null, null); apiClient.execute(call); } @@ -444,14 +654,34 @@ public class PetApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call deletePetAsync(Long petId, String apiKey, ApiCallback callback) throws ApiException { - Call call = deletePetCall(petId, apiKey); + public Call deletePetAsync(Long petId, String apiKey, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = deletePetCall(petId, apiKey, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for uploadFile */ - private Call uploadFileCall(Long petId, String additionalMetadata, File file) throws ApiException { + private Call uploadFileCall(Long petId, String additionalMetadata, File file, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -486,8 +716,20 @@ public class PetApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { "petstore_auth" }; - return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -498,7 +740,7 @@ public class PetApi { * @param file file to upload */ public void uploadFile(Long petId, String additionalMetadata, File file) throws ApiException { - Call call = uploadFileCall(petId, additionalMetadata, file); + Call call = uploadFileCall(petId, additionalMetadata, file, null, null); apiClient.execute(call); } @@ -511,8 +753,28 @@ public class PetApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call uploadFileAsync(Long petId, String additionalMetadata, File file, ApiCallback callback) throws ApiException { - Call call = uploadFileCall(petId, additionalMetadata, file); + public Call uploadFileAsync(Long petId, String additionalMetadata, File file, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = uploadFileCall(petId, additionalMetadata, file, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java index cb780538e18..2235a73e0c3 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java @@ -5,10 +5,16 @@ import io.swagger.client.ApiClient; import io.swagger.client.ApiException; import io.swagger.client.Configuration; import io.swagger.client.Pair; +import io.swagger.client.ProgressRequestBody; +import io.swagger.client.ProgressResponseBody; import com.google.gson.reflect.TypeToken; import com.squareup.okhttp.Call; +import com.squareup.okhttp.Interceptor; +import com.squareup.okhttp.Response; + +import java.io.IOException; import java.util.Map; import io.swagger.client.model.Order; @@ -37,7 +43,7 @@ public class StoreApi { /* Build call for getInventory */ - private Call getInventoryCall() throws ApiException { + private Call getInventoryCall(, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; @@ -62,8 +68,20 @@ public class StoreApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { "api_key" }; - return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -72,7 +90,7 @@ public class StoreApi { * @return Map */ public Map getInventory() throws ApiException { - Call call = getInventoryCall(); + Call call = getInventoryCall(, null, null); Type returnType = new TypeToken>(){}.getType(); return apiClient.execute(call, returnType); } @@ -83,15 +101,35 @@ public class StoreApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call getInventoryAsync(ApiCallback> callback) throws ApiException { - Call call = getInventoryCall(); + public Call getInventoryAsync(final ApiCallback> callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = getInventoryCall(, progressListener, progressRequestListener); Type returnType = new TypeToken>(){}.getType(); apiClient.executeAsync(call, returnType, callback); return call; } /* Build call for placeOrder */ - private Call placeOrderCall(Order body) throws ApiException { + private Call placeOrderCall(Order body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = body; @@ -116,8 +154,20 @@ public class StoreApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -127,7 +177,7 @@ public class StoreApi { * @return Order */ public Order placeOrder(Order body) throws ApiException { - Call call = placeOrderCall(body); + Call call = placeOrderCall(body, null, null); Type returnType = new TypeToken(){}.getType(); return apiClient.execute(call, returnType); } @@ -139,15 +189,35 @@ public class StoreApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call placeOrderAsync(Order body, ApiCallback callback) throws ApiException { - Call call = placeOrderCall(body); + public Call placeOrderAsync(Order body, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = placeOrderCall(body, progressListener, progressRequestListener); Type returnType = new TypeToken(){}.getType(); apiClient.executeAsync(call, returnType, callback); return call; } /* Build call for getOrderById */ - private Call getOrderByIdCall(String orderId) throws ApiException { + private Call getOrderByIdCall(String orderId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'orderId' is set @@ -178,8 +248,20 @@ public class StoreApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -189,7 +271,7 @@ public class StoreApi { * @return Order */ public Order getOrderById(String orderId) throws ApiException { - Call call = getOrderByIdCall(orderId); + Call call = getOrderByIdCall(orderId, null, null); Type returnType = new TypeToken(){}.getType(); return apiClient.execute(call, returnType); } @@ -201,15 +283,35 @@ public class StoreApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call getOrderByIdAsync(String orderId, ApiCallback callback) throws ApiException { - Call call = getOrderByIdCall(orderId); + public Call getOrderByIdAsync(String orderId, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = getOrderByIdCall(orderId, progressListener, progressRequestListener); Type returnType = new TypeToken(){}.getType(); apiClient.executeAsync(call, returnType, callback); return call; } /* Build call for deleteOrder */ - private Call deleteOrderCall(String orderId) throws ApiException { + private Call deleteOrderCall(String orderId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'orderId' is set @@ -240,8 +342,20 @@ public class StoreApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "DELETE", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "DELETE", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -250,7 +364,7 @@ public class StoreApi { * @param orderId ID of the order that needs to be deleted */ public void deleteOrder(String orderId) throws ApiException { - Call call = deleteOrderCall(orderId); + Call call = deleteOrderCall(orderId, null, null); apiClient.execute(call); } @@ -261,8 +375,28 @@ public class StoreApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call deleteOrderAsync(String orderId, ApiCallback callback) throws ApiException { - Call call = deleteOrderCall(orderId); + public Call deleteOrderAsync(String orderId, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = deleteOrderCall(orderId, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java index a04470b3b40..4f364db4b12 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java @@ -5,10 +5,16 @@ import io.swagger.client.ApiClient; import io.swagger.client.ApiException; import io.swagger.client.Configuration; import io.swagger.client.Pair; +import io.swagger.client.ProgressRequestBody; +import io.swagger.client.ProgressResponseBody; import com.google.gson.reflect.TypeToken; import com.squareup.okhttp.Call; +import com.squareup.okhttp.Interceptor; +import com.squareup.okhttp.Response; + +import java.io.IOException; import io.swagger.client.model.User; import java.util.*; @@ -37,7 +43,7 @@ public class UserApi { /* Build call for createUser */ - private Call createUserCall(User body) throws ApiException { + private Call createUserCall(User body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = body; @@ -62,8 +68,20 @@ public class UserApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -72,7 +90,7 @@ public class UserApi { * @param body Created user object */ public void createUser(User body) throws ApiException { - Call call = createUserCall(body); + Call call = createUserCall(body, null, null); apiClient.execute(call); } @@ -83,14 +101,34 @@ public class UserApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call createUserAsync(User body, ApiCallback callback) throws ApiException { - Call call = createUserCall(body); + public Call createUserAsync(User body, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = createUserCall(body, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for createUsersWithArrayInput */ - private Call createUsersWithArrayInputCall(List body) throws ApiException { + private Call createUsersWithArrayInputCall(List body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = body; @@ -115,8 +153,20 @@ public class UserApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -125,7 +175,7 @@ public class UserApi { * @param body List of user object */ public void createUsersWithArrayInput(List body) throws ApiException { - Call call = createUsersWithArrayInputCall(body); + Call call = createUsersWithArrayInputCall(body, null, null); apiClient.execute(call); } @@ -136,14 +186,34 @@ public class UserApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call createUsersWithArrayInputAsync(List body, ApiCallback callback) throws ApiException { - Call call = createUsersWithArrayInputCall(body); + public Call createUsersWithArrayInputAsync(List body, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = createUsersWithArrayInputCall(body, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for createUsersWithListInput */ - private Call createUsersWithListInputCall(List body) throws ApiException { + private Call createUsersWithListInputCall(List body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = body; @@ -168,8 +238,20 @@ public class UserApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "POST", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -178,7 +260,7 @@ public class UserApi { * @param body List of user object */ public void createUsersWithListInput(List body) throws ApiException { - Call call = createUsersWithListInputCall(body); + Call call = createUsersWithListInputCall(body, null, null); apiClient.execute(call); } @@ -189,14 +271,34 @@ public class UserApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call createUsersWithListInputAsync(List body, ApiCallback callback) throws ApiException { - Call call = createUsersWithListInputCall(body); + public Call createUsersWithListInputAsync(List body, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = createUsersWithListInputCall(body, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for loginUser */ - private Call loginUserCall(String username, String password) throws ApiException { + private Call loginUserCall(String username, String password, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; @@ -225,8 +327,20 @@ public class UserApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -237,7 +351,7 @@ public class UserApi { * @return String */ public String loginUser(String username, String password) throws ApiException { - Call call = loginUserCall(username, password); + Call call = loginUserCall(username, password, null, null); Type returnType = new TypeToken(){}.getType(); return apiClient.execute(call, returnType); } @@ -250,15 +364,35 @@ public class UserApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call loginUserAsync(String username, String password, ApiCallback callback) throws ApiException { - Call call = loginUserCall(username, password); + public Call loginUserAsync(String username, String password, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = loginUserCall(username, password, progressListener, progressRequestListener); Type returnType = new TypeToken(){}.getType(); apiClient.executeAsync(call, returnType, callback); return call; } /* Build call for logoutUser */ - private Call logoutUserCall() throws ApiException { + private Call logoutUserCall(, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; @@ -283,8 +417,20 @@ public class UserApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -292,7 +438,7 @@ public class UserApi { * */ public void logoutUser() throws ApiException { - Call call = logoutUserCall(); + Call call = logoutUserCall(, null, null); apiClient.execute(call); } @@ -302,14 +448,34 @@ public class UserApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call logoutUserAsync(ApiCallback callback) throws ApiException { - Call call = logoutUserCall(); + public Call logoutUserAsync(final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = logoutUserCall(, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for getUserByName */ - private Call getUserByNameCall(String username) throws ApiException { + private Call getUserByNameCall(String username, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'username' is set @@ -340,8 +506,20 @@ public class UserApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "GET", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -351,7 +529,7 @@ public class UserApi { * @return User */ public User getUserByName(String username) throws ApiException { - Call call = getUserByNameCall(username); + Call call = getUserByNameCall(username, null, null); Type returnType = new TypeToken(){}.getType(); return apiClient.execute(call, returnType); } @@ -363,15 +541,35 @@ public class UserApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call getUserByNameAsync(String username, ApiCallback callback) throws ApiException { - Call call = getUserByNameCall(username); + public Call getUserByNameAsync(String username, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = getUserByNameCall(username, progressListener, progressRequestListener); Type returnType = new TypeToken(){}.getType(); apiClient.executeAsync(call, returnType, callback); return call; } /* Build call for updateUser */ - private Call updateUserCall(String username, User body) throws ApiException { + private Call updateUserCall(String username, User body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = body; // verify the required parameter 'username' is set @@ -402,8 +600,20 @@ public class UserApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "PUT", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "PUT", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -413,7 +623,7 @@ public class UserApi { * @param body Updated user object */ public void updateUser(String username, User body) throws ApiException { - Call call = updateUserCall(username, body); + Call call = updateUserCall(username, body, null, null); apiClient.execute(call); } @@ -425,14 +635,34 @@ public class UserApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call updateUserAsync(String username, User body, ApiCallback callback) throws ApiException { - Call call = updateUserCall(username, body); + public Call updateUserAsync(String username, User body, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = updateUserCall(username, body, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for deleteUser */ - private Call deleteUserCall(String username) throws ApiException { + private Call deleteUserCall(String username, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'username' is set @@ -463,8 +693,20 @@ public class UserApi { final String contentType = apiClient.selectHeaderContentType(contentTypes); headerParams.put("Content-Type", contentType); + if(progressListener != null) { + apiClient.getHttpClient().networkInterceptors().add(new Interceptor() { + @Override + public Response intercept(Interceptor.Chain chain) throws IOException { + Response originalResponse = chain.proceed(chain.request()); + return originalResponse.newBuilder() + .body(new ProgressResponseBody(originalResponse.body(), progressListener)) + .build(); + } + }); + } + String[] authNames = new String[] { }; - return apiClient.buildCall(path, "DELETE", queryParams, postBody, headerParams, formParams, authNames); + return apiClient.buildCall(path, "DELETE", queryParams, postBody, headerParams, formParams, authNames, progressRequestListener); } /** @@ -473,7 +715,7 @@ public class UserApi { * @param username The name that needs to be deleted */ public void deleteUser(String username) throws ApiException { - Call call = deleteUserCall(username); + Call call = deleteUserCall(username, null, null); apiClient.execute(call); } @@ -484,8 +726,28 @@ public class UserApi { * @param callback The callback to be executed when the API call finishes * @return The request call */ - public Call deleteUserAsync(String username, ApiCallback callback) throws ApiException { - Call call = deleteUserCall(username); + public Call deleteUserAsync(String username, final ApiCallback callback) throws ApiException { + + ProgressResponseBody.ProgressListener progressListener = null; + ProgressRequestBody.ProgressRequestListener progressRequestListener = null; + + if(callback != null) { + progressListener = new ProgressResponseBody.ProgressListener() { + @Override + public void update(long bytesRead, long contentLength, boolean done) { + callback.onDownloadProgress(bytesRead, contentLength, done); + } + }; + + progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { + @Override + public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { + callback.onUploadProgress(bytesWritten, contentLength, done); + } + }; + } + + Call call = deleteUserCall(username, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index c072321f457..600455b7592 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -5,7 +5,7 @@ import io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T11:42:25.339-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-21T19:41:14.431+08:00") public class ApiKeyAuth implements Authentication { private final String location; private final String paramName; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/Authentication.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/Authentication.java index 18ca4080c2e..aa2efcd7e9b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/Authentication.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/Authentication.java @@ -5,7 +5,7 @@ import io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T11:42:25.339-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-21T19:41:14.431+08:00") public interface Authentication { /** Apply authentication settings to header and query params. */ void applyToParams(List queryParams, Map headerParams); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/OAuth.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/OAuth.java index bc6473d110f..8463a8bbd28 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/OAuth.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/OAuth.java @@ -5,7 +5,7 @@ import io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-02T22:14:00.422+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-21T19:41:14.431+08:00") public class OAuth implements Authentication { private String accessToken;