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

com.eg.agent.android.instrumentation.eGHttpInstrumentation Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package com.eg.agent.android.instrumentation;


import android.util.Log;

import com.eg.agent.android.common.TransactionData;
import com.eg.agent.android.instrumentation.NetworkInformation.HttpURLConnectionExtension;
import com.eg.agent.android.instrumentation.NetworkInformation.HttpsURLConnectionExtension;
import com.eg.agent.android.instrumentation.NetworkInformation.httpClient.ResponseHandlerImpl;

import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.protocol.HttpContext;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URLConnection;

import javax.net.ssl.HttpsURLConnection;

public final class eGHttpInstrumentation {
    @WrapReturn(className="java/net/URL", methodName="openConnection", methodDesc="()Ljava/net/URLConnection;")
    public static URLConnection openConnection(URLConnection paramURLConnection) {
        if (paramURLConnection instanceof HttpsURLConnection) {
            Log.e("eGAndroidAgent", "HttpsURLConnection");
            try {
                return new HttpsURLConnectionExtension((HttpsURLConnection) paramURLConnection);
            } catch (Exception e) {
                Log.e("eGAndroidAgent", e.getMessage());
            }
        } else {
            if (paramURLConnection instanceof HttpURLConnection) {
                try {
                    Log.e("eGAndroidAgent", "HttpURLConnection");
                    System.out.println("HttpURLConnection");
                    return new HttpURLConnectionExtension((HttpURLConnection) paramURLConnection);
                } catch (Exception e) {
                    Log.e("eGAndroidAgent", e.getMessage());
                }
            }
        }
        return (URLConnection) paramURLConnection;
    }

    public static URLConnection openConnectionWithProxy(URLConnection paramURLConnection) {
        if ((paramURLConnection instanceof HttpsURLConnection)) {
            return new HttpsURLConnectionExtension((HttpsURLConnection) paramURLConnection);
        } else {
            if (paramURLConnection instanceof HttpURLConnection) {
                Log.e("eGAndroidAgent", "HttpURLConnection");
                System.out.println("HttpURLConnection");
                return new HttpURLConnectionExtension((HttpURLConnection) paramURLConnection);
            }
        }
        return (URLConnection) paramURLConnection;
    }

    public static HttpResponse execute(HttpClient httpClient, HttpUriRequest httpUriRequest) throws IOException, ClientProtocolException {

        TransactionState localTransactionState = new TransactionState();
        try {
            HttpUriRequest localhttpUriRequest=TransactionStateUtil.insepectAndHttpClientData(httpUriRequest, localTransactionState);
            return TransactionStateUtil.insepectAndHttpClientData(httpClient.execute(localhttpUriRequest), localTransactionState);
        } catch (IOException paramHttpClient) {
            httpClientError(localTransactionState, paramHttpClient);
            throw paramHttpClient;
        }
    }
    public static HttpResponse execute(HttpClient httpClient, HttpUriRequest httpUriRequest, HttpContext httpContext) throws IOException, ClientProtocolException
    {
        TransactionState localTransactionState = new TransactionState();
       try {
           HttpUriRequest localhttpUriRequest = TransactionStateUtil.insepectAndHttpClientData(httpUriRequest, localTransactionState);
           return TransactionStateUtil.insepectAndHttpClientData(httpClient.execute(localhttpUriRequest, httpContext), localTransactionState);
       }
       catch (IOException paramHttpClient) {
           httpClientError(localTransactionState, paramHttpClient);
           throw paramHttpClient;
       }
    }

    public static HttpResponse execute(HttpClient httpClient, HttpHost httpHost, HttpRequest httpRequest) throws IOException, ClientProtocolException
    {
        TransactionState transactionState=new TransactionState();
        try {
            HttpRequest localhttpRequest = TransactionStateUtil.insepectAndHttpClientData(transactionState, httpHost, httpRequest);
            return TransactionStateUtil.insepectAndHttpClientData(httpClient.execute(httpHost, localhttpRequest), transactionState);
        }
        catch (IOException paramHttpClient) {
            httpClientError(transactionState, paramHttpClient);
            throw paramHttpClient;
        }
    }

    public static HttpResponse execute(HttpClient httpClient, HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext) throws IOException, ClientProtocolException
    {
        TransactionState  transactionState=new TransactionState();
        try{
        HttpRequest localhttpRequest=TransactionStateUtil.insepectAndHttpClientData(transactionState,httpHost,httpRequest);
        return  TransactionStateUtil.insepectAndHttpClientData(httpClient.execute(httpHost, localhttpRequest, httpContext), transactionState);
        }
        catch (IOException paramHttpClient) {
            httpClientError(transactionState, paramHttpClient);
            throw paramHttpClient;
        }
    }

    public static  T execute(HttpClient httpClient, HttpUriRequest httpUriRequest, ResponseHandler responseHandler) throws IOException, ClientProtocolException
    {
        TransactionState transactionState=new TransactionState();
        try{
        return (T)httpClient.execute(TransactionStateUtil.insepectAndHttpClientData(httpUriRequest, transactionState), _(responseHandler, transactionState));
        }
        catch (IOException paramHttpClient) {
            httpClientError(transactionState, paramHttpClient);
            throw paramHttpClient;
        }
    }

    public static  T execute(HttpClient httpClient, HttpUriRequest httpUriRequest, ResponseHandler responseHandler, HttpContext httpContext) throws IOException, ClientProtocolException {

        TransactionState transactionState=new TransactionState();
        try{
        return (T)httpClient.execute(TransactionStateUtil.insepectAndHttpClientData(httpUriRequest, transactionState), _(responseHandler, transactionState), httpContext);
        }
        catch (IOException paramHttpClient) {
            httpClientError(transactionState, paramHttpClient);
            throw paramHttpClient;
        }
    }

    public static  T execute(HttpClient httpClient, HttpHost httpHost, HttpRequest httpRequest, ResponseHandler responseHandler) throws IOException, ClientProtocolException {
        TransactionState transactionState=new TransactionState();
        try
        {
        return (T)httpClient.execute(httpHost, TransactionStateUtil.insepectAndHttpClientData(transactionState,httpHost, httpRequest), _(responseHandler, transactionState));
        }
        catch (IOException paramHttpClient) {
            httpClientError(transactionState, paramHttpClient);
            throw paramHttpClient;
        }
    }

    public static  T execute(HttpClient httpClient, HttpHost httpHost, HttpRequest httpRequest, ResponseHandler responseHandler, HttpContext httpContext) throws IOException, ClientProtocolException {
        TransactionState transactionState=new TransactionState();
        try
        {
            return (T)httpClient.execute(httpHost, TransactionStateUtil.insepectAndHttpClientData(transactionState,httpHost, httpRequest), _(responseHandler, transactionState),httpContext);
        }
        catch (IOException paramHttpClient) {
            httpClientError(transactionState, paramHttpClient);
            throw paramHttpClient;
        }
    }

    private static void httpClientError(TransactionState transactionState, Exception e) {
        Log.e("eG","Error in http"+e.getLocalizedMessage());
        if (!transactionState.isComplete()) {
            TransactionStateUtil.setErrorCodeFromException(transactionState, e);
            TransactionData transactionData = transactionState.end();
            if (transactionData != null) {
                //new HttpTransactionMeasurement(transactionData.getUrl(), transactionData.getHttpMethod(), transactionData.getStatusCode(), transactionData.getErrorCode(), transactionData.getTimestamp(), (double)transactionData.getTime(), transactionData.getBytesSent(), transactionData.getBytesReceived(), transactionData.getAppData());
            }
        }
    }
    private static  ResponseHandler _(ResponseHandler handler, TransactionState transactionState)
    {
        return ResponseHandlerImpl.wrap(handler, transactionState);
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy