retrofit2

Android Dagger2 + OkHttp + Retrofit dependency cycle error

北城以北 提交于 2019-11-28 08:26:56
Hey there I am using Dagger2 , Retrofit and OkHttp and I am facing dependency cycle issue. When providing OkHttp : @Provides @ApplicationScope OkHttpClient provideOkHttpClient(TokenAuthenticator auth,Dispatcher dispatcher){ return new OkHttpClient.Builder() .connectTimeout(Constants.CONNECT_TIMEOUT, TimeUnit.SECONDS) .readTimeout(Constants.READ_TIMEOUT,TimeUnit.SECONDS) .writeTimeout(Constants.WRITE_TIMEOUT,TimeUnit.SECONDS) .authenticator(auth) .dispatcher(dispatcher) .build(); } When providing Retrofit : @Provides @ApplicationScope Retrofit provideRetrofit(Resources resources,Gson gson,

SOAP API calling with retrofit getting null body in Android

我的未来我决定 提交于 2019-11-28 06:42:04
问题 I am trying to post an soap xml with Retrofit2 but but getting response 200 ok and body is always null I'm using a Simple XML Framework to model a SOAP request that looks like below code: API calls HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); Strategy strategy = new AnnotationStrategy(); Serializer serializer = new Persister(strategy); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor

Unit testing android application with retrofit and rxjava

一曲冷凌霜 提交于 2019-11-28 06:29:36
I have developed an android app that is using retrofit with rxJava, and now I'm trying to set up the unit tests with Mockito but I don't know how to mock the api responses in order to create tests that do not do the real calls but have fake responses. For instance, I want to test that the method syncGenres is working fine for my SplashPresenter. My classes are as follow: public class SplashPresenterImpl implements SplashPresenter { private SplashView splashView; public SplashPresenterImpl(SplashView splashView) { this.splashView = splashView; } @Override public void syncGenres() { Api

Retrofit 2 - URL Query Parameter

一世执手 提交于 2019-11-28 06:10:30
I am using a query parameters to set the values needed by the Google Maps API. The issue is I do not need the & sign for the first query parameter. @GET("/maps/api/geocode/json?") Call<JsonObject> getLocationInfo(@Query("address") String zipCode, @Query("sensor") boolean sensor, @Query("client") String client, @Query("signature") String signature); Retrofit generates: &address=90210&sensor=false&client=gme-client&signature=signkey which causes the call the fail when I need it to be address=90210&sensor=false&client=gme-client&signature=signkey How do I fix this? If you specify @GET("foobar?a=5

How can we handle different response type with Retrofit 2?

回眸只為那壹抹淺笑 提交于 2019-11-28 05:52:50
I have a webservice that returns either a list of serialized MyPOJO objects: [ { //JSON MyPOJO }, { //JSON MyPOJO } ] either an error object : { 'error': 'foo', 'message':'bar' } Using retrofit2, how can I retrieve the error ? Call<List<MyPOJO>> request = ... request.enqueue(new Callback<List<MyPOJO>>() { @Override public void onResponse(Response<List<MyPOJO>> response) { if (response.isSuccess()) { List<MyPOJO> myList = response.body(); // do something with the list... } else { // server responded with an error, here is how we are supposed to retrieve it ErrorResponse error = ErrorResponse

Expected BEGIN_ARRAY but was BEGIN_OBJECT retrofit2

做~自己de王妃 提交于 2019-11-28 05:48:46
问题 I have some problem about retrofit2 How to fix Expected BEGIN_ARRAY but was BEGIN_OBJECT in retrofit2 I don't know to fix it What's my wrong ? my json is { "result": true, "message": "success", "data": [ { "id": "10", "type_name": "pppppp" }, { "id_mt": "11", "type_name": "aaaaaa" } ] } and my model class is public class MessageFastModel { private boolean result; private String message; private List<DataBean> data; public boolean isResult() { return result; } public void setResult(boolean

Retrofit Post Parameter

人走茶凉 提交于 2019-11-28 05:16:29
I am implementing login feature and for that using Post request but i am getting error saying "retrofit.RetrofitError: com.squareup.okhttp.internal.http.HttpMethod.METHODS" Below is my code import java.util.HashMap; import java.util.Map; import retrofit.Callback; import retrofit.http.*; //Myapi.java import java.util.HashMap; import java.util.Map; import retrofit.Callback; import retrofit.http.*; public interface MyApi { /* LOGIN */ @POST("/api/0.01/oauth2/access_token/") // your login function in your api public void login(@Body HashMap<String, String> arguments, Callback<String> calback); } /

How to make multiple request and wait until data is come from all the requests in retrofit 2.0 - android

戏子无情 提交于 2019-11-28 05:16:06
current code: Retrofit retrofit = new Retrofit.Builder() .baseUrl(Constant.BASEURL) .addConverterFactory(GsonConverterFactory.create()) .build(); APIService service = retrofit.create(APIService.class); Call<ResponseWrap> call = service.getNewsData(); call.enqueue(new Callback<ResponseWrap>() { @Override public void onResponse(Call<ResponseWrap> call1, Response<ResponseWrap> response) { if (response.isSuccess()) { ResponseWrap finalRes = response.body(); for(int i=0; i<finalRes.getResponse().getResults().size(); ++i){ String title = finalRes.getResponse().getResults().get(i).getWebTitle(); News

Retrofit and OkHttp basic authentication

半腔热情 提交于 2019-11-28 04:57:04
I am trying to add basic authentication (username and password) to a Retrofit OkHttp client. This is the code I have so far: private static Retrofit createMMSATService(String baseUrl, String user, String pass) { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrl) .client(client) .addConverterFactory(GsonConverterFactory.create()) .build(); return retrofit; } I am using Retrofit

RxAndroid and Retrofit: Unable to create call adapter for io.reactivex.Observable<retrofit2.Response<okhttp3.ResponseBody>>

孤街浪徒 提交于 2019-11-28 03:10:51
问题 I am trying use rxJava, rxAndroid, Retrofit2, and OkHTTP3 to download a file from a URL endpoint. My code is unable to create the call adapter for an "Observable< retrofit2.Response< okhttp3.ResponseBody>>". These methods are new to me so I believe I'm missing an important concept here. Any direction or points is greatly appreciated. FATAL EXCEPTION: main Process: com.example.khe11e.rxdownloadfile, PID: 14130 java.lang.IllegalArgumentException: Unable to create call adapter for io.reactivex