use of com.squareup.moshi.JsonReader in project zipkin by openzipkin.
the class AWSSignatureVersion4 method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request input = chain.request();
Request signed = sign(input);
Response response = chain.proceed(signed);
if (response.code() == 403) {
try (ResponseBody body = response.body()) {
JsonReader message = enterPath(JsonReader.of(body.source()), "message");
if (message != null)
throw new IllegalStateException(message.nextString());
}
throw new IllegalStateException(response.toString());
}
return response;
}
use of com.squareup.moshi.JsonReader in project zipkin by openzipkin.
the class ElasticsearchDomainEndpoint method get.
@Override
public List<String> get() {
try (Response response = client.newCall(describeElasticsearchDomain).execute()) {
if (!response.isSuccessful()) {
throw new IllegalStateException(response.body().string());
}
JsonReader endpointReader = enterPath(JsonReader.of(response.body().source()), "DomainStatus", "Endpoint");
checkArgument(endpointReader != null, "DomainStatus.Endpoint wasn't present in response");
String endpoint = endpointReader.nextString();
if (!endpoint.startsWith("https://")) {
endpoint = "https://" + endpoint;
}
log.fine("using endpoint " + endpoint);
return Collections.singletonList(endpoint);
} catch (IOException e) {
throw new IllegalStateException("couldn't lookup domain endpoint", e);
}
}
use of com.squareup.moshi.JsonReader in project zipkin by openzipkin.
the class SearchResultConverter method convert.
@Override
public List<T> convert(BufferedSource content) throws IOException {
JsonReader hits = enterPath(JsonReader.of(content), "hits", "hits");
if (hits == null || hits.peek() != JsonReader.Token.BEGIN_ARRAY)
return defaultValue;
List<T> result = new ArrayList<>();
hits.beginArray();
while (hits.hasNext()) {
JsonReader source = enterPath(hits, "_source");
if (source != null) {
result.add(adapter.fromJson(source));
}
hits.endObject();
}
hits.endArray();
return result.isEmpty() ? defaultValue : result;
}
use of com.squareup.moshi.JsonReader in project zipkin by openzipkin.
the class ElasticsearchHttpStorage method ensureClusterReady.
CheckResult ensureClusterReady(String index) {
Request request = new Request.Builder().url(http().baseUrl.resolve("/_cluster/health/" + index)).tag("get-cluster-health").build();
try {
return http().execute(request, b -> {
b.request(Long.MAX_VALUE);
Buffer body = b.buffer();
JsonReader status = enterPath(JsonReader.of(body.clone()), "status");
if (status == null) {
throw new IllegalStateException("Health status couldn't be read " + body.readUtf8());
}
if ("RED".equalsIgnoreCase(status.nextString())) {
throw new IllegalStateException("Health status is RED");
}
return CheckResult.OK;
});
} catch (RuntimeException e) {
return CheckResult.failed(e);
}
}
Aggregations