All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eg.agent.android.instrumentation.okhttp2.CallbackExtension Maven / Gradle / Ivy

The newest version!
/*
 * Decompiled with CFR 0.137.
 * 
 * Could not load the following classes:
 *  com.squareup.okhttp.Callback
 *  com.squareup.okhttp.Request
 *  com.squareup.okhttp.Response
 */
package com.eg.agent.android.instrumentation.okhttp2;

import com.eg.agent.android.common.Data;
import com.eg.agent.android.instrumentation.httphelper.TransactionData;
import com.eg.agent.android.instrumentation.httphelper.TransactionUtil;
import com.eg.agent.android.instrumentation.okhttp2.OkHttp2TransactionStateUtil;

import com.eg.agent.android.measurement.http.HttpTransactionMetrics;
import com.eg.agent.android.MobileAgentUpload;
import com.eg.agent.android.Queue;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import java.io.IOException;

public class CallbackExtension
implements Callback {

    private TransactionData transactionState;
    private Callback impl;

    public CallbackExtension(Callback impl, TransactionData transactionState) {
        this.impl = impl;
        this.transactionState = transactionState;
    }

    public void onFailure(Request request, IOException e) {
        this.error(e);
        this.impl.onFailure(request, e);
    }

    public void onResponse(Response response) throws IOException {
        response = this.checkResponse(response);
        this.impl.onResponse(response);
    }

    private Response checkResponse(Response response) {
        if (!this.getTransactionData().isComplete()) {
//            log.verbose("CallbackExtension.checkResponse() - transaction is not complete.  Inspecting and instrumenting response.");
            response = OkHttp2TransactionStateUtil.inspectAndInstrumentResponse(this.getTransactionData(), response);
        }
        return response;
    }

    protected TransactionData getTransactionData() {
        return this.transactionState;
    }

    protected void error(Exception e) {
        Data transactionData;
        TransactionData transactionState = this.getTransactionData();
        TransactionUtil.setErrorCodeFromException(transactionState, e);
        if (!transactionState.isComplete() && (transactionData = transactionState.end()) != null) {
            transactionData.setResponseBody(e.toString());
            HttpTransactionMetrics metrics=  new HttpTransactionMetrics(transactionData);
           	metrics.setMainJson(MobileAgentUpload.getJSONObjet(transactionState));
            Queue.queue(metrics);
//            Queue.queue(new HttpTransactionMetrics(transactionData));
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy