Search in sources :

Example 46 with Call

use of zipkin2.Call in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_pj_p4.

// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_pj_p4(final OnNetworkCallback_PJ_P4 listener, int member_id, int ex41, int ex42, int ex43, int ex44, int ex45, int ex46, int ex47) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDataPJP4(member_id, ex41, ex42, ex43, ex44, ex45, ex46, ex47);
    call.enqueue(new Callback<POJO_PJ_P4>() {

        @Override
        public void onResponse(Call<POJO_PJ_P4> call, Response<POJO_PJ_P4> response) {
            try {
                POJO_PJ_P4 assessmentstu4 = (POJO_PJ_P4) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(assessmentstu4);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_PJ_P4> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit) POJO_PJ_P4(com.example.user.dvectn.POJO.POJO_PJ_P4)

Example 47 with Call

use of zipkin2.Call in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_pj_p2.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_pj_p2(final OnNetworkCallback_PJ_P2 listener, int member_id, int ex21, int ex22, int ex23, int ex24, int ex25, int ex26, int ex27, int ex28) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDataPJP2(member_id, ex21, ex22, ex23, ex24, ex25, ex26, ex27, ex28);
    call.enqueue(new Callback<POJO_PJ_P2>() {

        @Override
        public void onResponse(Call<POJO_PJ_P2> call, Response<POJO_PJ_P2> response) {
            try {
                POJO_PJ_P2 assessmentstu2 = (POJO_PJ_P2) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(assessmentstu2);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_PJ_P2> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit) POJO_PJ_P2(com.example.user.dvectn.POJO.POJO_PJ_P2)

Example 48 with Call

use of zipkin2.Call in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_test1_in_ag.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// public void callServer_bt_d1(final OnNetworkCallback_BT_D1 listener, int member_id, String  app_name, int app_date, String  app_detai) {
// 
// Gson gson = new GsonBuilder()
// .setLenient()
// .create();
// 
// final Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(Fragment_login.BASE_URL)
// .addConverterFactory(GsonConverterFactory.create(gson))
// .build();
// 
// APISERVER callapi = retrofit.create(APISERVER.class);
// 
// Call call = callapi.getDatadaily(member_id, app_name, app_date, app_detai);
// call.enqueue(new Callback<POJO_Checkdaily>() {
// 
// 
// @Override
// public void onResponse(Call<POJO_Checkdaily> call, Response<POJO_Checkdaily> response) {
// //                Log.e("onResponse",""+response.body());
// 
// try {
// 
// POJO_Checkdaily Checkdaily = (POJO_Checkdaily) response.body();
// 
// if (response.code() != 200) {
// //                        Log.e("Network connected","Response code = "+response.code());
// 
// ResponseBody responseBody = response.errorBody();
// 
// if (responseBody != null) {
// listener.onBodyError(responseBody);
// } else if (responseBody == null) {
// listener.onBodyErrorIsNull();
// }
// 
// //                        Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
// //                        Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
// } else {
// listener.onResponse(Checkdaily);
// }
// 
// } catch (Exception e) {
// //                    Log.e("Network connect error",e.getMessage());
// }
// }
// 
// @Override
// public void onFailure(Call<POJO_Checkdaily> call, Throwable t) {
// Log.e("NT", t.getMessage());
// try {
// 
// listener.onFailure(t);
// 
// } catch (Exception e) {
// 
// listener.onFailure(t);
// //                    Log.e("Network connectLogin",t.getMessage());
// }
// 
// }
// });
// }
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_test1_in_ag(final OnNetworkCallback_test1_in_ag listener, int member_id) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDatatest1(member_id);
    call.enqueue(new Callback<POJO_test1_in_ag>() {

        @Override
        public void onResponse(Call<POJO_test1_in_ag> call, Response<POJO_test1_in_ag> response) {
            try {
                POJO_test1_in_ag test1 = (POJO_test1_in_ag) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(test1);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_test1_in_ag> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) POJO_test1_in_ag(com.example.user.dvectn.POJO.POJO_test1_in_ag) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit)

Example 49 with Call

use of zipkin2.Call in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_dd_p1.

// ///////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_dd_p1(final OnNetworkCallback_DD_P1 listener, int member_id, int ex11, int ex12, int ex13, int ex14, int ex15) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDataDDP1(member_id, ex11, ex12, ex13, ex14, ex15);
    call.enqueue(new Callback<POJO_DD_P1>() {

        @Override
        public void onResponse(Call<POJO_DD_P1> call, Response<POJO_DD_P1> response) {
            try {
                POJO_DD_P1 affective1 = (POJO_DD_P1) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(affective1);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_DD_P1> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) POJO_DD_P1(com.example.user.dvectn.POJO.POJO_DD_P1) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit)

Example 50 with Call

use of zipkin2.Call in project bitcoin-wallet by bitcoin-wallet.

the class DynamicFeeLoader method fetchDynamicFees.

private static void fetchDynamicFees(final HttpUrl url, final File tempFile, final File targetFile, final String userAgent) {
    final Stopwatch watch = Stopwatch.createStarted();
    final Request.Builder request = new Request.Builder();
    request.url(url);
    request.header("User-Agent", userAgent);
    if (targetFile.exists())
        request.header("If-Modified-Since", HttpDate.format(new Date(targetFile.lastModified())));
    OkHttpClient.Builder httpClientBuilder = Constants.HTTP_CLIENT.newBuilder();
    httpClientBuilder.connectTimeout(5, TimeUnit.SECONDS);
    httpClientBuilder.writeTimeout(5, TimeUnit.SECONDS);
    httpClientBuilder.readTimeout(5, TimeUnit.SECONDS);
    final OkHttpClient httpClient = httpClientBuilder.build();
    final Call call = httpClient.newCall(request.build());
    try {
        final Response response = call.execute();
        final int status = response.code();
        if (status == HttpURLConnection.HTTP_NOT_MODIFIED) {
            log.info("Dynamic fees not modified at {}, took {}", url, watch);
        } else if (status == HttpURLConnection.HTTP_OK) {
            final ResponseBody body = response.body();
            final FileOutputStream os = new FileOutputStream(tempFile);
            Io.copy(body.byteStream(), os);
            os.close();
            final Date lastModified = response.headers().getDate("Last-Modified");
            if (lastModified != null)
                tempFile.setLastModified(lastModified.getTime());
            body.close();
            if (!tempFile.renameTo(targetFile))
                throw new IllegalStateException("Cannot rename " + tempFile + " to " + targetFile);
            watch.stop();
            log.info("Dynamic fees fetched from {}, took {}", url, watch);
        } else {
            log.warn("HTTP status {} when fetching dynamic fees from {}", response.code(), url);
        }
    } catch (final Exception x) {
        log.warn("Problem when fetching dynamic fees rates from " + url, x);
    }
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Stopwatch(com.google.common.base.Stopwatch) Request(okhttp3.Request) HttpDate(okhttp3.internal.http.HttpDate) Date(java.util.Date) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody) Response(okhttp3.Response) FileOutputStream(java.io.FileOutputStream)

Aggregations

Call (okhttp3.Call)409 Response (okhttp3.Response)309 Request (okhttp3.Request)282 IOException (java.io.IOException)232 Call (retrofit2.Call)134 Callback (okhttp3.Callback)133 OkHttpClient (okhttp3.OkHttpClient)98 Test (org.junit.Test)88 ResponseBody (okhttp3.ResponseBody)76 RequestBody (okhttp3.RequestBody)58 Retrofit (retrofit2.Retrofit)48 Gson (com.google.gson.Gson)47 Response (retrofit2.Response)47 File (java.io.File)44 Headers (okhttp3.Headers)41 Callback (retrofit2.Callback)41 GsonBuilder (com.google.gson.GsonBuilder)40 JSONObject (org.json.JSONObject)39 MockResponse (okhttp3.mockwebserver.MockResponse)38 List (java.util.List)35