From 7bb978d2da39e110c0693ceb05f5a453e7c85d64 Mon Sep 17 00:00:00 2001 From: Anurag Agarwal Date: Mon, 27 Feb 2023 22:23:16 +0530 Subject: [PATCH] HttpClient 4.0 java tests (#7912) Converts apache-httpclient-4.0 unit tests in java. Version 4.0 was using GuardedBy annotation which was interfering with the test cases, hence the library version was shifted to 4.1. https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/7195 --- .../javaagent/build.gradle.kts | 1 + .../test/groovy/ApacheHttpClientTest.groovy | 253 ------------------ .../src/test/groovy/HttpUriRequest.groovy | 21 -- .../v4_0/AbstractApacheHttpClientTest.java | 103 +++++++ .../v4_0/ApacheHttpClientTest.java | 217 +++++++++++++++ .../apachehttpclient/v4_0/HttpUriRequest.java | 24 ++ 6 files changed, 345 insertions(+), 274 deletions(-) delete mode 100644 instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/ApacheHttpClientTest.groovy delete mode 100644 instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/HttpUriRequest.groovy create mode 100644 instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/AbstractApacheHttpClientTest.java create mode 100644 instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientTest.java create mode 100644 instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/HttpUriRequest.java diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/build.gradle.kts b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/build.gradle.kts index afabfa6580a2..a3f37820ea2e 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/build.gradle.kts +++ b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/build.gradle.kts @@ -25,4 +25,5 @@ muzzle { dependencies { library("org.apache.httpcomponents:httpclient:4.0") + testCompileOnly("net.jcip:jcip-annotations:1.0") } diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/ApacheHttpClientTest.groovy b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/ApacheHttpClientTest.groovy deleted file mode 100644 index 995e2cce6074..000000000000 --- a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/ApacheHttpClientTest.groovy +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import io.opentelemetry.api.common.AttributeKey -import io.opentelemetry.instrumentation.test.AgentTestTrait -import io.opentelemetry.instrumentation.test.base.HttpClientTest -import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes -import org.apache.http.HttpHost -import org.apache.http.HttpRequest -import org.apache.http.HttpResponse -import org.apache.http.client.params.ClientPNames -import org.apache.http.conn.ClientConnectionManager -import org.apache.http.conn.ClientConnectionManagerFactory -import org.apache.http.conn.scheme.SchemeRegistry -import org.apache.http.impl.client.DefaultHttpClient -import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager -import org.apache.http.message.BasicHeader -import org.apache.http.message.BasicHttpRequest -import org.apache.http.params.BasicHttpParams -import org.apache.http.params.HttpConnectionParams -import org.apache.http.params.HttpParams -import org.apache.http.protocol.BasicHttpContext -import spock.lang.Shared - -import java.util.function.Consumer - -abstract class ApacheHttpClientTest extends HttpClientTest implements AgentTestTrait { - @Shared - DefaultHttpClient client = buildClient(false) - - @Shared - DefaultHttpClient clientWithReadTimeout = buildClient(true) - - DefaultHttpClient buildClient(boolean readTimeout) { - HttpParams httpParams = new BasicHttpParams() - HttpConnectionParams.setConnectionTimeout(httpParams, CONNECT_TIMEOUT_MS) - if (readTimeout) { - HttpConnectionParams.setSoTimeout(httpParams, READ_TIMEOUT_MS) - } - httpParams.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, ThreadSafeClientConnManagerFactory.getName()) - return new DefaultHttpClient(httpParams) - } - - DefaultHttpClient getClient(URI uri) { - if (uri.toString().contains("/read-timeout")) { - return clientWithReadTimeout - } - return client - } - - static class ThreadSafeClientConnManagerFactory implements ClientConnectionManagerFactory { - @Override - ClientConnectionManager newInstance(HttpParams httpParams, SchemeRegistry schemeRegistry) { - return new ThreadSafeClientConnManager(httpParams, schemeRegistry) - } - } - - def cleanupSpec() { - client.getConnectionManager().shutdown() - clientWithReadTimeout.getConnectionManager().shutdown() - } - - @Override - String userAgent() { - return "apachehttpclient" - } - - @Override - boolean testReadTimeout() { - true - } - - @Override - T buildRequest(String method, URI uri, Map headers) { - def request = createRequest(method, uri) - request.addHeader("user-agent", userAgent()) - headers.entrySet().each { - request.setHeader(new BasicHeader(it.key, it.value)) - } - return request - } - - @Override - Set> httpAttributes(URI uri) { - Set> extra = [ - SemanticAttributes.HTTP_SCHEME, - SemanticAttributes.HTTP_TARGET - ] - super.httpAttributes(uri) + extra - } - - // compilation fails with @Override annotation on this method (groovy quirk?) - int sendRequest(T request, String method, URI uri, Map headers) { - def response = executeRequest(request, uri) - response.entity?.content?.close() // Make sure the connection is closed. - return response.statusLine.statusCode - } - - // compilation fails with @Override annotation on this method (groovy quirk?) - void sendRequestWithCallback(T request, String method, URI uri, Map headers, HttpClientResult requestResult) { - try { - executeRequestWithCallback(request, uri) { - it.entity?.content?.close() // Make sure the connection is closed. - requestResult.complete(it.statusLine.statusCode) - } - } catch (Throwable throwable) { - requestResult.complete(throwable) - } - } - - abstract T createRequest(String method, URI uri) - - abstract HttpResponse executeRequest(T request, URI uri) - - abstract void executeRequestWithCallback(T request, URI uri, Consumer callback) - - static String fullPathFromURI(URI uri) { - StringBuilder builder = new StringBuilder() - if (uri.getPath() != null) { - builder.append(uri.getPath()) - } - - if (uri.getQuery() != null) { - builder.append('?') - builder.append(uri.getQuery()) - } - - if (uri.getFragment() != null) { - builder.append('#') - builder.append(uri.getFragment()) - } - return builder.toString() - } -} - -class ApacheClientHostRequest extends ApacheHttpClientTest { - @Override - BasicHttpRequest createRequest(String method, URI uri) { - // also testing with an absolute path below - return new BasicHttpRequest(method, fullPathFromURI(uri)) - } - - @Override - HttpResponse executeRequest(BasicHttpRequest request, URI uri) { - return getClient(uri).execute(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), request) - } - - @Override - void executeRequestWithCallback(BasicHttpRequest request, URI uri, Consumer callback) { - getClient(uri).execute(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), request) { - callback.accept(it) - } - } -} - -class ApacheClientHostAbsoluteUriRequest extends ApacheHttpClientTest { - @Override - BasicHttpRequest createRequest(String method, URI uri) { - return new BasicHttpRequest(method, uri.toString()) - } - - @Override - HttpResponse executeRequest(BasicHttpRequest request, URI uri) { - return getClient(uri).execute(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), request) - } - - @Override - void executeRequestWithCallback(BasicHttpRequest request, URI uri, Consumer callback) { - getClient(uri).execute(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), request) { - callback.accept(it) - } - } -} - -class ApacheClientHostRequestContext extends ApacheHttpClientTest { - @Override - BasicHttpRequest createRequest(String method, URI uri) { - // also testing with an absolute path below - return new BasicHttpRequest(method, fullPathFromURI(uri)) - } - - @Override - HttpResponse executeRequest(BasicHttpRequest request, URI uri) { - return getClient(uri).execute(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), request, new BasicHttpContext()) - } - - @Override - void executeRequestWithCallback(BasicHttpRequest request, URI uri, Consumer callback) { - getClient(uri).execute(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), request, { - callback.accept(it) - }, new BasicHttpContext()) - } -} - -class ApacheClientHostAbsoluteUriRequestContext extends ApacheHttpClientTest { - @Override - BasicHttpRequest createRequest(String method, URI uri) { - return new BasicHttpRequest(method, uri.toString()) - } - - @Override - HttpResponse executeRequest(BasicHttpRequest request, URI uri) { - return getClient(uri).execute(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), request, new BasicHttpContext()) - } - - @Override - void executeRequestWithCallback(BasicHttpRequest request, URI uri, Consumer callback) { - getClient(uri).execute(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), request, { - callback.accept(it) - }, new BasicHttpContext()) - } -} - -class ApacheClientUriRequest extends ApacheHttpClientTest { - @Override - HttpUriRequest createRequest(String method, URI uri) { - return new HttpUriRequest(method, uri) - } - - @Override - HttpResponse executeRequest(HttpUriRequest request, URI uri) { - return getClient(uri).execute(request) - } - - @Override - void executeRequestWithCallback(HttpUriRequest request, URI uri, Consumer callback) { - getClient(uri).execute(request) { - callback.accept(it) - } - } -} - -class ApacheClientUriRequestContext extends ApacheHttpClientTest { - @Override - HttpUriRequest createRequest(String method, URI uri) { - return new HttpUriRequest(method, uri) - } - - @Override - HttpResponse executeRequest(HttpUriRequest request, URI uri) { - return getClient(uri).execute(request, new BasicHttpContext()) - } - - @Override - void executeRequestWithCallback(HttpUriRequest request, URI uri, Consumer callback) { - getClient(uri).execute(request, { - callback.accept(it) - }, new BasicHttpContext()) - } -} diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/HttpUriRequest.groovy b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/HttpUriRequest.groovy deleted file mode 100644 index 4a3c7bd57bb1..000000000000 --- a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/HttpUriRequest.groovy +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import org.apache.http.client.methods.HttpRequestBase - -class HttpUriRequest extends HttpRequestBase { - - private final String methodName - - HttpUriRequest(final String methodName, final URI uri) { - this.methodName = methodName - setURI(uri) - } - - @Override - String getMethod() { - return methodName - } -} diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/AbstractApacheHttpClientTest.java b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/AbstractApacheHttpClientTest.java new file mode 100644 index 000000000000..fe0cd6efbc62 --- /dev/null +++ b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/AbstractApacheHttpClientTest.java @@ -0,0 +1,103 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; +import java.net.URI; +import java.util.Map; +import java.util.Set; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; + +abstract class AbstractApacheHttpClientTest + extends AbstractHttpClientTest { + @Override + protected String userAgent() { + return "apachehttpclient"; + } + + @Override + protected void configure(HttpClientTestOptions.Builder optionsBuilder) { + optionsBuilder.setUserAgent(userAgent()); + optionsBuilder.enableTestReadTimeout(); + optionsBuilder.setHttpAttributes(AbstractApacheHttpClientTest::getHttpAttributes); + } + + private static Set> getHttpAttributes(URI endpoint) { + return HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES; + } + + @Override + public T buildRequest(String method, URI uri, Map headers) { + T request = createRequest(method, uri); + request.addHeader("user-agent", userAgent()); + headers.forEach(request::setHeader); + return request; + } + + @Override + public int sendRequest(T request, String method, URI uri, Map headers) + throws Exception { + return getResponseCode(executeRequest(request, uri)); + } + + @Override + public void sendRequestWithCallback( + T request, + String method, + URI uri, + Map headers, + HttpClientResult requestResult) { + try { + executeRequestWithCallback(request, uri, requestResult); + } catch (Throwable throwable) { + requestResult.complete(throwable); + } + } + + protected HttpHost getHost(URI uri) { + return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); + } + + protected HttpContext getContext() { + return new BasicHttpContext(); + } + + protected static String fullPathFromUri(URI uri) { + StringBuilder builder = new StringBuilder(); + if (uri.getPath() != null) { + builder.append(uri.getPath()); + } + + if (uri.getQuery() != null) { + builder.append('?'); + builder.append(uri.getQuery()); + } + + if (uri.getFragment() != null) { + builder.append('#'); + builder.append(uri.getFragment()); + } + return builder.toString(); + } + + abstract T createRequest(String method, URI uri); + + abstract HttpResponse executeRequest(T request, URI uri) throws Exception; + + abstract void executeRequestWithCallback(T request, URI uri, HttpClientResult requestResult) + throws Exception; + + private static int getResponseCode(HttpResponse response) { + return response.getStatusLine().getStatusCode(); + } +} diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientTest.java b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientTest.java new file mode 100644 index 000000000000..426eb90f4c0d --- /dev/null +++ b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientTest.java @@ -0,0 +1,217 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0; + +import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest.CONNECTION_TIMEOUT; +import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest.READ_TIMEOUT; + +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; +import java.net.URI; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.params.ClientPNames; +import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.conn.ClientConnectionManagerFactory; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; +import org.apache.http.message.BasicHttpRequest; +import org.apache.http.params.BasicHttpParams; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.RegisterExtension; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class ApacheHttpClientTest { + @RegisterExtension + static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent(); + + private final DefaultHttpClient client = buildClient(false); + private final DefaultHttpClient clientWithReadTimeout = buildClient(true); + + @AfterAll + void tearDown() { + client.getConnectionManager().shutdown(); + clientWithReadTimeout.getConnectionManager().shutdown(); + } + + private static DefaultHttpClient buildClient(boolean readTimeout) { + HttpParams httpParams = new BasicHttpParams(); + HttpConnectionParams.setConnectionTimeout(httpParams, (int) CONNECTION_TIMEOUT.toMillis()); + if (readTimeout) { + HttpConnectionParams.setSoTimeout(httpParams, (int) READ_TIMEOUT.toMillis()); + } + httpParams.setParameter( + ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, + ThreadSafeClientConnManagerFactory.class.getName()); + return new DefaultHttpClient(httpParams); + } + + private DefaultHttpClient getClient(URI uri) { + if (uri.toString().contains("/read-timeout")) { + return clientWithReadTimeout; + } + return client; + } + + public static class ThreadSafeClientConnManagerFactory implements ClientConnectionManagerFactory { + @Override + public ClientConnectionManager newInstance( + HttpParams httpParams, SchemeRegistry schemeRegistry) { + return new ThreadSafeClientConnManager(httpParams, schemeRegistry); + } + } + + @Nested + class ApacheClientHostRequestTest extends AbstractTest { + @Override + public BasicHttpRequest createRequest(String method, URI uri) { + // also testing with an absolute path below + return new BasicHttpRequest(method, fullPathFromUri(uri)); + } + + @Override + public HttpResponse doExecuteRequest(BasicHttpRequest request, URI uri) throws Exception { + return getClient(uri).execute(getHost(uri), request); + } + + @Override + void executeRequestWithCallback(BasicHttpRequest request, URI uri, HttpClientResult result) + throws Exception { + getClient(uri).execute(getHost(uri), request, new HttpResponseHandler(result)); + } + } + + @Nested + class ApacheClientHostAbsoluteUriRequestTest extends AbstractTest { + @Override + BasicHttpRequest createRequest(String method, URI uri) { + return new BasicHttpRequest(method, uri.toString()); + } + + @Override + HttpResponse doExecuteRequest(BasicHttpRequest request, URI uri) throws Exception { + return getClient(uri).execute(getHost(uri), request); + } + + @Override + void executeRequestWithCallback(BasicHttpRequest request, URI uri, HttpClientResult result) + throws Exception { + getClient(uri).execute(getHost(uri), request, new HttpResponseHandler(result)); + } + } + + @Nested + class ApacheClientHostRequestContextTest extends AbstractTest { + @Override + BasicHttpRequest createRequest(String method, URI uri) { + // also testing with an absolute path below + return new BasicHttpRequest(method, fullPathFromUri(uri)); + } + + @Override + HttpResponse doExecuteRequest(BasicHttpRequest request, URI uri) throws Exception { + return getClient(uri).execute(getHost(uri), request, getContext()); + } + + @Override + void executeRequestWithCallback(BasicHttpRequest request, URI uri, HttpClientResult result) + throws Exception { + getClient(uri).execute(getHost(uri), request, new HttpResponseHandler(result), getContext()); + } + } + + @Nested + class ApacheClientHostAbsoluteUriRequestContextTest extends AbstractTest { + @Override + BasicHttpRequest createRequest(String method, URI uri) { + return new BasicHttpRequest(method, uri.toString()); + } + + @Override + HttpResponse doExecuteRequest(BasicHttpRequest request, URI uri) throws Exception { + return getClient(uri).execute(getHost(uri), request, getContext()); + } + + @Override + void executeRequestWithCallback(BasicHttpRequest request, URI uri, HttpClientResult result) + throws Exception { + getClient(uri).execute(getHost(uri), request, new HttpResponseHandler(result), getContext()); + } + } + + @Nested + class ApacheClientUriRequestTest extends AbstractTest { + @Override + HttpUriRequest createRequest(String method, URI uri) { + return new HttpUriRequest(method, uri); + } + + @Override + HttpResponse doExecuteRequest(HttpUriRequest request, URI uri) throws Exception { + return getClient(uri).execute(request); + } + + @Override + void executeRequestWithCallback(HttpUriRequest request, URI uri, HttpClientResult result) + throws Exception { + getClient(uri).execute(request, new HttpResponseHandler(result)); + } + } + + @Nested + class ApacheClientUriRequestContextTest extends AbstractTest { + @Override + HttpUriRequest createRequest(String method, URI uri) { + return new HttpUriRequest(method, uri); + } + + @Override + HttpResponse doExecuteRequest(HttpUriRequest request, URI uri) throws Exception { + return getClient(uri).execute(request, getContext()); + } + + @Override + void executeRequestWithCallback(HttpUriRequest request, URI uri, HttpClientResult result) + throws Exception { + getClient(uri).execute(request, new HttpResponseHandler(result), getContext()); + } + } + + abstract static class AbstractTest + extends AbstractApacheHttpClientTest { + @Override + final HttpResponse executeRequest(T request, URI uri) throws Exception { + HttpResponse httpResponse = doExecuteRequest(request, uri); + httpResponse.getEntity().getContent().close(); + return httpResponse; + } + + abstract HttpResponse doExecuteRequest(T request, URI uri) throws Exception; + } + + private static class HttpResponseHandler implements ResponseHandler { + private final HttpClientResult requestResult; + + public HttpResponseHandler(HttpClientResult requestResult) { + this.requestResult = requestResult; + } + + @Override + public Void handleResponse(HttpResponse response) throws IOException { + response.getEntity().getContent().close(); + requestResult.complete(response.getStatusLine().getStatusCode()); + return null; + } + } +} diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/HttpUriRequest.java b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/HttpUriRequest.java new file mode 100644 index 000000000000..3c93819482ae --- /dev/null +++ b/instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/HttpUriRequest.java @@ -0,0 +1,24 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0; + +import java.net.URI; +import org.apache.http.client.methods.HttpRequestBase; + +final class HttpUriRequest extends HttpRequestBase { + + private final String methodName; + + HttpUriRequest(String methodName, URI uri) { + this.methodName = methodName; + setURI(uri); + } + + @Override + public String getMethod() { + return methodName; + } +}