use of zipkin2.Call in project openhab-android by openhab.
the class MyWebImage method getBitmapFromUrl.
private Bitmap getBitmapFromUrl(Context context, final String url) {
final Map<String, Object> result = new HashMap<String, Object>();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
MyAsyncHttpClient client = new MyAsyncHttpClient(context, prefs.getBoolean(Constants.PREFERENCE_SSLHOST, false), prefs.getBoolean(Constants.PREFERENCE_SSLCERT, false));
client.setTimeout(READ_TIMEOUT);
client.setBaseUrl(url);
if (shouldAuth) {
client.setBasicAuth(authUsername, authPassword);
}
client.get(url, new MyHttpClient.ResponseHandler() {
@Override
public void onFailure(Call call, int statusCode, Headers headers, byte[] responseBody, Throwable error) {
Log.e(TAG, "Failed to get " + url + " with code " + statusCode + ":" + error);
synchronized (result) {
result.put("error", error);
result.notify();
}
}
@Override
public void onSuccess(Call call, int statusCode, Headers headers, byte[] responseBody) {
InputStream is = new ByteArrayInputStream(responseBody);
Map headersMap = headers.toMultimap();
boolean isSVG = headersMap.containsKey("content-type") && headersMap.get("content-type").toString().contains("svg");
synchronized (result) {
result.put("bitmap", getBitmapFromInputStream(isSVG, is));
result.notify();
}
}
});
synchronized (result) {
try {
result.wait(60000);
} catch (InterruptedException e) {
Log.e(TAG, "Timeout fetching " + url);
return null;
}
if (result.containsKey("error")) {
return null;
}
}
Log.i(TAG, "fetched bitmap for " + url);
return (Bitmap) result.get("bitmap");
}
use of zipkin2.Call in project openhab-android by openhab.
the class DefaultConnectionTest method testSyncResolveAbsoluteUrl.
@Test
public void testSyncResolveAbsoluteUrl() {
MyHttpClient httpClient = testConnection.getSyncHttpClient();
httpClient.get("http://mylocalmachine.local/rest/test", new MyHttpClient.TextResponseHandler() {
@Override
public void onFailure(Call call, int statusCode, Headers headers, String responseBody, Throwable error) {
assertEquals("http://mylocalmachine.local/rest/test", call.request().url().toString());
}
@Override
public void onSuccess(Call call, int statusCode, Headers headers, String responseBody) {
fail("The request should never succeed in tests.");
}
});
}
use of zipkin2.Call in project openhab-android by openhab.
the class MySyncHttpClientTest method testMethodErrorResponse.
/**
* Unit test against Issue #315 "Crash when connection could not be established"
*/
@Test
public void testMethodErrorResponse() {
MySyncHttpClient httpClient = new MySyncHttpClient(null, false, true);
httpClient.setBaseUrl("https://demo.test");
String host = "just.a.local.url.local";
Response resp = httpClient.method("https://" + host, "GET", new HashMap<String, String>(), null, "", new MyHttpClient.ResponseHandler() {
public void onFailure(Call call, int statusCode, Headers headers, byte[] responseBody, Throwable error) {
}
public void onSuccess(Call call, int statusCode, Headers headers, byte[] responseBody) {
}
});
assertEquals(500, resp.code());
assertTrue(resp.message().startsWith(UnknownHostException.class.getName()));
}
use of zipkin2.Call in project DVECTN by tanaponudom.
the class NetworkConnectionManager method callSrever_getstuemp.
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void callSrever_getstuemp(final OnNetworkCallback_getstuemp listener, String dep_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.get_getstuemp(dep_id);
call.enqueue(new Callback<List<POJO_getstuemp>>() {
@Override
public void onResponse(Call<List<POJO_getstuemp>> call, Response<List<POJO_getstuemp>> response) {
try {
List<POJO_getstuemp> getstuemp = (List<POJO_getstuemp>) 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(getstuemp);
}
} catch (Exception e) {
// Log.e("Network connect error",e.getMessage());
}
}
@Override
public void onFailure(Call<List<POJO_getstuemp>> call, Throwable t) {
Log.e("NT", t.getMessage());
try {
listener.onFailure(t);
} catch (Exception e) {
listener.onFailure(t);
// Log.e("Network connectLogin",t.getMessage());
}
}
});
}
use of zipkin2.Call in project DVECTN by tanaponudom.
the class NetworkConnectionManager method callServer_row_teacher.
// ////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_row_teacher(final OnNetworkCallback_row_teacher listener, int member_id, String score, int spn) {
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.get_away_font_me(member_id, score, spn);
call.enqueue(new Callback<POJO_row_teacher>() {
@Override
public void onResponse(Call<POJO_row_teacher> call, Response<POJO_row_teacher> response) {
try {
POJO_row_teacher row_roi = (POJO_row_teacher) 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(row_roi);
}
} catch (Exception e) {
// Log.e("Network connect error",e.getMessage());
}
}
@Override
public void onFailure(Call<POJO_row_teacher> call, Throwable t) {
Log.e("NT", t.getMessage());
try {
listener.onFailure(t);
} catch (Exception e) {
listener.onFailure(t);
// Log.e("Network connectLogin",t.getMessage());
}
}
});
}
Aggregations