retrofit

Retrofit REST client for Android and Java does not terminate

我只是一个虾纸丫 提交于 2020-01-28 11:23:07
问题 I am investigating the Retrofit REST client for Android and Java. Using a standard Java project within Eclipse I am using @POST with void return type. Making Asynchronous calls. Everything works as expected, however my test main method never terminates. I have to manually stop each test execution. What do I need to do (or stop doing) so that my tests terminate automatically? Here's my java code. import retrofit.Callback; import retrofit.RestAdapter; import retrofit.RetrofitError; import

How to read hostname from meta-data when providing Retrofit in DI Modules?

萝らか妹 提交于 2020-01-25 08:22:48
问题 I am using Dagger 2 + Retrofit to implement my interfaces which sends/receives data to/from my web service I am referring Philippe BOISNEY's AppModule.java as below private static String BASE_URL = "https://api.github.com/"; @Provides Gson provideGson() { return new GsonBuilder().create(); } @Provides Retrofit provideRetrofit(Gson gson) { Retrofit retrofit = new Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create(gson)) .baseUrl(BASE_URL) .build(); return retrofit; } However I

Passing variable to paging library class

梦想的初衷 提交于 2020-01-24 17:07:49
问题 I am creating an app with Android Paging Library. I'm using retrofit with it. Retrofit code is in ItemDataSource and there i can't pass variable to it. I have some variable coming with intent. How can i set my variable in Retrofit Post method. ItemDataSource public class ItemDataSource extends PageKeyedDataSource<Integer, Item> { //we will start from the first page which is 1 private static final int PAGE_NUMBER = 1; //this will be called once to load the initial data String table

Retrofit LiveDataCallAdapter doesn't call function adapt (call)

*爱你&永不变心* 提交于 2020-01-24 13:28:06
问题 Trying to solve this problem about 4 days, help, please. I'm creating an app with rest API (retrofit), try to implement LiveDataCallAdapter from Google samples https://github.com/googlesamples/android-architecture-components/tree/master/GithubBrowserSample, but retrofit doesn't call adapter method adapt for getting a response from the server. I'm edited only NetworkBoundResourse (for working without DB) Trying to put breakpoints, after I start repo (login), LiveDataCallAdapter fun adapt

Send empty body in POST request in Retrofit

旧巷老猫 提交于 2020-01-24 12:12:18
问题 My api expects an empty json body ( { } ) when making post requests. How do I set this up in Retrofit and Jackson? I tried passing null , and empty string, and "{}" but could not get this to work. @POST(my/url) Call<MyResponse> createPostRequest(@Body Object empty); How can I set an empty JSON body? 回答1: try this . It worked for me now. @POST(my/url) Call<MyResponse> createPostRequest(@Body Hashmap ); while using this method pass new HasMap as paremater apiservice.createPostRequest(new

Send empty body in POST request in Retrofit

点点圈 提交于 2020-01-24 12:12:05
问题 My api expects an empty json body ( { } ) when making post requests. How do I set this up in Retrofit and Jackson? I tried passing null , and empty string, and "{}" but could not get this to work. @POST(my/url) Call<MyResponse> createPostRequest(@Body Object empty); How can I set an empty JSON body? 回答1: try this . It worked for me now. @POST(my/url) Call<MyResponse> createPostRequest(@Body Hashmap ); while using this method pass new HasMap as paremater apiservice.createPostRequest(new

Retrofit 2.x : Log Header for request and response

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-24 02:26:04
问题 I am using retrofit 2.x and i want to log the header and body of request and response . HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .addInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR) .addNetworkInterceptor(new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws IOException { Request request = chain.request()

E/ExoPlayerImplInternal: Source error com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 404

六月ゝ 毕业季﹏ 提交于 2020-01-24 00:11:25
问题 I am trying the play the video by the exo Player, but it gives me this error:- E/ExoPlayerImplInternal: Source error. InvalidResponseCodeException: Response code: 404 This is my Activity Class :- public class VideoActivity extends AppCompatActivity implements VideoRendererEventListener { private String mVideoUrl; private SimpleExoPlayerView simpleExoPlayerView; private SimpleExoPlayer player; private static final String TAG = "AMAN"; @Override protected void onCreate(Bundle savedInstanceState

Retrofit: Unable to create @Body converter for class

依然范特西╮ 提交于 2020-01-22 17:54:05
问题 I need to send next json via retrofit 2: { "Inspection": { "UUID": "name", "ModifiedTime": "2016-03-09T01:13", "CreatedTime": "2016-03-09T01:13", "ReviewedWith": "name2", "Type": 1, "Project": { "Id": 41 }, "ActionTypes": [1] } } With Header: Authorization: access_token_value I tried this: //header parameter String accessToken = Requests.getAccessToken(); JsonObject obj = new JsonObject(); JsonObject inspection = new JsonObject(); inspection.addProperty("UUID","name"); inspection.addProperty(

How to parse Retrofit JSON response

匆匆过客 提交于 2020-01-22 17:08:40
问题 I have a typical Retrofit API request: RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(URL) .build(); ApiEndpointInterface api = restAdapter.create(ApiEndpointInterface.class); api.getToken('1', new Callback<DefaultResponse>() { @Override public void success(DefaultResponse json, Response response) { // } @Override public void failure(RetrofitError response) { // } }); And the returned JSON is: {"success":true,"data":{"token_id":"pPt9AKl0Cg","token_key":"8ax224sFrJZZkStAQuER"