Search in sources :

Example 1 with HttpResponse

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

the class DefaultCreateReportSpiCall 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), 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("Create report 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("Create report 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 2 with HttpResponse

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

the class DefaultSettingsSpiCall method invoke.

// com.google.firebase.crashlytics.internal.settings.network.SettingsSpiCall
@Override
public JSONObject invoke(SettingsRequest requestData, boolean dataCollectionToken) {
    if (dataCollectionToken) {
        try {
            Map<String, String> queryParams = getQueryParamsFor(requestData);
            HttpRequest httpRequest = getHttpRequest(queryParams);
            HttpRequest httpRequest2 = applyHeadersTo(httpRequest, requestData);
            Logger logger = this.logger;
            logger.d("Requesting settings from " + getUrl());
            Logger logger2 = this.logger;
            logger2.d("Settings query params were: " + queryParams);
            HttpResponse httpResponse = httpRequest2.execute();
            Logger logger3 = this.logger;
            logger3.d("Settings request ID: " + httpResponse.header(AbstractSpiCall.HEADER_REQUEST_ID));
            JSONObject toReturn = handleResponse(httpResponse);
            return toReturn;
        } catch (IOException e) {
            this.logger.e("Settings request failed.", e);
            return null;
        }
    } else {
        throw new RuntimeException("An invalid data collection token was used.");
    }
}
Also used : HttpRequest(com.google.firebase.crashlytics.internal.network.HttpRequest) JSONObject(org.json.JSONObject) HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse) IOException(java.io.IOException) Logger(com.google.firebase.crashlytics.internal.Logger)

Example 3 with HttpResponse

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

the class DefaultSettingsSpiCall method invoke.

@Override
public JSONObject invoke(SettingsRequest requestData, boolean dataCollectionToken) {
    if (!dataCollectionToken) {
        throw new RuntimeException("An invalid data collection token was used.");
    }
    JSONObject toReturn = null;
    try {
        final Map<String, String> queryParams = getQueryParamsFor(requestData);
        HttpGetRequest httpRequest = createHttpGetRequest(queryParams);
        httpRequest = applyHeadersTo(httpRequest, requestData);
        logger.d("Requesting settings from " + url);
        logger.v("Settings query params were: " + queryParams);
        final HttpResponse httpResponse = httpRequest.execute();
        toReturn = handleResponse(httpResponse);
    } catch (IOException e) {
        logger.e("Settings request failed.", e);
        toReturn = null;
    }
    return toReturn;
}
Also used : JSONObject(org.json.JSONObject) HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse) HttpGetRequest(com.google.firebase.crashlytics.internal.network.HttpGetRequest) IOException(java.io.IOException)

Example 4 with HttpResponse

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

the class DefaultSettingsSpiCallTest method testHandleResponse_requestNotSuccessful.

public void testHandleResponse_requestNotSuccessful() throws IOException {
    final HttpResponse mockHttpResponse = mock(HttpResponse.class);
    when(mockHttpResponse.code()).thenReturn(HttpURLConnection.HTTP_INTERNAL_ERROR);
    assertNull(defaultSettingsSpiCall.handleResponse(mockHttpResponse));
    verify(mockHttpResponse, never()).body();
    verify(mockLogger, times(1)).e(eq("Settings request failed; (status: " + HttpURLConnection.HTTP_INTERNAL_ERROR + ") from " + TEST_URL));
}
Also used : HttpResponse(com.google.firebase.crashlytics.internal.network.HttpResponse)

Example 5 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)

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