Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert httpurlconnection InboundWrapper changes #1840

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading