use of zipkin2.Call in project Rocket.Chat.Android by RocketChat.
the class DefaultServerPolicyApi method getOkHttpCallback.
private okhttp3.Callback getOkHttpCallback(@NonNull FlowableEmitter<Response<JSONObject>> emitter, @NonNull String protocol) {
return new okhttp3.Callback() {
@Override
public void onFailure(Call call, IOException ioException) {
if (emitter.isCancelled()) {
return;
}
emitter.onError(ioException);
}
@Override
public void onResponse(Call call, okhttp3.Response response) throws IOException {
if (emitter.isCancelled()) {
return;
}
if (!response.isSuccessful()) {
emitter.onNext(new Response<>(false, protocol, null));
emitter.onComplete();
return;
}
final ResponseBody body = response.body();
if (body == null || body.contentLength() == 0) {
emitter.onNext(new Response<>(false, protocol, null));
emitter.onComplete();
return;
}
try {
emitter.onNext(new Response<>(true, protocol, new JSONObject(body.string())));
} catch (Exception e) {
emitter.onNext(new Response<>(false, protocol, null));
}
emitter.onComplete();
}
};
}
use of zipkin2.Call in project Gradle-demo by Arisono.
the class OkhttpUtils method sendGetHttp.
/**
* get http
* @param url
* @param tag
*/
public static void sendGetHttp(String url, Map<String, Object> params, String cookies, String tag) {
StringBuilder buf = new StringBuilder(url);
if (params != null) {
if (!params.isEmpty()) {
if (url.indexOf("?") == -1)
buf.append("?");
else if (!url.endsWith("&"))
buf.append("&");
Iterator<Map.Entry<String, Object>> entries = params.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<String, Object> entry = entries.next();
buf.append(String.valueOf(entry.getKey())).append("=").append(String.valueOf(entry.getValue())).append("&");
}
buf.deleteCharAt(buf.length() - 1);
}
}
Request request = new Request.Builder().url(buf.toString()).addHeader("content-type", "text/html;charset:utf-8").addHeader("Cookie", "12").build();
OkhttpUtils.println(tag + ":" + buf.toString());
OkhttpUtils.client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
String requestJson;
requestJson = OkhttpUtils.getResponseString(response);
OkhttpUtils.println(requestJson);
RxBus.getInstance().send(tag + ":" + requestJson);
}
@Override
public void onFailure(Call call, IOException e) {
OkhttpUtils.onFailurePrintln(call, e, this);
}
});
}
use of zipkin2.Call in project realm-java by realm.
the class OkHttpAuthenticationServer method logout.
private LogoutResponse logout(URL logoutUrl, String requestBody) throws Exception {
Request request = new Request.Builder().url(logoutUrl).addHeader("Content-Type", "application/json").addHeader("Accept", "application/json").post(RequestBody.create(JSON, requestBody)).build();
Call call = client.newCall(request);
Response response = call.execute();
return LogoutResponse.from(response);
}
use of zipkin2.Call in project okhttp by square.
the class RealWebSocket method connect.
public void connect(OkHttpClient client) {
client = client.newBuilder().protocols(ONLY_HTTP1).build();
final int pingIntervalMillis = client.pingIntervalMillis();
final Request request = originalRequest.newBuilder().header("Upgrade", "websocket").header("Connection", "Upgrade").header("Sec-WebSocket-Key", key).header("Sec-WebSocket-Version", "13").build();
call = Internal.instance.newWebSocketCall(client, request);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
try {
checkResponse(response);
} catch (ProtocolException e) {
failWebSocket(e, response);
closeQuietly(response);
return;
}
// Promote the HTTP streams into web socket streams.
StreamAllocation streamAllocation = Internal.instance.streamAllocation(call);
// Prevent connection pooling!
streamAllocation.noNewStreams();
Streams streams = streamAllocation.connection().newWebSocketStreams(streamAllocation);
// Process all web socket messages.
try {
listener.onOpen(RealWebSocket.this, response);
String name = "OkHttp WebSocket " + request.url().redact();
initReaderAndWriter(name, pingIntervalMillis, streams);
streamAllocation.connection().socket().setSoTimeout(0);
loopReader();
} catch (Exception e) {
failWebSocket(e, null);
}
}
@Override
public void onFailure(Call call, IOException e) {
failWebSocket(e, null);
}
});
}
use of zipkin2.Call in project retrofit by square.
the class CallsTest method deferredThrowExecute.
@Test
public void deferredThrowExecute() throws IOException {
final IOException failure = new IOException("Hey");
Call<Object> failing = Calls.defer(new Callable<Call<Object>>() {
@Override
public Call<Object> call() throws Exception {
throw failure;
}
});
try {
failing.execute();
fail();
} catch (IOException e) {
assertSame(failure, e);
}
}
Aggregations