use of com.squareup.moshi.Moshi.Builder in project ApplicationInsights-Java by microsoft.
the class StatusFileTests method parseJsonFile.
Map parseJsonFile(File tempFolder) throws IOException {
JsonAdapter<Map> adapter = new Builder().build().adapter(Map.class);
String fileName = StatusFile.constructFileName(StatusFile.getJsonMap());
String contents = new String(Files.readAllBytes(new File(tempFolder, fileName).toPath()), UTF_8);
return adapter.fromJson(contents);
}
use of com.squareup.moshi.Moshi.Builder in project ApplicationInsights-Java by microsoft.
the class ProfilerFrontendClientV2 method reportUploadFinish.
/**
* Report to Service Profiler that the profile upload has been completed.
*/
@Override
public Mono<ArtifactAcceptedResponse> reportUploadFinish(UUID profileId, String etag) {
URL requestUrl = uploadFinishedRequestUrl(profileId, etag);
return executePostWithRedirect(requestUrl).flatMap(response -> {
if (response == null) {
// this shouldn't happen, the mono should complete with a response or a failure
return Mono.error(new AssertionError("http response mono returned empty"));
}
int statusCode = response.getStatusCode();
if (statusCode != 201 && statusCode != 202) {
LOGGER.error("Trace upload failed: {}", statusCode);
consumeResponseBody(response);
return Mono.error(new AssertionError("http request failed"));
}
return response.getBodyAsString();
}).flatMap(json -> {
if (json == null) {
// this shouldn't happen, the mono should complete with a response or a failure
return Mono.error(new AssertionError("response body mono returned empty"));
}
try {
JsonAdapter<ArtifactAcceptedResponse> builder = new Builder().build().adapter(ArtifactAcceptedResponse.class);
ArtifactAcceptedResponse data = builder.fromJson(json);
if (data == null) {
return Mono.error(new IllegalStateException("Failed to deserialize response"));
}
return Mono.just(data);
} catch (IOException e) {
return Mono.error(new IllegalStateException("Failed to deserialize response", e));
}
});
}
Aggregations