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

com.eg.agent.android.instrumentation.retrofit.ClientExtension Maven / Gradle / Ivy

The newest version!
/*
 * Decompiled with CFR 0.137.
 * 
 * Could not load the following classes:
 *  retrofit.client.Client
 *  retrofit.client.Header
 *  retrofit.client.Request
 *  retrofit.client.Response
 *  retrofit.mime.TypedInput
 *  retrofit.mime.TypedOutput
 */
package com.eg.agent.android.instrumentation.retrofit;

import com.eg.agent.android.common.Data;
import com.eg.agent.android.connectivity.Payload;
import com.eg.agent.android.instrumentation.httphelper.TransactionData;
import com.eg.agent.android.instrumentation.httphelper.TransactionUtil;
import com.eg.agent.android.instrumentation.retrofit.ContentBufferingTypedInput;
import com.eg.agent.android.instrumentation.retrofit.RetrofitTransactionStateUtil;
import com.eg.agent.android.logging.EGAgentLog;
import com.eg.agent.android.logging.EGAgentLogManager;
import com.eg.agent.android.measurement.http.HttpTransactionMetrics;
import com.eg.agent.android.EGAgent;
import com.eg.agent.android.Features;
import com.eg.agent.android.MobileAgentUpload;
import com.eg.agent.android.Queue;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import retrofit.client.Client;
import retrofit.client.Header;
import retrofit.client.Request;
import retrofit.client.Response;
import retrofit.mime.TypedInput;
import retrofit.mime.TypedOutput;

public class ClientExtension
implements Client {
	private static final EGAgentLog log = EGAgentLogManager.getAgentLog();
    private Client impl;
    private TransactionData transactionState;
    private Request request;

    public ClientExtension(Client impl) {
        this.impl = impl;
    }

    public Response execute(Request request) throws IOException {
        this.request = request;
        this.getTransactionState();
        request = this.setConnectivityHeaders(request);
        Response response = null;
        try {
            response = this.impl.execute(request);
            response = new Response(response.getUrl(), response.getStatus(), response.getReason(), response.getHeaders(), (TypedInput)new ContentBufferingTypedInput(response.getBody()));
        }
        catch (IOException ex) {
            this.error(ex);
            throw ex;
        }
        this.checkResponse(response);
        return response;
    }

    private Request setConnectivityHeaders(Request request) {
        String crossProcessId = EGAgent.getCrossProcessId();
        ArrayList
headers = new ArrayList
(request.getHeaders()); if (Features.featureEnabled(Features.DistributedTracing) && this.transactionState.getCatPayload() != null) { headers.add(new Header("eg", this.transactionState.getCatPayload().asBase64Json())); } if (crossProcessId != null) { headers.add(new Header("X-EG-ID", crossProcessId)); } return new Request(request.getMethod(), request.getUrl(), headers, request.getBody()); } private void checkResponse(Response response) { log.debug("ClientExtension:checkResponse:this.getTransactionState().isComplete()=>"+this.getTransactionState().isComplete()); if (!this.getTransactionState().isComplete()) { RetrofitTransactionStateUtil.inspectAndInstrumentResponse(this.getTransactionState(), response); } } protected TransactionData getTransactionState() { if (this.transactionState == null) { this.transactionState = new TransactionData(); } RetrofitTransactionStateUtil.inspectAndInstrument(this.transactionState, this.request); return this.transactionState; } protected void error(Exception e) { Data transactionData; TransactionData transactionState = this.getTransactionState(); 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)); } } void setRequest(Request request) { this.request = request; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy