retrofit2

How to retry Retrofit call on HTTP errors (401) when using RxJava?

旧巷老猫 提交于 2019-12-12 13:00:54
问题 My current Android Application is employing Retrofit(2.4.0) and RxJava(2.1.16) to execute my Web Service calls. Im using Google SignIn for my User Authentication. I want my Retrofit calls to detect HTTP 401 (UNAUTHORIZED) and attempt to Silently Login with Google Signin then retry the Retrofit call. My retrofit calls resemble this @Headers(HEADER_ACCEPT_JSON) @GET("resources") Observable<Response<String>> getResources(@Header(HEADER_AUTHORIZATION) @NonNull final String authenticationToken,

how to send JSONObject into retrofit API call android

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 12:01:28
问题 I have implemented first time retrofit in my android code and facing follwing issues getting following error : java.lang.IllegalArgumentException: @Body parameters cannot be used with form or multi-part encoding. (parameter #1) I have implemented my code like below public interface APIService { @FormUrlEncoded @POST("/") @Headers({ "domecode: axys", "Content-Type: application/json;charset=UTF-8" }) Call<JsonObject> sendLocation(@Body JsonObject jsonObject); } public class ApiUtils { static

Retrofit2 handling HTTP 204 (No Content response ) situation with RxJava's Observable concepts

a 夏天 提交于 2019-12-12 10:54:05
问题 I have a web-service which return a list of users for a topic, if there is no any user for that topic it just returns HTTP code 204( No Content). This is my retrofit2 call for that service (in Kotlin) @GET("/user/{topic}") fun getAllUserFor(@Path(value="topic",encoded=true) topic:String) :Observable<List<User>> And my execution is : fun getAllUsers(topic: String, onSuccess: Consumer<List<User>>, onFail:Consumer<Throwable>){ val api = NetworkLayer.getUserApi() api.getAllUserFor(topic)

RxJava and cursor based RESTful pagination

自闭症网瘾萝莉.ら 提交于 2019-12-12 10:46:46
问题 I'm working with the Spotify API and am hoping to chain a few paginated results using RxJava. Spotify uses cursor based pagination, so solutions like the one from @lopar will not work. The response is from this call and looks something like this (imagine there are 50 items ): { "artists" : { "items" : [ { "id" : "6liAMWkVf5LH7YR9yfFy1Y", "name" : "Portishead", "type" : "artist" }], "next" : "https://api.spotify.com/v1/me/following?type=artist&after=6liAMWkVf5LH7YR9yfFy1Y&limit=50", "total" :

Logging with Retrofit2 without OkHttp intercept

蓝咒 提交于 2019-12-12 09:58:28
问题 I want to log the complete request (url, request param, body) of retrofit2 request without using okHttp Library. How can it be done 回答1: You have to add logging-interceptor: compile 'com.squareup.okhttp3:logging-interceptor:3.4.1' compile 'com.squareup.retrofit2:retrofit:2.1.0' OkHttpClient.Builder builder = new OkHttpClient.Builder(); HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); builder

Android Retrofit 2 Simple XML Converter

时光怂恿深爱的人放手 提交于 2019-12-12 07:34:01
问题 I am using Retrofit 2.1.0 and Retrofit SimpleXML Converter 2.1.0 . I added simplexmlconverter to retrofit instance with addConverterFactory method. XML is below <?xml version="1.0" encoding="UTF-8"?> <rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" version="2.0"> <channel> <title>title</title> <description></description> <language>en-us</language>

How to handle errors with Retrofit?

╄→гoц情女王★ 提交于 2019-12-12 07:07:54
问题 My server returns a basic JSON structure for all request like: { "success": false, "data": { "errors": { "email": [ "This is not an email." ], "password": [ "The password must be at least 6 characters." ] } } } Where success can be true or false, and data can return a number of things, from errors to data the app might need. How can I handle this response (both success and error) using Retrofit? What would need to be changed/added to my Retrofit API call? Call<BasicResponse> call = apiService

How to add the json response into spinner in android using retrofit?

故事扮演 提交于 2019-12-12 07:02:09
问题 In our project we don't hard code the Label and dropdown , we assign the value to Label from JSON . I don't understand how to assign the gender array to dropdown . Here is the response getting from URL { "statusCode": "200", "statusMessage": "SUCCESS", "meetmeConfig": { "id": "bb52dc0f-29d0-4079-99c7-a07c8045a829", "moduleName": "MeetMe", "createdDate": 1523962430721, "configContent": { "trackingOptions": [ { "optionName": "Before the meet", "isTimeRequired": true, "trackingTime": [ 5, 10, 15

Android How to sum total of two different list in same fragment called with retrofit2?

不打扰是莪最后的温柔 提交于 2019-12-12 05:27:36
问题 i have two lists called with retrofit 2 in the same fragment both list are of different objects and the response is working ok Each object has a field (importe (represents money)) that i have to sum (method calculateTotal, that sum the objects of a list), so here is the problem: how can i sum the total of list1 + total of list2?? i need to show in textView the total sum of the two list: Total.setText(totalAtenciones+totalNotas) @Override public View onCreateView(LayoutInflater inflater,

“java.nio.charset.UnsupportedCharsetException: utf8mb4” error in retrofit

你。 提交于 2019-12-12 05:02:21
问题 10-26 23:29:25.422 30062-30062/okok.com.retrofittrial W/System.err: java.nio.charset.UnsupportedCharsetException: utf8mb4 10-26 23:29:25.422 30062-30062/okok.com.retrofittrial W/System.err: at java.nio.charset.Charset.forName(Charset.java:571) 10-26 23:29:25.422 30062-30062/okok.com.retrofittrial W/System.err: at okhttp3.MediaType.charset(MediaType.java:103) 10-26 23:29:25.422 30062-30062/okok.com.retrofittrial W/System.err: at okhttp3.ResponseBody.charset(ResponseBody.java:114) 10-26 23:29