com.eg.agent.android.DataSendToRum Maven / Gradle / Ivy
package com.eg.agent.android;
import android.util.Log;
import com.eg.agent.android.instrumentation.TransactionState;
import com.eg.agent.android.trace.Trace;
import com.eg.agent.android.util.Util;
import com.eg.google.gson.Gson;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class DataSendToRum {
static Gson gson = new Gson();
private static String useSsl = AgentConfiguration.useSsl ? "https://" : "http://";
static String url = "" + useSsl + "" + AgentConfiguration.AndroidAppCommonDetails;
private static final AgentConfiguration agentConfiguration = new AgentConfiguration();
private static AndroidAgentImpl androidAgentimpl = new AndroidAgentImpl();
static String AppName = androidAgentimpl.getApplicationInformation().getAppName();
static String dev_info = gson.toJson(androidAgentimpl.getDeviceInformation());
static String app_info = gson.toJson(androidAgentimpl.getApplicationInformation());
static String res_info = gson.toJson(androidAgentimpl.getResourceInforamtion());
static String deviceInformation = "DeviceInformation";
static String applicationInformation = "ApplicationInformation";
static String resourceInformatin = "ResourceInformation";
static String activityInformation = "ActivityInformation";
static String agentInformation = "AgentInformation";
static String appLaunchTime = "AppLaunchTime";
static String appNameParam = "app_name";
static String httpInformation = "HttpInformation";
static String networkInformation = "NetWorkInformation";
static String ActivityName = "ActivityName";
static String threadType = "ThreadType";
static String className = "ClassName";
static String instrumentationType = "InstrumentationType";
static String apiMethodName = "ApiMethodName";
static String executionMethodName = "ExecutionMethodName";
static String executionTime = "ExecutionTime";
static String applicationToken="applicationToken";
public static void SendToCollector(String type, ApplicationStateMonitorAgent applicationStateMonitor) {
System.out.println("Inside Applicate State");
if (android.os.Build.VERSION.SDK_INT > 9) {
Util.addStrictMode();
}
try {
String activity_data = gson.toJson(applicationStateMonitor.asJsonObject());
/*
System.out.println("dev_info "+dev_info);
*/
JSONObject reqJsonParams = new JSONObject();
JSONObject reqJson = new JSONObject();
reqJson.put(appNameParam, AppName);
reqJson.put(deviceInformation, dev_info);
reqJson.put(applicationInformation, app_info);
reqJson.put(resourceInformatin, res_info);
reqJson.put(activityInformation, activity_data);
System.out.println("token "+agentConfiguration.getApplicationToken());
reqJson.put(applicationToken,agentConfiguration.getApplicationToken());
// reqJson.put(deviceInformation, reqJsonParams);
reqJson.put(instrumentationType,"ActivityInfo");
// reqJson.put(apiType, "appstate");
JSONObject mainJson = new JSONObject();
mainJson.put("reqJson",reqJson);
// String activity_info = "{\"" + AppName + "\":{\"DeviceInformation1\":[" + dev_info + "],\"ApplicationInformation1\":[" + app_info + "],\"ResourceInformation\":[" + res_info + "],\"ActivityInformation\":[" + activity_data + "]}}";
// String urlParameters = "AppName=" + AppName + "&DeviceInformation1=" + URLEncoder.encode(activity_info, "UTF-8") + "&ApplicationInformation1=&AgentInformation=&AppLaunchTime=";
// Log.e("json params", mainJson.toString());
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
// Log.e("reqJsonParams", mainJson.toString());
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.write(mainJson.toString().getBytes("UTF-8"));
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
Log.e("ActivityInfo response", response.toString());
in.close();
} catch (Exception e) {
e.printStackTrace();
Log.e("eG send to data to collector", e.getMessage());
}
}
/* public static void sendData(String activity_name, String launch_time, String AppStatus) {
Log.e("ff", "SEEEEE");
if (android.os.Build.VERSION.SDK_INT > 9) {
Util.addStrictMode();
}
String url = "" + useSsl + "" + AgentConfiguration.AndroidAppCommonDetails;
try {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
String urlParameters = "AppName=" + AppName + "&MemoryInformation=&EnvironmentInformation=" + res_info + "&ActivityName=" + activity_name + "&PageResponseTime=" + launch_time + "&AppStatus=" + AppStatus + "";
// Send post request
Log.e("urlParameters", urlParameters);
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
Log.e("response", response.toString());
in.close();
} catch (Exception e) {
Log.e("DDDD", e.getMessage());
}
}*/
public static void sendData(TransactionState transactionState) {
System.out.println("Inside send Data");
if (android.os.Build.VERSION.SDK_INT > 9) {
Util.addStrictMode();
}
try {
// String strurl = "" + useSsl + "" + AgentConfiguration.AndroidAppCommonDetails;
String networkData = gson.toJson(transactionState.asJsonObject());
JSONObject reqJsonParams = new JSONObject();
JSONObject reqJson = new JSONObject();
reqJson.put(appNameParam, AppName);
//reqJson.put(apiDetails, networkData);
reqJson.put(instrumentationType,"HTTP");
reqJson.put(deviceInformation, dev_info);
reqJson.put(applicationInformation, app_info);
reqJson.put(resourceInformatin, res_info);
reqJson.put(httpInformation, networkData);
// reqJson.put(networkInformation, reqJsonParams);
reqJson.put(ActivityName,Trace.getActiviteClassName());
System.out.println("token "+agentConfiguration.getApplicationToken());
reqJson.put(applicationToken,agentConfiguration.getApplicationToken());
JSONObject mainJson=new JSONObject();
mainJson.put("reqJson",reqJson);
String http_data = "{\"" + AppName + "\":{\"DeviceInformation1\":[" + dev_info + "],\"ApplicationInformation1\":[" + app_info + "],\"ResourceInformation\":[" + res_info + "],\"HttpInformation\":[" + networkData + "]}}";
String urlParameters = "AppName=" + AppName + "&NetWorkInformation=" + URLEncoder.encode(http_data, "UTF-8") + "&ActivityName=" + AgentConfiguration.applicationName + "";
Log.e("json Params", mainJson.toString());
/***
*
* API call
*/
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
Log.e("reqJsonParams", mainJson.toString());
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.write(mainJson.toString().getBytes("UTF-8"));
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
Log.e("response", response.toString());
in.close();
} catch (Exception e) {
e.printStackTrace();
Log.e("eG send to data to collector", e.getMessage());
}
}
//API Call
public static void SendData(String string, String method, String category, long excution_time, String ApiType) throws IOException {
try {
Log.e("reqJsonParams enter SendData","SendData ");
if (android.os.Build.VERSION.SDK_INT > 9) {
Util.addStrictMode();
}
Log.e("reqJsonParams enter method","Main "+AppName);
// Log.e("reqJsonParams enter method","Main "+Trace.getActiviteClassName());
String urlParameters = "AppName=" + AppName + "&ThreadType=" + category + "&ActivityName=" + Trace.getActiviteClassName() + "&ClassName="
+ Trace.getActiviteClassName()+"&ApiMethodName=" + method + "&ExecutionMethodName=" + method + "&ExecutionTime=" + excution_time + "";
//+ "&ApiType=" + ApiType +
JSONObject reqJsonParams = new JSONObject();
reqJsonParams.put(appNameParam, AppName);
reqJsonParams.put(threadType, category);
reqJsonParams.put(ActivityName, Trace.getActiviteClassName());
reqJsonParams.put(className, Trace.getActiviteClassName());
reqJsonParams.put(instrumentationType, ApiType);
reqJsonParams.put(apiMethodName, method);
reqJsonParams.put(executionMethodName, method);
reqJsonParams.put(executionTime, excution_time);
reqJsonParams.put(deviceInformation, dev_info);
System.out.println("token "+agentConfiguration.getApplicationToken());
reqJsonParams.put(applicationToken,agentConfiguration.getApplicationToken());
// reqJsonParams.put(apiType, "apiType");
JSONObject mainJson=new JSONObject();
mainJson.put("reqJson",reqJsonParams);
Log.e("reqJsonParams enter method", mainJson.toString());
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
Log.e("reqJsonParams", mainJson.toString());
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.write(mainJson.toString().getBytes("UTF-8"));
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
Log.e("response", response.toString());
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy