Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set connection and socket timeout for default swagger android client

I am using android api generated by default Swagger codegen (in Swagger Editor). The problem is that there is no any option, how to set connection timeout and socket timeout.

Is there any elegant way to set timeout without any change in generated code? Or do I have to implement my own timer, which will terminate server call?

Thanks for any advice!

like image 976
matusalem Avatar asked Jul 13 '26 21:07

matusalem


1 Answers

I don't think the default Android API client has any helper method to set the connection timeout.

I would suggest you to use the okhttp-gson HTTP library for Java instead (which is compatible with Android). Here is the command to generate Java client with the okhttp-gson library:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-i modules/swagger-codegen/src/test/resources/2_0/petstore.json \
-l java \
-o /var/tmp/java-okhttp-gson/ \
-D library=okhttp-gson

and it allows setting the HTTP connection timeout via the setConnectTimeout method in ApiClient

like image 67
William Cheng Avatar answered Jul 16 '26 10:07

William Cheng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!