use of com.tonyodev.fetch2.Request in project zipkin by openzipkin.
the class HttpCallTest method propagatesOnDispatcherThreadWhenFatal.
@Test
public void propagatesOnDispatcherThreadWhenFatal() throws Exception {
mws.enqueue(new MockResponse());
http.newCall(request, b -> {
throw new LinkageError();
}).submit(callback);
SimpleTimeLimiter timeLimiter = new SimpleTimeLimiter();
try {
timeLimiter.callWithTimeout(callback::get, 100, TimeUnit.MILLISECONDS, true);
failBecauseExceptionWasNotThrown(UncheckedTimeoutException.class);
} catch (UncheckedTimeoutException expected) {
}
}
use of com.tonyodev.fetch2.Request in project zipkin by openzipkin.
the class HttpCallTest method executionException_conversionException.
@Test
public void executionException_conversionException() throws Exception {
mws.enqueue(new MockResponse());
http.newCall(request, b -> {
throw new IllegalArgumentException("eeek");
}).submit(callback);
try {
callback.get();
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException expected) {
assertThat(expected).isInstanceOf(IllegalArgumentException.class);
}
}
use of com.tonyodev.fetch2.Request in project zipkin by openzipkin.
the class ElasticsearchHttpStorage method flush.
/** This is a blocking call, only used in tests. */
static void flush(HttpCall.Factory factory, String index) throws IOException {
Request flushRequest = new Request.Builder().url(factory.baseUrl.newBuilder().addPathSegment(index).addPathSegment("_flush").build()).post(RequestBody.create(APPLICATION_JSON, "")).tag("flush-index").build();
factory.execute(flushRequest, b -> null);
}
use of com.tonyodev.fetch2.Request in project Pokemap by omkarmoghe.
the class NetworkRequestLoggingInterceptor method convertRequestBodyToString.
private String convertRequestBodyToString(final Request request) {
try {
final Request copy = request.newBuilder().build();
final Buffer buffer = new Buffer();
copy.body().writeTo(buffer);
return buffer.readUtf8();
} catch (final IOException e) {
e.printStackTrace();
Log.e(TAG, "Failed to convert request body to string via convertRequestBodyToString(). Raised: " + e.getMessage());
return null;
}
}
use of com.tonyodev.fetch2.Request in project Pokemap by omkarmoghe.
the class NetworkRequestLoggingInterceptor method intercept.
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
final Request request = chain.request();
// Log request
Log.d(TAG, MessageFormat.format(REQUEST_SEND_LOG, request.method(), sanitize(request.url()), chain.connection(), request.headers()));
if (request.method().compareToIgnoreCase("post") == 0)
Log.d(TAG, MessageFormat.format(REQUEST_BODY_LOG, convertRequestBodyToString(request)));
final long requestStart = System.currentTimeMillis();
final Response response = chain.proceed(request);
final long requestEnd = System.currentTimeMillis();
final long responseTime = requestEnd - requestStart;
// Log response
Log.d(TAG, MessageFormat.format(RESPONSE_RECEIVE_LOG, responseTime, sanitize(response.request().url()), response.headers()));
final String responseBodyString = response.body().string();
if (responseBodyString.length() > 0)
Log.d(TAG, MessageFormat.format(RESPONSE_BODY_LOG, responseBodyString.trim()));
return response.newBuilder().body(ResponseBody.create(response.body().contentType(), responseBodyString)).build();
}
Aggregations