Search in sources :

Example 6 with HttpResponse

use of com.google.firebase.crashlytics.internal.network.HttpResponse in project firebase-android-sdk by firebase.

the class DefaultSettingsSpiCallTest method testHandleResponse_requestSuccessfulValidJson.

public void testHandleResponse_requestSuccessfulValidJson() throws IOException {
    final HttpResponse mockHttpResponse = mock(HttpResponse.class);
    when(mockHttpResponse.code()).thenReturn(HttpURLConnection.HTTP_OK);
    when(mockHttpResponse.body()).thenReturn(getJsonContentFrom("default_settings.json"));
    assertNotNull(defaultSettingsSpiCall.handleResponse(mockHttpResponse));
}
Also used : HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse)

Example 7 with HttpResponse

use of com.google.firebase.crashlytics.internal.network.HttpResponse in project GreenHouse by utsanjan.

the class NativeCreateReportSpiCall method invoke.

// com.google.firebase.crashlytics.internal.report.network.CreateReportSpiCall
@Override
public boolean invoke(CreateReportRequest requestData, boolean dataCollectionToken) {
    if (dataCollectionToken) {
        HttpRequest httpRequest = getHttpRequest();
        HttpRequest httpRequest2 = applyMultipartDataTo(applyHeadersTo(httpRequest, requestData.googleAppId), requestData.organizationId, requestData.report);
        Logger logger = Logger.getLogger();
        logger.d("Sending report to: " + getUrl());
        try {
            HttpResponse httpResponse = httpRequest2.execute();
            int statusCode = httpResponse.code();
            Logger logger2 = Logger.getLogger();
            logger2.d("Result was: " + statusCode);
            return ResponseParser.parse(statusCode) == 0;
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    } else {
        throw new RuntimeException("An invalid data collection token was used.");
    }
}
Also used : HttpRequest(com.google.firebase.crashlytics.internal.network.HttpRequest) HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse) IOException(java.io.IOException) Logger(com.google.firebase.crashlytics.internal.Logger)

Example 8 with HttpResponse

use of com.google.firebase.crashlytics.internal.network.HttpResponse in project GreenHouse by utsanjan.

the class AbstractAppSpiCall method invoke.

// com.google.firebase.crashlytics.internal.settings.network.AppSpiCall
@Override
public boolean invoke(AppRequestData requestData, boolean dataCollectionToken) {
    if (dataCollectionToken) {
        HttpRequest httpRequest = applyMultipartDataTo(applyHeadersTo(getHttpRequest(), requestData), requestData);
        Logger logger = Logger.getLogger();
        logger.d("Sending app info to " + getUrl());
        try {
            HttpResponse httpResponse = httpRequest.execute();
            int statusCode = httpResponse.code();
            String kind = "POST".equalsIgnoreCase(httpRequest.method()) ? "Create" : "Update";
            Logger logger2 = Logger.getLogger();
            logger2.d(kind + " app request ID: " + httpResponse.header(AbstractSpiCall.HEADER_REQUEST_ID));
            Logger logger3 = Logger.getLogger();
            logger3.d("Result was " + statusCode);
            return ResponseParser.parse(statusCode) == 0;
        } catch (IOException ioe) {
            Logger.getLogger().e("HTTP request failed.", ioe);
            throw new RuntimeException(ioe);
        }
    } else {
        throw new RuntimeException("An invalid data collection token was used.");
    }
}
Also used : HttpRequest(com.google.firebase.crashlytics.internal.network.HttpRequest) HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse) IOException(java.io.IOException) Logger(com.google.firebase.crashlytics.internal.Logger)

Example 9 with HttpResponse

use of com.google.firebase.crashlytics.internal.network.HttpResponse in project firebase-android-sdk by firebase.

the class DefaultSettingsSpiCallTest method testHandleResponse_requestSuccessfulNoJson.

public void testHandleResponse_requestSuccessfulNoJson() {
    final HttpResponse mockHttpResponse = mock(HttpResponse.class);
    when(mockHttpResponse.code()).thenReturn(HttpURLConnection.HTTP_OK);
    when(mockHttpResponse.body()).thenReturn("No Json here!");
    assertNull(defaultSettingsSpiCall.handleResponse(mockHttpResponse));
    // Verify failing to parse a JSON object does not result in an error log.
    verify(mockLogger, never()).e(anyString());
}
Also used : HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse)

Example 10 with HttpResponse

use of com.google.firebase.crashlytics.internal.network.HttpResponse in project firebase-android-sdk by firebase.

the class DefaultSettingsSpiCallTest method testHandleResponse_requestSuccessfulValidJson.

public void testHandleResponse_requestSuccessfulValidJson() throws IOException {
    final HttpResponse mockHttpResponse = mock(HttpResponse.class);
    when(mockHttpResponse.code()).thenReturn(HttpURLConnection.HTTP_OK);
    when(mockHttpResponse.body()).thenReturn(getJsonContentFrom("default_settings.json"));
    assertNotNull(defaultSettingsSpiCall.handleResponse(mockHttpResponse));
}
Also used : HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse)

Aggregations

HttpResponse (com.google.firebase.crashlytics.internal.network.HttpResponse)12 IOException (java.io.IOException)6 Logger (com.google.firebase.crashlytics.internal.Logger)4 HttpRequest (com.google.firebase.crashlytics.internal.network.HttpRequest)4 JSONObject (org.json.JSONObject)3 HttpGetRequest (com.google.firebase.crashlytics.internal.network.HttpGetRequest)2