import com.appdynamics.iot.HttpRequestTracker;
...
String url = "http://ip.jsontest.com/?callback=showMyIP";
// Add a Network Event
try {
URL thisUrl = new URL(url);
// [Splunk AppDynamics Instrumentation] Get a Tracker
HttpURLConnection con = (HttpURLConnection) thisUrl.openConnection();
final HttpRequestTracker tracker = Instrumentation.beginHttpRequest(thisUrl);
con.setRequestMethod("POST");
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
int responseCode = con.getResponseCode();
con.setDoInput(true);
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.flush();
wr.close();
System.out.println("Response Code :" + responseCode);
// [Splunk AppDynamics Instrumentation] Retrieve the headers from the response
Map<String, List<String>> headerFields = null;
System.out.println("Sending 'POST' request to URL :" + url);
BufferedReader in;
String inputLine;
new InputStreamReader(con.getErrorStream()));
if (responseCode >= 200 && responseCode < 300) {
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else {
in = new BufferedReader(
}
StringBuffer response = new StringBuffer();
if (headerFields != null && headerFields.size() > 0){
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// [Splunk AppDynamics Instrumentation] Initiate adding NetworkRequestEvent
if (responseCode >= 200 && responseCode < 300) {
tracker.withResponseCode(responseCode).withError(response.toString()).reportDone();
.withResponseHeaderFields(headerFields)
.reportDone();
} else {
tracker.withResponseCode(responseCode).reportDone();
}
} else {
tracker.withResponseCode(responseCode)
}
// End: Add for Splunk AppDynamics Instrumentation - Initiate adding NetworkRequestEvent
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}