com.newrelic.agent.transport.DataSenderImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.newrelic.agent.transport.DataSenderImpl.java

Source

/*   1:    */ package com.newrelic.agent.transport;

/*   2:    */
/*   3:    */ /*  49:    */ import java.io.BufferedReader;
/*  50:    */ import java.io.ByteArrayOutputStream;
/*  51:    */ import java.io.IOException;
/*  52:    */ import java.io.InputStream;
/*  53:    */ import java.io.InputStreamReader;
/*  54:    */ import java.io.OutputStream;
/*  55:    */ import java.io.OutputStreamWriter;
/*  56:    */ import java.io.Writer;
/*  57:    */ import java.lang.reflect.Constructor;
/*  58:    */ import java.net.MalformedURLException;
/*  59:    */ import java.net.SocketException;
/*  60:    */ import java.net.URISyntaxException;
/*  61:    */ import java.net.URL;
/*  62:    */ import java.rmi.UnexpectedException;
/*  63:    */ import java.security.KeyStore;
/*  64:    */ import java.security.KeyStoreException;
/*  65:    */ import java.security.NoSuchAlgorithmException;
/*  67:    */ import java.security.cert.CertificateException;
/*  68:    */ import java.text.MessageFormat;
/*  69:    */ import java.util.Arrays;
/*  70:    */ import java.util.Collection;
/*  71:    */ import java.util.Collections;
/*  72:    */ import java.util.List;
/*  73:    */ import java.util.Map;
/*  74:    */ import java.util.logging.Level;
/*  75:    */ import java.util.zip.Deflater;
/*  76:    */ import java.util.zip.DeflaterOutputStream;
/*  77:    */ import java.util.zip.GZIPInputStream;

/*  78:    */ import javax.net.ssl.SSLContext;

import com.newrelic.agent.Agent;
/*   4:    */ import com.newrelic.agent.ForceDisconnectException;
/*   5:    */ import com.newrelic.agent.MetricData;
/*   6:    */ import com.newrelic.agent.MetricDataException;
/*   7:    */ import com.newrelic.agent.config.AgentConfig;
/*   9:    */ import com.newrelic.agent.deps.org.apache.http.Header;
/*  10:    */ import com.newrelic.agent.deps.org.apache.http.HttpEntity;
/*  11:    */ import com.newrelic.agent.deps.org.apache.http.HttpHost;
/*  12:    */ import com.newrelic.agent.deps.org.apache.http.auth.AuthScope;
/*  13:    */ import com.newrelic.agent.deps.org.apache.http.auth.Credentials;
/*  14:    */ import com.newrelic.agent.deps.org.apache.http.auth.UsernamePasswordCredentials;
/*  15:    */ import com.newrelic.agent.deps.org.apache.http.client.CredentialsProvider;
/*  16:    */ import com.newrelic.agent.deps.org.apache.http.client.config.RequestConfig;
/*  18:    */ import com.newrelic.agent.deps.org.apache.http.client.methods.CloseableHttpResponse;
/*  19:    */ import com.newrelic.agent.deps.org.apache.http.client.methods.HttpUriRequest;
/*  20:    */ import com.newrelic.agent.deps.org.apache.http.client.methods.RequestBuilder;
/*  21:    */ import com.newrelic.agent.deps.org.apache.http.client.protocol.HttpClientContext;
/*  22:    */ import com.newrelic.agent.deps.org.apache.http.config.SocketConfig;
/*  24:    */ import com.newrelic.agent.deps.org.apache.http.conn.ssl.SSLConnectionSocketFactory;
/*  26:    */ import com.newrelic.agent.deps.org.apache.http.conn.ssl.StrictHostnameVerifier;
/*  27:    */ import com.newrelic.agent.deps.org.apache.http.entity.ByteArrayEntity;
/*  28:    */ import com.newrelic.agent.deps.org.apache.http.impl.client.BasicCredentialsProvider;
/*  29:    */ import com.newrelic.agent.deps.org.apache.http.impl.client.CloseableHttpClient;
/*  30:    */ import com.newrelic.agent.deps.org.apache.http.impl.client.HttpClientBuilder;
/*  31:    */ import com.newrelic.agent.deps.org.apache.http.message.BasicHeader;
/*  32:    */ import com.newrelic.agent.deps.org.apache.http.protocol.HttpContext;
import com.newrelic.agent.deps.org.apache.http.ssl.SSLContextBuilder;
/*  33:    */ import com.newrelic.agent.deps.org.json.simple.JSONArray;
/*  34:    */ import com.newrelic.agent.deps.org.json.simple.JSONStreamAware;
/*  35:    */ import com.newrelic.agent.deps.org.json.simple.JSONValue;
/*  36:    */ import com.newrelic.agent.deps.org.json.simple.parser.JSONParser;
/*  37:    */ import com.newrelic.agent.errors.TracedError;
/*  38:    */ import com.newrelic.agent.logging.ApacheCommonsAdaptingLogFactory;
/*  40:    */ import com.newrelic.agent.profile.IProfile;
/*  41:    */ import com.newrelic.agent.service.ServiceFactory;
/*  42:    */ import com.newrelic.agent.service.analytics.CustomInsightsEvent;
/*  43:    */ import com.newrelic.agent.service.analytics.TransactionEvent;
/*  44:    */ import com.newrelic.agent.service.module.Jar;
/*  45:    */ import com.newrelic.agent.sql.SqlTrace;
/*  46:    */ import com.newrelic.agent.trace.TransactionTrace;
/*  47:    */ import com.newrelic.agent.util.RubyConversion;
/*  48:    */ import com.newrelic.agent.utilization.UtilizationData;

/*  25:    */
/*   8:    */
/*  17:    */
/*  23:    */
/*  39:    */
/*  66:    */
/*  79:    */
/*  80:    */ public class DataSenderImpl/*  81:    */ implements DataSender
/*  82:    */ {
    /*  83:    */ private static final String MODULE_TYPE = "Jars";
    /*  84:    */ private static final int PROTOCOL_VERSION = 14;
    /*  85:    */ private static final int DEFAULT_REQUEST_TIMEOUT_IN_SECONDS = 120;
    /*  86:    */ private static final String BEFORE_LICENSE_KEY_URI_PATTERN = "/agent_listener/invoke_raw_method?method={0}";
    /*  87:    */ private static final String AFTER_LICENSE_KEY_URI_PATTERN = "&marshal_format=json&protocol_version=14";
    /*  88:    */ private static final String LICENSE_KEY_URI_PATTERN = "&license_key={0}";
    /*  89:    */ private static final String RUN_ID_PATTERN = "&run_id={1}";
    /*  90:    */ private static final String CONNECT_METHOD = "connect";
    /*  91:    */ private static final String METRIC_DATA_METHOD = "metric_data";
    /*  92:    */ private static final String GET_AGENT_COMMANDS_METHOD = "get_agent_commands";
    /*  93:    */ private static final String AGENT_COMMAND_RESULTS_METHOD = "agent_command_results";
    /*  94:    */ private static final String GET_REDIRECT_HOST_METHOD = "get_redirect_host";
    /*  95:    */ private static final String ERROR_DATA_METHOD = "error_data";
    /*  96:    */ private static final String PROFILE_DATA_METHOD = "profile_data";
    /*  97:    */ private static final String QUEUE_PING_COMMAND_METHOD = "queue_ping_command";
    /*  98:    */ private static final String ANALYTIC_DATA_METHOD = "analytic_event_data";
    /*  99:    */ private static final String CUSTOM_ANALYTIC_DATA_METHOD = "custom_event_data";
    /* 100:    */ private static final String UPDATE_LOADED_MODULES_METHOD = "update_loaded_modules";
    /* 101:    */ private static final String SHUTDOWN_METHOD = "shutdown";
    /* 102:    */ private static final String SQL_TRACE_DATA_METHOD = "sql_trace_data";
    /* 103:    */ private static final String TRANSACTION_SAMPLE_DATA_METHOD = "transaction_sample_data";
    /* 104:110 */ private static final String USER_AGENT_HEADER_VALUE = null;
    /* 105:    */ private static final String GZIP = "gzip";
    /* 106:    */ private static final String DEFLATE_ENCODING = "deflate";
    /* 107:    */ private static final String IDENTITY_ENCODING = "identity";
    /* 108:    */ private static final String RESPONSE_MAP_EXCEPTION_KEY = "exception";
    /* 109:    */ private static final String EXCEPTION_MAP_MESSAGE_KEY = "message";
    /* 110:    */ private static final String EXCEPTION_MAP_ERROR_TYPE_KEY = "error_type";
    /* 111:    */ private static final String EXCEPTION_MAP_RETURN_VALUE_KEY = "return_value";
    /* 112:    */ private static final String AGENT_RUN_ID_KEY = "agent_run_id";
    /* 113:    */ private static final String SSL_KEY = "ssl";
    /* 114:120 */ private static final Object NO_AGENT_RUN_ID = null;
    /* 115:    */ private static final String NULL_RESPONSE = "null";
    /* 116:    */ private static final String TIMEOUT_PROPERTY = "timeout";
    /* 117:    */ private static final int COMPRESSION_LEVEL = -1;
    /* 118:    */ private static final String GET_XRAY_PARMS_METHOD = "get_xray_metadata";
    /* 119:    */ private static final String UTILIZATION_DATA_METHOD = "utilization_data";
    /* 120:    */ private volatile String host;
    /* 121:    */ private final int port;
    /* 122:    */ private volatile String protocol;
    /* 123:    */ private final HttpHost proxy;
    /* 124:    */ private final Credentials proxyCredentials;
    /* 125:    */ private final int defaultTimeoutInMillis;
    /* 126:    */ private volatile boolean auditMode;
    /* 127:133 */ private volatile Object agentRunId = NO_AGENT_RUN_ID;
    /* 128:    */ private final String agentRunIdUriPattern;
    /* 129:    */ private final String noAgentRunIdUriPattern;
    /* 130:    */ private final boolean usePrivateSSL;
    /* 131:    */ private final boolean useSSL;
    /* 132:    */ private final SSLContext sslContext;

    /* 133:    */
    /* 134:    */ private static String initUserHeaderValue()
    /* 135:    */ {
        /* 136:141 */ String arch = "unknown";
        /* 137:142 */ String javaVersion = "unknown";
        /* 138:    */ try
        /* 139:    */ {
            /* 140:144 */ arch = System.getProperty("os.arch");
            /* 141:145 */ javaVersion = System.getProperty("java.version");
            /* 142:    */ }
        /* 143:    */ catch (Exception e) {
        }
        /* 144:149 */ return MessageFormat.format("NewRelic-JavaAgent/{0} (java {1} {2})",
                new Object[] { Agent.getVersion(), javaVersion, arch });
        /* 145:    */ }

    /* 146:    */
    /* 147:    */ public DataSenderImpl(AgentConfig config)
    /* 148:    */ {
        /* 149:154 */ System.setProperty("com.newrelic.agent.deps.org.apache.commons.logging.LogFactory",
                ApacheCommonsAdaptingLogFactory.class.getName());
        /* 150:    */
        /* 151:156 */ this.auditMode = config.isAuditMode();
        /* 152:157 */ Agent.LOG.info(MessageFormat.format("Setting audit_mode to {0}",
                new Object[] { Boolean.valueOf(this.auditMode) }));
        /* 153:158 */ this.host = config.getHost();
        /* 154:159 */ this.port = config.getPort();
        /* 155:160 */ this.useSSL = config.isSSL();
        /* 156:161 */ this.protocol = (this.useSSL ? "https" : "http");
        /* 157:162 */ String msg = MessageFormat.format("Setting protocol to \"{0}\"",
                new Object[] { this.protocol });
        /* 158:163 */ Agent.LOG.info(msg);
        /* 159:164 */ String proxyHost = config.getProxyHost();
        /* 160:165 */ Integer proxyPort = config.getProxyPort();
        /* 161:166 */ this.usePrivateSSL = config.isUsePrivateSSL();
        /* 162:167 */ this.sslContext = createSSLContext();
        /* 163:168 */ if ((proxyHost != null) && (proxyPort != null))
        /* 164:    */ {
            /* 165:169 */ msg = MessageFormat.format("Using proxy host {0}:{1}",
                    new Object[] { proxyHost, Integer.toString(proxyPort.intValue()) });
            /* 166:170 */ Agent.LOG.fine(msg);
            /* 167:171 */ this.proxy = new HttpHost(proxyHost, proxyPort.intValue());
            /* 168:    */
            /* 169:173 */ this.proxyCredentials = getProxyCredentials(proxyHost, proxyPort, config.getProxyUser(),
                    config.getProxyPassword());
            /* 170:    */ }
        /* 171:    */ else
        /* 172:    */ {
            /* 173:176 */ this.proxy = null;
            /* 174:177 */ this.proxyCredentials = null;
            /* 175:    */ }
        /* 176:179 */ this.defaultTimeoutInMillis = (((Integer) config.getProperty("timeout", Integer.valueOf(120)))
                .intValue() * 1000);
        /* 177:180 */ String licenseKeyUri = MessageFormat.format("&license_key={0}",
                new Object[] { config.getLicenseKey() });
        /* 178:181 */ this.noAgentRunIdUriPattern = ("/agent_listener/invoke_raw_method?method={0}" + licenseKeyUri
                + "&marshal_format=json&protocol_version=14");
        /* 179:182 */ this.agentRunIdUriPattern = (this.noAgentRunIdUriPattern + "&run_id={1}");
        /* 180:    */ }

    /* 181:    */
    /* 182:    */ public static KeyStore getKeyStore()
            /* 183:    */ throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException
    /* 184:    */ {
        /* 185:187 */ KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
        /* 186:    */
        /* 187:189 */ InputStream in = DataSenderImpl.class.getResourceAsStream("/nrcerts");
        /* 188:190 */ if (null == in) {
            /* 189:191 */ Agent.LOG.fine("Unable to find NR trust store");
            /* 190:    */ } else {
            /* 191:    */ try
            /* 192:    */ {
                /* 193:194 */ keystore.load(in, null);
                /* 194:    */ }
            /* 195:    */ finally
            /* 196:    */ {
                /* 197:196 */ in.close();
                /* 198:    */ }
            /* 199:    */ }
        /* 200:200 */ Agent.LOG.finer("SSL Keystore Provider: " + keystore.getProvider().getName());
        /* 201:    */
        /* 202:202 */ return keystore;
        /* 203:    */ }

    /* 204:    */
    /* 205:    */ private SSLContext createSSLContext()
    /* 206:    */ {
        /* 207:206 */ SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        /* 208:    */ try
        /* 209:    */ {
            /* 210:208 */ if ((this.usePrivateSSL) && (this.useSSL)) {
                /* 211:209 */ sslContextBuilder.loadTrustMaterial(getKeyStore(), null);
                /* 212:    */ }
            /* 213:212 */ return sslContextBuilder.build();
            /* 214:    */ }
        /* 215:    */ catch (Exception e) {
        }
        /* 216:214 */ return null;
        /* 217:    */ }

    /* 218:    */
    /* 219:    */ private Credentials getProxyCredentials(String proxyHost, Integer proxyPort, String proxyUser,
            String proxyPass)
    /* 220:    */ {
        /* 221:220 */ if ((proxyUser != null) && (proxyPass != null))
        /* 222:    */ {
            /* 223:221 */ Agent.LOG.info(
                    MessageFormat.format("Setting Proxy Authenticator for user '{0}'", new Object[] { proxyUser }));
            /* 224:222 */ return new UsernamePasswordCredentials(proxyUser, proxyPass);
            /* 225:    */ }
        /* 226:224 */ return null;
        /* 227:    */ }

    /* 228:    */
    /* 229:    */ private void checkAuditMode()
    /* 230:    */ {
        /* 231:228 */ boolean auditMode2 = ServiceFactory.getConfigService().getLocalAgentConfig().isAuditMode();
        /* 232:229 */ if (this.auditMode != auditMode2)
        /* 233:    */ {
            /* 234:230 */ this.auditMode = auditMode2;
            /* 235:231 */ Agent.LOG.info(MessageFormat.format("Setting audit_mode to {0}",
                    new Object[] { Boolean.valueOf(this.auditMode) }));
            /* 236:    */ }
        /* 237:    */ }

    /* 238:    */
    /* 239:    */ private void setAgentRunId(Object runId)
    /* 240:    */ {
        /* 241:236 */ this.agentRunId = runId;
        /* 242:237 */ if (runId != NO_AGENT_RUN_ID) {
            /* 243:238 */ Agent.LOG.info("Agent run id: " + runId);
            /* 244:    */ }
        /* 245:    */ }

    /* 246:    */
    /* 247:    */ public Map<String, Object> connect(Map<String, Object> startupOptions)
            /* 248:    */ throws Exception
    /* 249:    */ {
        /* 250:244 */ String redirectHost = getRedirectHost();
        /* 251:245 */ if (redirectHost != null)
        /* 252:    */ {
            /* 253:246 */ this.host = redirectHost;
            /* 254:247 */ String msg = MessageFormat.format("Collector redirection to {0}:{1}",
                    new Object[] { this.host, Integer.toString(this.port) });
            /* 255:248 */ Agent.LOG.info(msg);
            /* 256:    */ }
        /* 257:250 */ return doConnect(startupOptions);
        /* 258:    */ }

    /* 259:    */
    /* 260:    */ private String getRedirectHost()/* 261:    */ throws Exception
    /* 262:    */ {
        /* 263:254 */ Object response = invokeNoRunId("get_redirect_host", "deflate", new InitialSizedJsonArray(0));
        /* 264:255 */ return response == null ? null : response.toString();
        /* 265:    */ }

    /* 266:    */
    /* 267:    */ private Map<String, Object> doConnect(Map<String, Object> startupOptions)
            /* 268:    */ throws Exception
    /* 269:    */ {
        /* 270:260 */ InitialSizedJsonArray params = new InitialSizedJsonArray(1);
        /* 271:261 */ params.add(startupOptions);
        /* 272:262 */ Object response = invokeNoRunId("connect", "deflate", params);
        /* 273:263 */ if (!(response instanceof Map))
        /* 274:    */ {
            /* 275:264 */ String msg = MessageFormat.format("Expected a map of connection data, got {0}",
                    new Object[] { response });
            /* 276:265 */ throw new UnexpectedException(msg);
            /* 277:    */ }
        /* 278:267 */ Map<String, Object> data = (Map) response;
        /* 279:268 */ if (data.containsKey("agent_run_id"))
        /* 280:    */ {
            /* 281:269 */ Object runId = data.get("agent_run_id");
            /* 282:270 */ setAgentRunId(runId);
            /* 283:    */ }
        /* 284:    */ else
        /* 285:    */ {
            /* 286:272 */ String msg = MessageFormat.format("Missing {0} connection parameter",
                    new Object[] { "agent_run_id" });
            /* 287:273 */ throw new UnexpectedException(msg);
            /* 288:    */ }
        /* 289:275 */ Object ssl = data.get("ssl");
        /* 290:276 */ if (Boolean.TRUE.equals(ssl))
        /* 291:    */ {
            /* 292:277 */ Agent.LOG.info("Setting protocol to \"https\"");
            /* 293:278 */ this.protocol = "https";
            /* 294:    */ }
        /* 295:280 */ return data;
        /* 296:    */ }

    /* 297:    */
    /* 298:    */ public List<List<?>> getAgentCommands()/* 299:    */ throws Exception
    /* 300:    */ {
        /* 301:286 */ checkAuditMode();
        /* 302:287 */ Object runId = this.agentRunId;
        /* 303:288 */ if (runId == NO_AGENT_RUN_ID) {
            /* 304:289 */ return Collections.emptyList();
            /* 305:    */ }
        /* 306:291 */ InitialSizedJsonArray params = new InitialSizedJsonArray(1);
        /* 307:292 */ params.add(runId);
        /* 308:    */
        /* 309:294 */ Object response = invokeRunId("get_agent_commands", "deflate", runId, params);
        /* 310:295 */ if ((response == null) || ("null".equals(response))) {
            /* 311:296 */ return Collections.emptyList();
            /* 312:    */ }
        /* 313:    */ try
        /* 314:    */ {
            /* 315:299 */ return (List) response;
            /* 316:    */ }
        /* 317:    */ catch (ClassCastException e)
        /* 318:    */ {
            /* 319:301 */ String msg = MessageFormat
                    .format("Invalid response from New Relic when getting agent commands: {0}", new Object[] { e });
            /* 320:302 */ Agent.LOG.warning(msg);
            /* 321:303 */ throw e;
            /* 322:    */ }
        /* 323:    */ }

    /* 324:    */
    /* 325:    */ public List<?> getXRayParameters(Collection<Long> ids)/* 326:    */ throws Exception
    /* 327:    */ {
        /* 328:310 */ if (ids.size() > 0)
        /* 329:    */ {
            /* 330:311 */ checkAuditMode();
            /* 331:312 */ Object runId = this.agentRunId;
            /* 332:313 */ if (runId == NO_AGENT_RUN_ID) {
                /* 333:314 */ return Collections.emptyList();
                /* 334:    */ }
            /* 335:316 */ JSONArray params = new JSONArray();
            /* 336:317 */ params.add(runId);
            /* 337:319 */ for (Long s : ids) {
                /* 338:320 */ params.add(s);
                /* 339:    */ }
            /* 340:322 */ Object response = invokeRunId("get_xray_metadata", "deflate", runId, params);
            /* 341:323 */ if ((response == null) || ("null".equals(response))) {
                /* 342:324 */ return Collections.emptyList();
                /* 343:    */ }
            /* 344:    */ try
            /* 345:    */ {
                /* 346:327 */ return (List) response;
                /* 347:    */ }
            /* 348:    */ catch (ClassCastException e)
            /* 349:    */ {
                /* 350:329 */ String msg = MessageFormat.format(
                        "Invalid response from New Relic when getting agent X Ray parameters: {0}",
                        new Object[] { e });
                /* 351:    */
                /* 352:331 */ Agent.LOG.warning(msg);
                /* 353:332 */ throw e;
                /* 354:    */ }
            /* 355:    */ }
        /* 356:335 */ Agent.LOG.info("Attempted to fetch X-Ray Session metadata with no session IDs");
        /* 357:    */
        /* 358:337 */ return Collections.emptyList();
        /* 359:    */ }

    /* 360:    */
    /* 361:    */ public void queuePingCommand()/* 362:    */ throws Exception
    /* 363:    */ {
        /* 364:342 */ Object runId = this.agentRunId;
        /* 365:343 */ if (runId == NO_AGENT_RUN_ID) {
            /* 366:344 */ return;
            /* 367:    */ }
        /* 368:346 */ InitialSizedJsonArray params = new InitialSizedJsonArray(1);
        /* 369:347 */ params.add(runId);
        /* 370:348 */ invokeRunId("queue_ping_command", "deflate", runId, params);
        /* 371:    */ }

    /* 372:    */
    /* 373:    */ public void sendCommandResults(Map<Long, Object> commandResults)/* 374:    */ throws Exception
    /* 375:    */ {
        /* 376:353 */ Object runId = this.agentRunId;
        /* 377:354 */ if ((runId == NO_AGENT_RUN_ID) || (commandResults.isEmpty())) {
            /* 378:355 */ return;
            /* 379:    */ }
        /* 380:357 */ InitialSizedJsonArray params = new InitialSizedJsonArray(2);
        /* 381:358 */ params.add(runId);
        /* 382:359 */ params.add(commandResults);
        /* 383:360 */ invokeRunId("agent_command_results", "deflate", runId, params);
        /* 384:    */ }

    /* 385:    */
    /* 386:    */ public void sendErrorData(List<TracedError> errors)/* 387:    */ throws Exception
    /* 388:    */ {
        /* 389:365 */ Object runId = this.agentRunId;
        /* 390:366 */ if ((runId == NO_AGENT_RUN_ID) || (errors.isEmpty())) {
            /* 391:367 */ return;
            /* 392:    */ }
        /* 393:369 */ InitialSizedJsonArray params = new InitialSizedJsonArray(2);
        /* 394:370 */ params.add(runId);
        /* 395:371 */ params.add(errors);
        /* 396:372 */ invokeRunId("error_data", "identity", runId, params);
        /* 397:    */ }

    /* 398:    */
    /* 399:    */ public void sendUtilizationData(UtilizationData data)/* 400:    */ throws Exception
    /* 401:    */ {
        /* 402:377 */ Object runId = this.agentRunId;
        /* 403:378 */ if ((runId == NO_AGENT_RUN_ID) || (data == null)) {
            /* 404:379 */ return;
            /* 405:    */ }
        /* 406:382 */ invokeRunId("utilization_data", "identity", runId, data);
        /* 407:    */ }

    /* 408:    */
    /* 409:    */ public void sendAnalyticsEvents(Collection<TransactionEvent> events)/* 410:    */ throws Exception
    /* 411:    */ {
        /* 412:387 */ Object runId = this.agentRunId;
        /* 413:388 */ if ((runId == NO_AGENT_RUN_ID) || (events.isEmpty())) {
            /* 414:389 */ return;
            /* 415:    */ }
        /* 416:391 */ InitialSizedJsonArray params = new InitialSizedJsonArray(2);
        /* 417:392 */ params.add(runId);
        /* 418:393 */ params.add(events);
        /* 419:394 */ invokeRunId("analytic_event_data", "deflate", runId, params);
        /* 420:    */ }

    /* 421:    */
    /* 422:    */ public void sendCustomAnalyticsEvents(Collection<CustomInsightsEvent> events)
            /* 423:    */ throws Exception
    /* 424:    */ {
        /* 425:399 */ Object runId = this.agentRunId;
        /* 426:400 */ if ((runId == NO_AGENT_RUN_ID) || (events.isEmpty())) {
            /* 427:401 */ return;
            /* 428:    */ }
        /* 429:403 */ InitialSizedJsonArray params = new InitialSizedJsonArray(2);
        /* 430:404 */ params.add(runId);
        /* 431:405 */ params.add(events);
        /* 432:406 */ invokeRunId("custom_event_data", "deflate", runId, params);
        /* 433:    */ }

    /* 434:    */
    /* 435:    */ public List<List<?>> sendMetricData(long beginTimeMillis, long endTimeMillis,
            List<MetricData> metricData)/* 436:    */ throws Exception
    /* 437:    */ {
        /* 438:413 */ Object runId = this.agentRunId;
        /* 439:414 */ if ((runId == NO_AGENT_RUN_ID) || (metricData.isEmpty())) {
            /* 440:415 */ return Collections.emptyList();
            /* 441:    */ }
        /* 442:417 */ InitialSizedJsonArray params = new InitialSizedJsonArray(4);
        /* 443:418 */ params.add(runId);
        /* 444:419 */ params.add(Long.valueOf(beginTimeMillis / 1000L));
        /* 445:420 */ params.add(Long.valueOf(endTimeMillis / 1000L));
        /* 446:421 */ params.add(metricData);
        /* 447:422 */ Object response = invokeRunId("metric_data", "deflate", runId, params);
        /* 448:423 */ if ((response == null) || ("null".equals(response))) {
            /* 449:424 */ throw new MetricDataException("Invalid null response sending metric data");
            /* 450:    */ }
        /* 451:    */ try
        /* 452:    */ {
            /* 453:427 */ return (List) response;
            /* 454:    */ }
        /* 455:    */ catch (ClassCastException e)
        /* 456:    */ {
            /* 457:429 */ String msg = MessageFormat
                    .format("Invalid response from New Relic when sending metric data: {0}", new Object[] { e });
            /* 458:430 */ Agent.LOG.warning(msg);
            /* 459:431 */ throw e;
            /* 460:    */ }
        /* 461:    */ }

    /* 462:    */
    /* 463:    */ public List<Long> sendProfileData(List<IProfile> profiles)/* 464:    */ throws Exception
    /* 465:    */ {
        /* 466:438 */ Object runId = this.agentRunId;
        /* 467:439 */ if ((runId == NO_AGENT_RUN_ID) || (profiles.isEmpty())) {
            /* 468:440 */ return Collections.emptyList();
            /* 469:    */ }
        /* 470:442 */ InitialSizedJsonArray params = new InitialSizedJsonArray(2);
        /* 471:443 */ params.add(runId);
        /* 472:444 */ params.add(profiles);
        /* 473:445 */ Object response = invokeRunId("profile_data", "identity", runId, params);
        /* 474:446 */ if ((response == null) || ("null".equals(response))) {
            /* 475:447 */ return Collections.emptyList();
            /* 476:    */ }
        /* 477:    */ try
        /* 478:    */ {
            /* 479:450 */ return (List) response;
            /* 480:    */ }
        /* 481:    */ catch (ClassCastException e)
        /* 482:    */ {
            /* 483:452 */ String msg = MessageFormat.format("Invalid response from New Relic sending profiles: {0}",
                    new Object[] { e });
            /* 484:453 */ Agent.LOG.warning(msg);
            /* 485:454 */ throw e;
            /* 486:    */ }
        /* 487:    */ }

    /* 488:    */
    /* 489:    */ public void sendModules(List<Jar> pJars)/* 490:    */ throws Exception
    /* 491:    */ {
        /* 492:465 */ Object runId = this.agentRunId;
        /* 493:466 */ if ((runId == NO_AGENT_RUN_ID) || (pJars == null) || (pJars.isEmpty())) {
            /* 494:467 */ return;
            /* 495:    */ }
        /* 496:469 */ InitialSizedJsonArray params = new InitialSizedJsonArray(2);
        /* 497:    */
        /* 498:    */
        /* 499:472 */ params.add("Jars");
        /* 500:473 */ params.add(pJars);
        /* 501:    */
        /* 502:475 */ Object response = invokeRunId("update_loaded_modules", "identity", runId, params);
        /* 503:476 */ if ((response == null) || ("null".equals(response))) {
            /* 504:477 */ return;
            /* 505:    */ }
        /* 506:479 */ String msg = MessageFormat.format(
                "Invalid response from New Relic when sending modules. Response: {0}", new Object[] { response });
        /* 507:    */
        /* 508:481 */ Agent.LOG.warning(msg);
        /* 509:    */ }

    /* 510:    */
    /* 511:    */ public void sendSqlTraceData(List<SqlTrace> sqlTraces)/* 512:    */ throws Exception
    /* 513:    */ {
        /* 514:487 */ Object runId = this.agentRunId;
        /* 515:488 */ if ((runId == NO_AGENT_RUN_ID) || (sqlTraces.isEmpty())) {
            /* 516:489 */ return;
            /* 517:    */ }
        /* 518:491 */ InitialSizedJsonArray params = new InitialSizedJsonArray(1);
        /* 519:492 */ params.add(sqlTraces);
        /* 520:493 */ Object response = invokeRunId("sql_trace_data", "identity", runId, params);
        /* 521:494 */ if ((response == null) || ("null".equals(response))) {
            /* 522:495 */ return;
            /* 523:    */ }
        /* 524:497 */ String msg = MessageFormat.format(
                "Invalid response from New Relic when sending sql traces. Response: {0}",
                new Object[] { response });
        /* 525:    */
        /* 526:499 */ Agent.LOG.warning(msg);
        /* 527:    */ }

    /* 528:    */
    /* 529:    */ public void sendTransactionTraceData(List<TransactionTrace> traces)/* 530:    */ throws Exception
    /* 531:    */ {
        /* 532:504 */ Object runId = this.agentRunId;
        /* 533:505 */ if ((runId == NO_AGENT_RUN_ID) || (traces.isEmpty())) {
            /* 534:506 */ return;
            /* 535:    */ }
        /* 536:508 */ InitialSizedJsonArray params = new InitialSizedJsonArray(2);
        /* 537:509 */ params.add(runId);
        /* 538:510 */ params.add(traces);
        /* 539:511 */ Object response = invokeRunId("transaction_sample_data", "identity", runId, params);
        /* 540:512 */ if ((response == null) || ("null".equals(response))) {
            /* 541:513 */ return;
            /* 542:    */ }
        /* 543:515 */ String msg = MessageFormat.format(
                "Invalid response from New Relic when sending transaction traces. Response: {0}",
                new Object[] { response });
        /* 544:    */
        /* 545:517 */ Agent.LOG.warning(msg);
        /* 546:    */ }

    /* 547:    */
    /* 548:    */ public void shutdown(long timeMillis)/* 549:    */ throws Exception
    /* 550:    */ {
        /* 551:522 */ Object runId = this.agentRunId;
        /* 552:523 */ if (runId == NO_AGENT_RUN_ID) {
            /* 553:524 */ return;
            /* 554:    */ }
        /* 555:526 */ InitialSizedJsonArray params = new InitialSizedJsonArray(2);
        /* 556:527 */ params.add(runId);
        /* 557:528 */ params.add(Long.valueOf(timeMillis));
        /* 558:529 */ int requestTimeoutInMillis = 10000;
        /* 559:    */ try
        /* 560:    */ {
            /* 561:531 */ invokeRunId("shutdown", "deflate", runId, requestTimeoutInMillis, params);
            /* 562:    */ }
        /* 563:    */ finally
        /* 564:    */ {
            /* 565:533 */ setAgentRunId(NO_AGENT_RUN_ID);
            /* 566:    */ }
        /* 567:    */ }

    /* 568:    */
    /* 569:    */ private Object invokeRunId(String method, String encoding, Object runId, JSONStreamAware params)
            /* 570:    */ throws Exception
    /* 571:    */ {
        /* 572:538 */ return invokeRunId(method, encoding, runId, this.defaultTimeoutInMillis, params);
        /* 573:    */ }

    /* 574:    */
    /* 575:    */ private Object invokeRunId(String method, String encoding, Object runId, int timeoutInMillis,
            JSONStreamAware params)/* 576:    */ throws Exception
    /* 577:    */ {
        /* 578:543 */ String uri = MessageFormat.format(this.agentRunIdUriPattern,
                new Object[] { method, runId.toString() });
        /* 579:544 */ return invoke(method, encoding, uri, params, timeoutInMillis);
        /* 580:    */ }

    /* 581:    */
    /* 582:    */ private Object invokeNoRunId(String method, String encoding, JSONStreamAware params)
            /* 583:    */ throws Exception
    /* 584:    */ {
        /* 585:548 */ String uri = MessageFormat.format(this.noAgentRunIdUriPattern, new Object[] { method });
        /* 586:549 */ return invoke(method, encoding, uri, params, this.defaultTimeoutInMillis);
        /* 587:    */ }

    /* 588:    */
    /* 589:    */ private Object invoke(String method, String encoding, String uri, JSONStreamAware params,
            int timeoutInMillis)/* 590:    */ throws Exception
    /* 591:    */ {
        /* 592:554 */ ReadResult readResult = send(method, encoding, uri, params, timeoutInMillis);
        /* 593:555 */ Map<?, ?> responseMap = null;
        /* 594:556 */ String responseBody = readResult.getResponseBody();
        /* 595:558 */ if (responseBody != null)
        /* 596:    */ {
            /* 597:559 */ Exception ex = null;
            /* 598:    */ try
            /* 599:    */ {
                /* 600:561 */ responseMap = getResponseMap(responseBody);
                /* 601:562 */ ex = parseException(responseMap);
                /* 602:    */ }
            /* 603:    */ catch (Exception e)
            /* 604:    */ {
                /* 605:565 */ Agent.LOG.log(Level.WARNING, "Error parsing response JSON({0}) from NewRelic: {1}",
                        new Object[] { method, e.toString() });
                /* 606:    */
                /* 607:567 */ Agent.LOG.log(Level.FINEST, "Invalid response JSON({0}): {1}",
                        new Object[] { method, responseBody });
                /* 608:    */
                /* 609:569 */ throw e;
                /* 610:    */ }
            /* 611:571 */ if (ex != null) {
                /* 612:572 */ throw ex;
                /* 613:    */ }
            /* 614:    */ }
        /* 615:    */ else
        /* 616:    */ {
            /* 617:576 */ Agent.LOG.log(Level.FINER, "Response was null ({0})", new Object[] { method });
            /* 618:    */ }
        /* 619:579 */ if (responseMap != null) {
            /* 620:580 */ return responseMap.get("return_value");
            /* 621:    */ }
        /* 622:582 */ return null;
        /* 623:    */ }

    /* 624:    */
    /* 625:    */ /* Error */
    /* 626:    */ private ReadResult connectAndSend(String method, String encoding, String uri,
            JSONStreamAware params, int timeoutInMillis)/* 627:    */ throws Exception
    /* 628:    */ {
        return null;
        /* 629:    */ // Byte code:
        /* 630:    */ //   0: aconst_null
        /* 631:    */ //   1: astore 6
        /* 632:    */ //   3: aload_0
        /* 633:    */ //   4: aload_2
        /* 634:    */ //   5: aload_3
        /* 635:    */ //   6: iload 5
        /* 636:    */ //   8: invokespecial 680   com/newrelic/agent/transport/DataSenderImpl:createHttpClient   (Ljava/lang/String;Ljava/lang/String;I)Lcom/newrelic/agent/deps/org/apache/http/impl/client/CloseableHttpClient;
        /* 637:    */ //   11: astore 6
        /* 638:    */ //   13: aload_0
        /* 639:    */ //   14: aload_2
        /* 640:    */ //   15: aload 4
        /* 641:    */ //   17: invokespecial 684   com/newrelic/agent/transport/DataSenderImpl:writeData   (Ljava/lang/String;Lcom/newrelic/agent/deps/org/json/simple/JSONStreamAware;)[B
        /* 642:    */ //   20: astore 7
        /* 643:    */ //   22: aload_0
        /* 644:    */ //   23: aload_2
        /* 645:    */ //   24: aload_3
        /* 646:    */ //   25: iload 5
        /* 647:    */ //   27: aload 7
        /* 648:    */ //   29: invokespecial 688   com/newrelic/agent/transport/DataSenderImpl:createRequest   (Ljava/lang/String;Ljava/lang/String;I[B)Lcom/newrelic/agent/deps/org/apache/http/client/methods/HttpUriRequest;
        /* 649:    */ //   32: astore 8
        /* 650:    */ //   34: aload_0
        /* 651:    */ //   35: invokespecial 692   com/newrelic/agent/transport/DataSenderImpl:createHttpContext   ()Lcom/newrelic/agent/deps/org/apache/http/protocol/HttpContext;
        /* 652:    */ //   38: astore 9
        /* 653:    */ //   40: aload 6
        /* 654:    */ //   42: aload 8
        /* 655:    */ //   44: aload 9
        /* 656:    */ //   46: invokevirtual 698   com/newrelic/agent/deps/org/apache/http/impl/client/CloseableHttpClient:execute   (Lcom/newrelic/agent/deps/org/apache/http/client/methods/HttpUriRequest;Lcom/newrelic/agent/deps/org/apache/http/protocol/HttpContext;)Lcom/newrelic/agent/deps/org/apache/http/client/methods/CloseableHttpResponse;
        /* 657:    */ //   49: astore 10
        /* 658:    */ //   51: aload 10
        /* 659:    */ //   53: invokeinterface 704 1 0
        /* 660:    */ //   58: astore 11
        /* 661:    */ //   60: aload 11
        /* 662:    */ //   62: ifnonnull +14 -> 76
        /* 663:    */ //   65: new 144   java/lang/Exception
        /* 664:    */ //   68: dup
        /* 665:    */ //   69: ldc_w 706
        /* 666:    */ //   72: invokespecial 707   java/lang/Exception:<init>   (Ljava/lang/String;)V
        /* 667:    */ //   75: athrow
        /* 668:    */ //   76: aload_0
        /* 669:    */ //   77: getfield 203   com/newrelic/agent/transport/DataSenderImpl:auditMode   Z
        /* 670:    */ //   80: ifeq +47 -> 127
        /* 671:    */ //   83: ldc_w 709
        /* 672:    */ //   86: iconst_3
        /* 673:    */ //   87: anewarray 4   java/lang/Object
        /* 674:    */ //   90: dup
        /* 675:    */ //   91: iconst_0
        /* 676:    */ //   92: aload_1
        /* 677:    */ //   93: aastore
        /* 678:    */ //   94: dup
        /* 679:    */ //   95: iconst_1
        /* 680:    */ //   96: aload 8
        /* 681:    */ //   98: invokeinterface 715 1 0
        /* 682:    */ //   103: aastore
        /* 683:    */ //   104: dup
        /* 684:    */ //   105: iconst_2
        /* 685:    */ //   106: aload 4
        /* 686:    */ //   108: invokestatic 721   com/newrelic/agent/transport/DataSenderWriter:toJSONString   (Ljava/lang/Object;)Ljava/lang/String;
        /* 687:    */ //   111: aastore
        /* 688:    */ //   112: invokestatic 169   java/text/MessageFormat:format   (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
        /* 689:    */ //   115: astore 12
        /* 690:    */ //   117: getstatic 207   com/newrelic/agent/Agent:LOG   Lcom/newrelic/agent/logging/IAgentLogger;
        /* 691:    */ //   120: aload 12
        /* 692:    */ //   122: invokeinterface 221 2 0
        /* 693:    */ //   127: aload 11
        /* 694:    */ //   129: invokeinterface 726 1 0
        /* 695:    */ //   134: istore 13
        /* 696:    */ //   136: iload 13
        /* 697:    */ //   138: sipush 407
        /* 698:    */ //   141: if_icmpne +51 -> 192
        /* 699:    */ //   144: aload 10
        /* 700:    */ //   146: ldc_w 728
        /* 701:    */ //   149: invokeinterface 732 2 0
        /* 702:    */ //   154: invokeinterface 737 1 0
        /* 703:    */ //   159: astore 12
        /* 704:    */ //   161: new 739   com/newrelic/agent/transport/HttpError
        /* 705:    */ //   164: dup
        /* 706:    */ //   165: new 309   java/lang/StringBuilder
        /* 707:    */ //   168: dup
        /* 708:    */ //   169: invokespecial 310   java/lang/StringBuilder:<init>   ()V
        /* 709:    */ //   172: ldc_w 741
        /* 710:    */ //   175: invokevirtual 314   java/lang/StringBuilder:append   (Ljava/lang/String;)Ljava/lang/StringBuilder;
        /* 711:    */ //   178: aload 12
        /* 712:    */ //   180: invokevirtual 314   java/lang/StringBuilder:append   (Ljava/lang/String;)Ljava/lang/StringBuilder;
        /* 713:    */ //   183: invokevirtual 316   java/lang/StringBuilder:toString   ()Ljava/lang/String;
        /* 714:    */ //   186: iload 13
        /* 715:    */ //   188: invokespecial 742   com/newrelic/agent/transport/HttpError:<init>   (Ljava/lang/String;I)V
        /* 716:    */ //   191: athrow
        /* 717:    */ //   192: iload 13
        /* 718:    */ //   194: sipush 200
        /* 719:    */ //   197: if_icmpeq +39 -> 236
        /* 720:    */ //   200: getstatic 207   com/newrelic/agent/Agent:LOG   Lcom/newrelic/agent/logging/IAgentLogger;
        /* 721:    */ //   203: getstatic 667   java/util/logging/Level:FINER   Ljava/util/logging/Level;
        /* 722:    */ //   206: ldc_w 744
        /* 723:    */ //   209: iconst_1
        /* 724:    */ //   210: anewarray 4   java/lang/Object
        /* 725:    */ //   213: dup
        /* 726:    */ //   214: iconst_0
        /* 727:    */ //   215: iload 13
        /* 728:    */ //   217: invokestatic 299   java/lang/Integer:valueOf   (I)Ljava/lang/Integer;
        /* 729:    */ //   220: aastore
        /* 730:    */ //   221: invokeinterface 659 4 0
        /* 731:    */ //   226: iload 13
        /* 732:    */ //   228: aload_0
        /* 733:    */ //   229: getfield 226   com/newrelic/agent/transport/DataSenderImpl:host   Ljava/lang/String;
        /* 734:    */ //   232: invokestatic 748   com/newrelic/agent/transport/HttpError:create   (ILjava/lang/String;)Lcom/newrelic/agent/transport/HttpError;
        /* 735:    */ //   235: athrow
        /* 736:    */ //   236: aload_0
        /* 737:    */ //   237: aload 10
        /* 738:    */ //   239: invokespecial 752   com/newrelic/agent/transport/DataSenderImpl:readResponseBody   (Lcom/newrelic/agent/deps/org/apache/http/client/methods/CloseableHttpResponse;)Ljava/lang/String;
        /* 739:    */ //   242: astore 12
        /* 740:    */ //   244: aload_0
        /* 741:    */ //   245: getfield 203   com/newrelic/agent/transport/DataSenderImpl:auditMode   Z
        /* 742:    */ //   248: ifeq +34 -> 282
        /* 743:    */ //   251: ldc_w 754
        /* 744:    */ //   254: iconst_2
        /* 745:    */ //   255: anewarray 4   java/lang/Object
        /* 746:    */ //   258: dup
        /* 747:    */ //   259: iconst_0
        /* 748:    */ //   260: aload_1
        /* 749:    */ //   261: aastore
        /* 750:    */ //   262: dup
        /* 751:    */ //   263: iconst_1
        /* 752:    */ //   264: aload 12
        /* 753:    */ //   266: aastore
        /* 754:    */ //   267: invokestatic 169   java/text/MessageFormat:format   (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
        /* 755:    */ //   270: astore 14
        /* 756:    */ //   272: getstatic 207   com/newrelic/agent/Agent:LOG   Lcom/newrelic/agent/logging/IAgentLogger;
        /* 757:    */ //   275: aload 14
        /* 758:    */ //   277: invokeinterface 221 2 0
        /* 759:    */ //   282: iload 13
        /* 760:    */ //   284: aload 12
        /* 761:    */ //   286: invokestatic 757   com/newrelic/agent/transport/ReadResult:create   (ILjava/lang/String;)Lcom/newrelic/agent/transport/ReadResult;
        /* 762:    */ //   289: astore 14
        /* 763:    */ //   291: jsr +17 -> 308
        /* 764:    */ //   294: jsr +33 -> 327
        /* 765:    */ //   297: aload 14
        /* 766:    */ //   299: areturn
        /* 767:    */ //   300: astore 15
        /* 768:    */ //   302: jsr +6 -> 308
        /* 769:    */ //   305: aload 15
        /* 770:    */ //   307: athrow
        /* 771:    */ //   308: astore 16
        /* 772:    */ //   310: aload 10
        /* 773:    */ //   312: invokeinterface 758 1 0
        /* 774:    */ //   317: ret 16
        /* 775:    */ //   319: astore 17
        /* 776:    */ //   321: jsr +6 -> 327
        /* 777:    */ //   324: aload 17
        /* 778:    */ //   326: athrow
        /* 779:    */ //   327: astore 18
        /* 780:    */ //   329: aload 6
        /* 781:    */ //   331: ifnull +8 -> 339
        /* 782:    */ //   334: aload 6
        /* 783:    */ //   336: invokevirtual 759   com/newrelic/agent/deps/org/apache/http/impl/client/CloseableHttpClient:close   ()V
        /* 784:    */ //   339: ret 18
        /* 785:    */ // Line number table:
        /* 786:    */ //   Java source line #589   -> byte code offset #0
        /* 787:    */ //   Java source line #592   -> byte code offset #3
        /* 788:    */ //   Java source line #594   -> byte code offset #13
        /* 789:    */ //   Java source line #595   -> byte code offset #22
        /* 790:    */ //   Java source line #597   -> byte code offset #34
        /* 791:    */ //   Java source line #598   -> byte code offset #40
        /* 792:    */ //   Java source line #600   -> byte code offset #51
        /* 793:    */ //   Java source line #601   -> byte code offset #60
        /* 794:    */ //   Java source line #602   -> byte code offset #65
        /* 795:    */ //   Java source line #605   -> byte code offset #76
        /* 796:    */ //   Java source line #606   -> byte code offset #83
        /* 797:    */ //   Java source line #608   -> byte code offset #117
        /* 798:    */ //   Java source line #611   -> byte code offset #127
        /* 799:    */ //   Java source line #613   -> byte code offset #136
        /* 800:    */ //   Java source line #614   -> byte code offset #144
        /* 801:    */ //   Java source line #615   -> byte code offset #161
        /* 802:    */ //   Java source line #616   -> byte code offset #192
        /* 803:    */ //   Java source line #617   -> byte code offset #200
        /* 804:    */ //   Java source line #618   -> byte code offset #226
        /* 805:    */ //   Java source line #621   -> byte code offset #236
        /* 806:    */ //   Java source line #622   -> byte code offset #244
        /* 807:    */ //   Java source line #623   -> byte code offset #251
        /* 808:    */ //   Java source line #624   -> byte code offset #272
        /* 809:    */ //   Java source line #626   -> byte code offset #282
        /* 810:    */ //   Java source line #628   -> byte code offset #300
        /* 811:    */ //   Java source line #632   -> byte code offset #319
        /* 812:    */ //   Java source line #633   -> byte code offset #334
        /* 813:    */ // Local variable table:
        /* 814:    */ //   start   length   slot   name   signature
        /* 815:    */ //   0   341   0   this   DataSenderImpl
        /* 816:    */ //   0   341   1   method   String
        /* 817:    */ //   0   341   2   encoding   String
        /* 818:    */ //   0   341   3   uri   String
        /* 819:    */ //   0   341   4   params   JSONStreamAware
        /* 820:    */ //   0   341   5   timeoutInMillis   int
        /* 821:    */ //   1   334   6   conn   CloseableHttpClient
        /* 822:    */ //   20   8   7   data   byte[]
        /* 823:    */ //   32   65   8   request   HttpUriRequest
        /* 824:    */ //   38   7   9   context   HttpContext
        /* 825:    */ //   49   262   10   response   CloseableHttpResponse
        /* 826:    */ //   58   70   11   statusLine   com.newrelic.agent.deps.org.apache.http.StatusLine
        /* 827:    */ //   115   6   12   msg   String
        /* 828:    */ //   159   20   12   authField   String
        /* 829:    */ //   242   43   12   responseBody   String
        /* 830:    */ //   134   149   13   statusCode   int
        /* 831:    */ //   270   28   14   msg   String
        /* 832:    */ //   300   6   15   localObject1   Object
        /* 833:    */ //   308   1   16   localObject2   Object
        /* 834:    */ //   319   6   17   localObject3   Object
        /* 835:    */ //   327   1   18   localObject4   Object
        /* 836:    */ // Exception table:
        /* 837:    */ //   from   to   target   type
        /* 838:    */ //   51   294   300   finally
        /* 839:    */ //   300   305   300   finally
        /* 840:    */ //   3   297   319   finally
        /* 841:    */ //   300   324   319   finally
        /* 842:    */ }

    /* 843:    */
    /* 844:    */ private HttpContext createHttpContext()
    /* 845:    */ {
        /* 846:639 */ HttpClientContext context = new HttpClientContext();
        /* 847:641 */ if ((this.proxy != null) && (this.proxyCredentials != null))
        /* 848:    */ {
            /* 849:642 */ CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            /* 850:643 */ credentialsProvider.setCredentials(new AuthScope(this.proxy), this.proxyCredentials);
            /* 851:644 */ context.setCredentialsProvider(credentialsProvider);
            /* 852:    */ }
        /* 853:647 */ return context;
        /* 854:    */ }

    /* 855:    */
    /* 856:    */ private ReadResult send(String method, String encoding, String uri, JSONStreamAware params,
            int timeoutInMillis)/* 857:    */ throws Exception
    /* 858:    */ {
        /* 859:    */ try
        /* 860:    */ {
            /* 861:653 */ return connectAndSend(method, encoding, uri, params, timeoutInMillis);
            /* 862:    */ }
        /* 863:    */ catch (MalformedURLException e)
        /* 864:    */ {
            /* 865:655 */ Agent.LOG.log(Level.SEVERE,
                    "You have requested a connection to New Relic via a protocol which is unavailable in your runtime: {0}",
                    new Object[] { e.toString() });
            /* 866:    */
            /* 867:    */
            /* 868:    */
            /* 869:659 */ throw new ForceDisconnectException(e.toString());
            /* 870:    */ }
        /* 871:    */ catch (SocketException e)
        /* 872:    */ {
            /* 873:661 */ if ((e.getCause() instanceof NoSuchAlgorithmException))
            /* 874:    */ {
                /* 875:662 */ String msg = MessageFormat.format(
                        "You have requested a connection to New Relic via an algorithm which is unavailable in your runtime: {0}  This may also be indicative of a corrupted keystore or trust store on your server.",
                        new Object[] { e.getCause().toString() });
                /* 876:    */
                /* 877:    */
                /* 878:665 */ Agent.LOG.error(msg);
                /* 879:    */ }
            /* 880:    */ else
            /* 881:    */ {
                /* 882:668 */ Agent.LOG.log(Level.INFO,
                        "A socket exception was encountered while sending data to New Relic ({0}).  Please check your network / proxy settings.",
                        new Object[] { e.toString() });
                /* 883:672 */ if (Agent.LOG.isLoggable(Level.FINE)) {
                    /* 884:673 */ Agent.LOG.log(Level.FINE, "Error sending JSON({0}): {1}",
                            new Object[] { method, DataSenderWriter.toJSONString(params) });
                    /* 885:    */ }
                /* 886:676 */ Agent.LOG.log(Level.FINEST, e, e.toString(), new Object[0]);
                /* 887:    */ }
            /* 888:678 */ throw e;
            /* 889:    */ }
        /* 890:    */ catch (HttpError e)
        /* 891:    */ {
            /* 892:707 */ throw e;
            /* 893:    */ }
        /* 894:    */ catch (Exception e)
        /* 895:    */ {
            /* 896:709 */ Agent.LOG.log(Level.INFO, "Remote {0} call failed : {1}.",
                    new Object[] { method, e.toString() });
            /* 897:710 */ if (Agent.LOG.isLoggable(Level.FINE)) {
                /* 898:711 */ Agent.LOG.log(Level.FINE, "Error sending JSON({0}): {1}",
                        new Object[] { method, DataSenderWriter.toJSONString(params) });
                /* 899:    */ }
            /* 900:713 */ Agent.LOG.log(Level.FINEST, e, e.toString(), new Object[0]);
            /* 901:714 */ throw e;
            /* 902:    */ }
        /* 903:    */ }

    /* 904:    */
    /* 905:    */ private HttpUriRequest createRequest(String encoding, String uri, int requestTimeoutInMillis,
            byte[] data)/* 906:    */ throws MalformedURLException, URISyntaxException
    /* 907:    */ {
        /* 908:720 */ URL url = new URL(this.protocol, this.host, this.port, uri);
        /* 909:721 */ RequestConfig config = RequestConfig.custom().setConnectTimeout(requestTimeoutInMillis)
                .setConnectionRequestTimeout(requestTimeoutInMillis).setSocketTimeout(requestTimeoutInMillis)
                .build();
        /* 910:    */
        /* 911:723 */ RequestBuilder requestBuilder = RequestBuilder.post().setUri(url.toURI())
                .setEntity(new ByteArrayEntity(data));
        /* 912:724 */ requestBuilder.setConfig(config);
        /* 913:    */
        /* 914:726 */ return requestBuilder.build();
        /* 915:    */ }

    /* 916:    */
    /* 917:    */ private CloseableHttpClient createHttpClient(String encoding, String uri,
            int requestTimeoutInMillis)/* 918:    */ throws Exception
    /* 919:    */ {
        /* 920:732 */ HttpClientBuilder builder = HttpClientBuilder.create();
        /* 921:733 */ builder.setUserAgent(USER_AGENT_HEADER_VALUE)
                .setDefaultHeaders(Arrays.asList(new Header[] { new BasicHeader("Connection", "Keep-Alive"),
                        new BasicHeader("CONTENT-TYPE", "application/octet-stream"),
                        new BasicHeader("ACCEPT-ENCODING", "gzip"),
                        new BasicHeader("CONTENT-ENCODING", encoding) }));
        /* 922:    */
        /* 923:    */
        /* 924:    */
        /* 925:737 */ builder.setDefaultSocketConfig(
                SocketConfig.custom().setSoTimeout(requestTimeoutInMillis).setSoKeepAlive(true).build());
        /* 926:    */
        /* 927:739 */ RequestConfig.Builder requestBuilder = RequestConfig.custom()
                .setConnectTimeout(requestTimeoutInMillis).setConnectionRequestTimeout(requestTimeoutInMillis)
                .setSocketTimeout(requestTimeoutInMillis);
        /* 928:    */
        /* 929:    */
        /* 930:742 */ builder.setDefaultRequestConfig(requestBuilder.build());
        /* 931:    */
        /* 932:744 */ builder.setHostnameVerifier(new StrictHostnameVerifier());
        /* 933:746 */ if (this.proxy != null) {
            /* 934:747 */ builder.setProxy(this.proxy);
            /* 935:    */ }
        /* 936:750 */ if (this.sslContext != null) {
            /* 937:751 */ builder.setSSLSocketFactory(new SSLConnectionSocketFactory(this.sslContext));
            /* 938:    */ }
        /* 939:754 */ CloseableHttpClient httpClient = builder.build();
        /* 940:    */
        /* 941:756 */ return httpClient;
        /* 942:    */ }

    /* 943:    */
    /* 944:    */ private byte[] writeData(String encoding, JSONStreamAware params)/* 945:    */ throws IOException
    /* 946:    */ {
        /* 947:760 */ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        /* 948:761 */ Writer out = null;
        /* 949:    */ try
        /* 950:    */ {
            /* 951:763 */ OutputStream os = getOutputStream(outStream, encoding);
            /* 952:764 */ out = new OutputStreamWriter(os, "UTF-8");
            /* 953:765 */ JSONValue.writeJSONString(params, out);
            /* 954:766 */ out.flush();
            /* 955:    */ }
        /* 956:    */ finally
        /* 957:    */ {
            /* 958:768 */ if (out != null) {
                /* 959:769 */ out.close();
                /* 960:    */ }
            /* 961:    */ }
        /* 962:772 */ return outStream.toByteArray();
        /* 963:    */ }

    /* 964:    */
    /* 965:    */ private OutputStream getOutputStream(OutputStream out, String encoding)
            /* 966:    */ throws IOException
    /* 967:    */ {
        /* 968:776 */ if ("deflate".equals(encoding)) {
            /* 969:777 */ return new DeflaterOutputStream(out, new Deflater(-1));
            /* 970:    */ }
        /* 971:779 */ return out;
        /* 972:    */ }

    /* 973:    */
    /* 974:    */ private String readResponseBody(CloseableHttpResponse response)/* 975:    */ throws Exception
    /* 976:    */ {
        /* 977:784 */ HttpEntity entity = response.getEntity();
        /* 978:785 */ if (entity == null) {
            /* 979:786 */ throw new Exception("The http response entity was null");
            /* 980:    */ }
        /* 981:788 */ InputStream is = entity.getContent();
        /* 982:789 */ BufferedReader in = getBufferedReader(response, is);
        /* 983:    */ try
        /* 984:    */ {
            /* 985:791 */ return in.readLine();
            /* 986:    */ }
        /* 987:    */ finally
        /* 988:    */ {
            /* 989:793 */ in.close();
            /* 990:794 */ is.close();
            /* 991:    */ }
        /* 992:    */ }

    /* 993:    */
    /* 994:    */ private Map<?, ?> getResponseMap(String responseBody)/* 995:    */ throws Exception
    /* 996:    */ {
        /* 997:799 */ JSONParser parser = new JSONParser();
        /* 998:800 */ Object response = parser.parse(responseBody);
        /* 999:801 */ return (Map) Map.class.cast(response);
        /* :00:    */ }

    /* :01:    */
    /* :02:    */ private BufferedReader getBufferedReader(CloseableHttpResponse response, InputStream is)
            /* :03:    */ throws IOException
    /* :04:    */ {
        /* :05:805 */ Header encodingHeader = response.getFirstHeader("content-encoding");
        /* :06:806 */ if (encodingHeader != null)
        /* :07:    */ {
            /* :08:807 */ String encoding = encodingHeader.getValue();
            /* :09:808 */ if ("gzip".equals(encoding)) {
                /* :10:809 */ is = new GZIPInputStream(is);
                /* :11:    */ }
            /* :12:    */ }
        /* :13:812 */ return new BufferedReader(new InputStreamReader(is, "UTF-8"));
        /* :14:    */ }

    /* :15:    */
    /* :16:    */ private Exception parseException(Map<?, ?> responseMap)/* :17:    */ throws Exception
    /* :18:    */ {
        /* :19:823 */ Object exception = responseMap.get("exception");
        /* :20:824 */ if (exception == null) {
            /* :21:825 */ return null;
            /* :22:    */ }
        /* :23:827 */ Map<?, ?> exceptionMap = (Map) Map.class.cast(exception);
        /* :24:    */ String message;
        /* :25:    */ try
        /* :26:    */ {
            /* :27:830 */ message = (String) exceptionMap.get("message");
            /* :28:    */ }
        /* :29:    */ catch (Exception e)
        /* :30:    */ {
            /* :31:832 */ message = exceptionMap.toString();
            /* :32:    */ }
        /* :33:834 */ String type = (String) exceptionMap.get("error_type");
        /* :34:835 */ Class<Exception> clazz = RubyConversion.rubyClassToJavaClass(type);
        /* :35:836 */ Constructor<Exception> constructor = clazz.getConstructor(new Class[] { String.class });
        /* :36:837 */ return (Exception) constructor.newInstance(new Object[] { message });
        /* :37:    */ }
    /* :38:    */ }

/* Location:           E:\tmp\newrelic\newrelic.jar
    
 * Qualified Name:     com.newrelic.agent.transport.DataSenderImpl
    
 * JD-Core Version:    0.7.0.1
    
 */