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

com.eg.agent.android.common.Data Maven / Gradle / Ivy

The newest version!
package com.eg.agent.android.common;

import java.util.Map;

import com.eg.agent.android.connectivity.Payload;
import com.eg.agent.android.Features;

public class Data
{
    private final long timestamp;
    private final String url;
    private final String httpMethod;

    private final float time;
    private final int statusCode;
    private int errorCode;

    private final long bytesSent;
    private final long bytesReceived;
    private final String appData;
    private String responseBody = null;
    private  String errorMessage;
    private Map params = null;
    private  Payload catPayload=null;
    private  String carrier=null;
    private  String wanType=null;
    public String getResponseBody()
    {
        return this.responseBody;
    }
    public Payload getCatPayload()
    {
        return this.catPayload;
    }
    public Map getParams()
    {
        return this.params;
    }

    public void setParams(Map params)
    {
        this.params = params;
    }
    public void setResponseBody(String responseBody)
    {
        if (Features.featureEnabled(Features.HttpResponseBodyCapture)) {
            if ((responseBody == null) || (responseBody.isEmpty())) {
                this.responseBody = null;
            } else {
                this.responseBody = responseBody;
            }
        }
    }
    public String getErrorMessage()
    {
        return this.errorMessage;
    }
    public boolean isErrorOrFailure()
    {
        return (isRequestError()) || (isRequestFailure());
    }
    public boolean isRequestError()
    {
        return isRequestError(this.statusCode);
    }

    public static boolean isRequestFailure(int errorCode)
    {
        return errorCode != 0;
    }
    public boolean isRequestFailure()
    {
        return isRequestFailure(this.errorCode);
    }
    public static boolean isRequestError(int statusCode)
    {
        return statusCode >= 400L;
    }
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    public Data(String url, String httpMethod, float time, int statusCode, int errorCode, long bytesSent, long bytesReceived, String appData)
    {
        int endPos = url.indexOf(63);
        if(endPos < 0)
        {
            endPos = url.indexOf(59);
            if(endPos < 0)
            {
                endPos = url.length();
            }
        }
        String trimmedUrl = url.substring(0, endPos);
        this.url = trimmedUrl;
        this.httpMethod = httpMethod;
        this.time = time;
        this.statusCode = statusCode;
        this.errorCode = errorCode;
        this.bytesSent = bytesSent;
        this.bytesReceived = bytesReceived;
        this.appData = appData;
        this.timestamp = System.currentTimeMillis();
    }
    public Data(String url, String httpMethod, String carrier, float time, int statusCode, int errorCode, long bytesSent, long bytesReceived, String appData, String wanType, Payload catPayload)
    {
        int endPos = url.indexOf('?');
        if (endPos < 0)
        {
            endPos = url.indexOf(';');
            if (endPos < 0) {
                endPos = url.length();
            }
        }
        String trimmedUrl = url.substring(0, endPos);

        this.url = trimmedUrl;
        this.httpMethod = httpMethod;
        this.carrier = carrier;
        this.time = time;
        this.statusCode = statusCode;
        this.errorCode = errorCode;
        this.bytesSent = bytesSent;
        this.bytesReceived = bytesReceived;
        this.appData = appData;
        this.wanType = wanType;
        this.timestamp = System.currentTimeMillis();
        this.responseBody = null;
        this.params = null;
        this.catPayload = catPayload;
    }
    public String getUrl()
    {
        return this.url;
    }
    public String getHttpMethod()
    {
        return this.httpMethod;
    }

    public int getStatusCode()
    {
        return this.statusCode;
    }
    public int getErrorCode() {
        return this.errorCode;
    }

    public void setErrorCode(int errorCode)
    {
        this.errorCode=errorCode;
    }
    public long getBytesSent()
    {
        return this.bytesSent;
    }
    public long getBytesReceived()
    {
        return this.bytesReceived;
    }
    public String getAppData()
    {
        return this.appData;
    }

    public float getTime()
    {
        return this.time;
    }

    public String toString()
    {
        return("timestamp=" + this.timestamp + ", " +
                "url=\'" + this.url + '\'' + ", " +
                "httpMethod=\'" + this.httpMethod + '\'' + "," +
                " time=" + this.time + ", " +
                "statusCode=" + this.statusCode + ", " +
                "errorCode=" + this.errorCode + ", " +
                "error Message=" + this.errorMessage + ", " +
                "bytesSent=" + this.bytesSent + ", " +
                "bytesReceived=" + this.bytesReceived +  '}');

    }
    public long getTimestamp() {
        return this.timestamp;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy