Search code examples
androidretrofitrx-javarx-androidokhttp

How can I get request url from retrofit with rx ? - Android


MinSdkVersion of my application is 17 and targetSdkVersion is 25 .In this application I am connecting to service with Rx and retrofit, this code don't work on api 17 I can't connect to webService, bellow is my code :

My RetrofitApi.java :

public class RetrofitApi {
    private static PublicApi retrofit = null;

    public static PublicApi getClient(String url) {
        retrofit = new Retrofit.Builder()
                .baseUrl(url)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build().create(PublicApi.class);
        return retrofit;
    }
}

My PublicApi.java :

public interface PublicApi {

    @GET("/web_service/mobile/rest")
    Observable<LastNews> lastNews(@Query("function") String function);
}

And :

PublicApi publicApi = RetrofitApi.getClient("https://xxx.xxx.xxx/");
CompositeDisposable mCompositeDisposable = new CompositeDisposable();
mCompositeDisposable.add(publicApi.lastNews("getLastNews")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(this::responseLastNews, this::errorLastNews));
private void responseLastNews(LastNews lastNewses){
}
private void errorLastNews(Throwable error) {
    Log.i("LOG", error.getMessage());
}

When I tested on API 17 get me error and don't connect to server.Told me :

java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

Solution

  • Your base URL (**https**://xxx.xxx.xxx/) is secured with SSL, you need to implement SSL connection to get it working.

    Please refer this link