From 32378f7235a38216cd24e97576d3192b2ec134ab Mon Sep 17 00:00:00 2001 From: Jason Keller Date: Fri, 29 Mar 2024 14:44:10 -0700 Subject: [PATCH] Revert httpurlconnection InboundWrapper changes --- .../httpurlconnection/InboundWrapper.java | 12 ++++-------- .../httpurlconnection/InboundTest.java | 14 ++------------ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/instrumentation/httpurlconnection/src/main/java/com/nr/agent/instrumentation/httpurlconnection/InboundWrapper.java b/instrumentation/httpurlconnection/src/main/java/com/nr/agent/instrumentation/httpurlconnection/InboundWrapper.java index 36914d0b99..750192be2c 100644 --- a/instrumentation/httpurlconnection/src/main/java/com/nr/agent/instrumentation/httpurlconnection/InboundWrapper.java +++ b/instrumentation/httpurlconnection/src/main/java/com/nr/agent/instrumentation/httpurlconnection/InboundWrapper.java @@ -9,30 +9,26 @@ import java.net.HttpURLConnection; import java.util.List; -import java.util.Map; import com.newrelic.api.agent.HeaderType; import com.newrelic.api.agent.ExtendedInboundHeaders; public class InboundWrapper extends ExtendedInboundHeaders { - private final Map> headers; + private final HttpURLConnection connection; public InboundWrapper(HttpURLConnection connection) { - this.headers = connection.getHeaderFields(); + this.connection = connection; } @Override public String getHeader(String name) { - if (headers == null || name == null) return null; - List result = headers.get(name); - return result == null || result.isEmpty() ? null : result.get(0); + return connection.getHeaderField(name); } @Override public List getHeaders(String name) { - if (headers == null || name == null) return null; - return headers.get(name); + return connection.getHeaderFields().get(name); } @Override diff --git a/instrumentation/httpurlconnection/src/test/java/com/nr/agent/instrumentation/httpurlconnection/InboundTest.java b/instrumentation/httpurlconnection/src/test/java/com/nr/agent/instrumentation/httpurlconnection/InboundTest.java index 079c4b9c0e..08f291c087 100644 --- a/instrumentation/httpurlconnection/src/test/java/com/nr/agent/instrumentation/httpurlconnection/InboundTest.java +++ b/instrumentation/httpurlconnection/src/test/java/com/nr/agent/instrumentation/httpurlconnection/InboundTest.java @@ -176,18 +176,8 @@ public void connectResponseMessageTest() throws Exception { } private String fetchTransactionName(Introspector introspector, String expectedMethod) { - // The number 2 is a little misleading here, 1 should be the real number, but because of the way we - // are mocking the weaved class for testing, it will be 2 here. - // One comes from the InboundWrapper call to get the headers, which forces a call to getInputStream, - // which actually calls the the HttpServerImpl which creates the transaction. - // The other comes from the "call" methods in this test class - assertEquals(2, introspector.getFinishedTransactionCount(500)); - - String transactionName = introspector.getTransactionNames().stream() - .filter( n -> n.contains(expectedMethod)) - .findFirst() - .orElse(null); - + assertEquals(1, introspector.getFinishedTransactionCount(500)); + String transactionName = introspector.getTransactionNames().iterator().next(); boolean foundExpectedEvent = false; for (TransactionEvent event : introspector.getTransactionEvents(transactionName)) { foundExpectedEvent = foundExpectedEvent || event.getName().endsWith("/" + expectedMethod);