use of okhttp3.Request in project zipkin by openzipkin.
the class ElasticsearchHttpStorageTest method memoizesIndexTemplate.
@Test
public void memoizesIndexTemplate() throws Exception {
es.enqueue(new MockResponse().setBody("{\"version\":{\"number\":\"2.4.0\"}}"));
// get template
es.enqueue(new MockResponse());
// dependencies request
es.enqueue(new MockResponse());
// dependencies request
es.enqueue(new MockResponse());
long endTs = storage.indexNameFormatter().parseDate("2016-10-02");
storage.spanStore().getDependencies(endTs, TimeUnit.DAYS.toMillis(1));
storage.spanStore().getDependencies(endTs, TimeUnit.DAYS.toMillis(1));
// get version
es.takeRequest();
// get template
es.takeRequest();
assertThat(es.takeRequest().getPath()).startsWith("/zipkin-2016-10-01,zipkin-2016-10-02/dependencylink/_search");
assertThat(es.takeRequest().getPath()).startsWith("/zipkin-2016-10-01,zipkin-2016-10-02/dependencylink/_search");
}
use of okhttp3.Request in project zipkin by openzipkin.
the class HttpBulkSpanIndexerTest method doesntWriteSpanId.
@Test
public void doesntWriteSpanId() throws Exception {
es.enqueue(new MockResponse());
indexer.add("test_zipkin_http-2016-10-01", TestObjects.LOTS_OF_SPANS[0], (Long) null);
indexer.execute(callback);
callback.get();
RecordedRequest request = es.takeRequest();
assertThat(request.getBody().readByteString().utf8()).doesNotContain("\"_id\"");
}
use of okhttp3.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 okhttp3.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();
}
use of okhttp3.Request in project android-oss by kickstarter.
the class ApiExceptionFactory method badRequestException.
@NonNull
public static ApiException badRequestException() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().errorMessages(Collections.singletonList("bad request")).httpCode(400).build();
final ResponseBody body = ResponseBody.create(null, "");
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(400, body);
return new ApiException(envelope, response);
}
Aggregations