use of zipkin2.Call in project BaseProject by feer921.
the class RetrofitClient method cancelAllCall.
/**
* 取消所以添加过的网络请求
*/
public void cancelAllCall() {
if (cachedCalls == null || cachedCalls.isEmpty()) {
return;
}
synchronized (syncLockObj) {
Iterator<Call> callIterator = cachedCalls.keySet().iterator();
while (callIterator.hasNext()) {
Call curCall = callIterator.next();
if (curCall != null) {
curCall.cancel();
}
}
cachedCalls.clear();
}
}
use of zipkin2.Call in project libsignal-service-java by signalapp.
the class PushServiceSocket method getServiceConnection.
private Response getServiceConnection(String urlFragment, String method, String body) throws PushNetworkException {
try {
ConnectionHolder connectionHolder = getRandom(serviceClients, random);
OkHttpClient okHttpClient = connectionHolder.getClient().newBuilder().connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).build();
Log.w(TAG, "Push service URL: " + connectionHolder.getUrl());
Log.w(TAG, "Opening URL: " + String.format("%s%s", connectionHolder.getUrl(), urlFragment));
Request.Builder request = new Request.Builder();
request.url(String.format("%s%s", connectionHolder.getUrl(), urlFragment));
if (body != null) {
request.method(method, RequestBody.create(MediaType.parse("application/json"), body));
} else {
request.method(method, null);
}
if (credentialsProvider.getPassword() != null) {
request.addHeader("Authorization", getAuthorizationHeader(credentialsProvider));
}
if (userAgent != null) {
request.addHeader("X-Signal-Agent", userAgent);
}
if (connectionHolder.getHostHeader().isPresent()) {
request.addHeader("Host", connectionHolder.getHostHeader().get());
}
Call call = okHttpClient.newCall(request.build());
synchronized (connections) {
connections.add(call);
}
try {
return call.execute();
} finally {
synchronized (connections) {
connections.remove(call);
}
}
} catch (IOException e) {
throw new PushNetworkException(e);
}
}
use of zipkin2.Call in project libsignal-service-java by signalapp.
the class PushServiceSocket method uploadToCdn.
private byte[] uploadToCdn(String acl, String key, String policy, String algorithm, String credential, String date, String signature, InputStream data, String contentType, long length, OutputStreamFactory outputStreamFactory) throws PushNetworkException, NonSuccessfulResponseCodeException {
ConnectionHolder connectionHolder = getRandom(cdnClients, random);
OkHttpClient okHttpClient = connectionHolder.getClient().newBuilder().connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).build();
DigestingRequestBody file = new DigestingRequestBody(data, outputStreamFactory, contentType, length);
RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("acl", acl).addFormDataPart("key", key).addFormDataPart("policy", policy).addFormDataPart("Content-Type", contentType).addFormDataPart("x-amz-algorithm", algorithm).addFormDataPart("x-amz-credential", credential).addFormDataPart("x-amz-date", date).addFormDataPart("x-amz-signature", signature).addFormDataPart("file", "file", file).build();
Request.Builder request = new Request.Builder().url(connectionHolder.getUrl()).post(requestBody);
if (connectionHolder.getHostHeader().isPresent()) {
request.addHeader("Host", connectionHolder.getHostHeader().get());
}
Call call = okHttpClient.newCall(request.build());
synchronized (connections) {
connections.add(call);
}
try {
Response response;
try {
response = call.execute();
} catch (IOException e) {
throw new PushNetworkException(e);
}
if (response.isSuccessful())
return file.getTransmittedDigest();
else
throw new NonSuccessfulResponseCodeException("Response: " + response);
} finally {
synchronized (connections) {
connections.remove(call);
}
}
}
use of zipkin2.Call in project openhab-android by openhab.
the class OpenHABNotificationFragment method loadNotifications.
private void loadNotifications() {
Connection conn = ConnectionFactory.getConnection(Connection.TYPE_CLOUD);
if (conn == null) {
return;
}
startProgressIndicator();
mRequestHandle = conn.getAsyncHttpClient().get("/api/v1/notifications?limit=20", new MyHttpClient.ResponseHandler() {
@Override
public void onSuccess(Call call, int statusCode, Headers headers, byte[] responseBody) {
stopProgressIndicator();
Log.d(TAG, "Notifications request success");
try {
String jsonString = new String(responseBody, "UTF-8");
JSONArray jsonArray = new JSONArray(jsonString);
Log.d(TAG, jsonArray.toString());
mNotifications.clear();
for (int i = 0; i < jsonArray.length(); i++) {
try {
JSONObject sitemapJson = jsonArray.getJSONObject(i);
mNotifications.add(OpenHABNotification.fromJson(sitemapJson));
} catch (JSONException e) {
e.printStackTrace();
}
}
mNotificationAdapter.notifyDataSetChanged();
} catch (UnsupportedEncodingException | JSONException e) {
Log.d(TAG, e.getMessage(), e);
}
}
@Override
public void onFailure(Call call, int statusCode, Headers headers, byte[] responseBody, Throwable error) {
stopProgressIndicator();
Log.e(TAG, "Notifications request failure");
}
});
}
use of zipkin2.Call in project openhab-android by openhab.
the class MySyncHttpClient method method.
protected Response method(String url, String method, Map<String, String> addHeaders, String requestBody, String mediaType, final ResponseHandler responseHandler) {
Request.Builder requestBuilder = new Request.Builder();
requestBuilder.url(getBaseUrl().newBuilder(url).build());
for (Map.Entry<String, String> entry : headers.entrySet()) {
requestBuilder.addHeader(entry.getKey(), entry.getValue());
}
if (addHeaders != null) {
for (Map.Entry<String, String> entry : addHeaders.entrySet()) {
requestBuilder.addHeader(entry.getKey(), entry.getValue());
}
}
if (requestBody != null) {
requestBuilder.method(method, RequestBody.create(MediaType.parse(mediaType), requestBody));
}
Request request = requestBuilder.build();
Call call = client.newCall(request);
try {
Response resp = call.execute();
if (resp.isSuccessful()) {
responseHandler.onSuccess(call, resp.code(), resp.headers(), resp.body().bytes());
} else {
responseHandler.onFailure(call, resp.code(), resp.headers(), resp.body().bytes(), new IOException(resp.code() + ": " + resp.message()));
}
return resp;
} catch (IOException ex) {
responseHandler.onFailure(call, 0, new Headers.Builder().build(), null, ex);
return new Response.Builder().code(500).message(ex.getClass().getName() + ": " + ex.getMessage()).request(request).protocol(Protocol.HTTP_1_0).build();
}
}
Aggregations