Skip to content

Commit

Permalink
Merge pull request #1840 from newrelic/revert-httpurlconnection-chang…
Browse files Browse the repository at this point in the history
…e-8-10-0

Revert httpurlconnection InboundWrapper changes
  • Loading branch information
jasonjkeller authored Apr 3, 2024
2 parents 1d060c9 + 32378f7 commit ef98cb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, List<String>> 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<String> result = headers.get(name);
return result == null || result.isEmpty() ? null : result.get(0);
return connection.getHeaderField(name);
}

@Override
public List<String> getHeaders(String name) {
if (headers == null || name == null) return null;
return headers.get(name);
return connection.getHeaderFields().get(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ef98cb6

Please sign in to comment.