retrofit2

Retrofit 2 + RxAndroid: Handle Errors (4xx and some 200)

人走茶凉 提交于 2020-01-13 14:56:13
问题 I saw a lot of articles and questions about error handling using retrofit combined with RxAndroid, but i am not able to set my configuration right. What do I want to accomplish: when receiving a 4xx code: handle it on onError() when receiving a 2xx code: -> try to parse to expected response and deliver it onNext() -> If not possible try to convert the JSON answer to MyAPIError class (simple POJO with errorNum and message) and deliver it on onError. So either 2xx or 4xx http codes might end up

Retrofit generic response handler

随声附和 提交于 2020-01-13 13:52:50
问题 I wish to handle all my responses in single method. the purpose is to recall the service when the response code is not 3, when the response code is 3 I intend to first refresh the token and then recall the same service. I've created a Basecallback class to catch one method but I can't see the log and can't catch breakpoints. BASECALLBACK.class public class BaseCallBack<T> implements Callback<T> { @Override public void onResponse(Call<T> call, Response<T> response) { if (!response.isSuccessful

Retrofit generic response handler

南笙酒味 提交于 2020-01-13 13:52:26
问题 I wish to handle all my responses in single method. the purpose is to recall the service when the response code is not 3, when the response code is 3 I intend to first refresh the token and then recall the same service. I've created a Basecallback class to catch one method but I can't see the log and can't catch breakpoints. BASECALLBACK.class public class BaseCallBack<T> implements Callback<T> { @Override public void onResponse(Call<T> call, Response<T> response) { if (!response.isSuccessful

Retrofit2 post method showing server internal error but postman giving response

那年仲夏 提交于 2020-01-13 13:47:50
问题 I am very new to retroft. I am using retrofit2 for my API integration. I have an API for POST method. I am sending the body from postman and I am getting response, but when I am doing this programatically I am getting "Internal Server Error". This is my post man response And my code is private void savePost(String post_body, String permission, String latitude, String longitude, String location) { try { Retrofit retrofit = new Retrofit.Builder() .baseUrl(BuildConfig.BASE_URL)

How to make RxErrorHandlingCallAdapterFactory?

帅比萌擦擦* 提交于 2020-01-12 05:30:10
问题 I found this. But in new ver compile 'com.squareup.retrofit2:adapter-rxjava:2.2.0' at CallAdapter it has two params CallAdapter<?,?> How to modify RxCallAdapterWrapper to implement if from CallAdapter<?,?> 回答1: Disclaimer: I'm the author of the blog post you referenced The original post was meant as a proof of concept and for RxJava 2 so it's easier for me to explain with that version too, but I'll try and cover more ground. I'm guessing you're using version 1, since you talk about adapter

Android Upload Multiple Files In A Single Request

自作多情 提交于 2020-01-11 12:53:27
问题 I'm posting content to the server in a multipart/form-data request. and the data I'm posting contains multiple parameters including a file array parameter (files[]). Using postman I'm setting the parameters and the files as: first-parameter=text content second-parameter=text content files[0]={first selected file} files[1]={second selected file} Submitting this request on postman is always successful, and the files are uploaded successfully. When I generate code snippets on postman, this is

Upload a file to AWS S3 pre-signed URL using Retrofit2

对着背影说爱祢 提交于 2020-01-11 10:01:47
问题 I'm trying to upload a file to Amazon's S3 using a pre-signed URL. I get the URL from a server which generates the URL & sends it to me as part of a JSON object. I get the URL as a String, something like this: https://com-example-mysite.s3-us-east-1.amazonaws.com/userFolder/ImageName?X-Amz-Security-Token=xxfooxx%2F%2F%2F%2F%2F%2F%2F%2F%2F%2Fxxbarxx%3D&X-Amz-Algorithm=xxAlgoxx&X-Amz-Date=20170831T090152Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=xxcredxx&X-Amz-Signature

Deserializing json from retrofit using jackson where same variable name can represent two different objects

杀马特。学长 韩版系。学妹 提交于 2020-01-11 09:42:09
问题 The response from retrofit2 may be of the following types.(and we don't know before hand which response will come) { "id": "abc", "place": "LA", "driverId": "abbabaaan" } or { "id": "abc", "place": "LA", "driverId": { "name": "xyz", "id": "jygsdsah", "car": "merc" } } Is there any way to define a class so that while deserializing jackson will check the type of object "driverId" contains and assigns it to say "driverIdObj" field or "driverIdStr" field in the class. 回答1: You could deserialize

Deserializing json from retrofit using jackson where same variable name can represent two different objects

可紊 提交于 2020-01-11 09:42:08
问题 The response from retrofit2 may be of the following types.(and we don't know before hand which response will come) { "id": "abc", "place": "LA", "driverId": "abbabaaan" } or { "id": "abc", "place": "LA", "driverId": { "name": "xyz", "id": "jygsdsah", "car": "merc" } } Is there any way to define a class so that while deserializing jackson will check the type of object "driverId" contains and assigns it to say "driverIdObj" field or "driverIdStr" field in the class. 回答1: You could deserialize

Retrofit 2 Multipart image upload with data

北城以北 提交于 2020-01-10 20:13:29
问题 Hello everyone I want to post image and other data through Retrofit2. I am sending data with one image. All the other info is storing but my image is not storing.while i am testing with postman, it works. please guide me where I am lacking in my code This is the postman code snippet that works OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"); RequestBody body = RequestBody.create(mediaType, "