Remove spring-web dependency from ZipkinHttpClientSender
Closes gh-42160
This commit is contained in:
@@ -27,7 +27,8 @@ import zipkin2.reporter.BytesMessageSender;
|
||||
import zipkin2.reporter.Encoding;
|
||||
import zipkin2.reporter.HttpEndpointSupplier.Factory;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.unit.DataSize;
|
||||
|
||||
/**
|
||||
@@ -60,20 +61,20 @@ abstract class HttpSender extends BaseHttpSender<URI, byte[]> {
|
||||
|
||||
@Override
|
||||
protected void postSpans(URI endpoint, byte[] body) throws IOException {
|
||||
HttpHeaders headers = getDefaultHeaders();
|
||||
MultiValueMap<String, String> headers = getDefaultHeaders();
|
||||
if (needsCompression(body)) {
|
||||
body = compress(body);
|
||||
headers.set("Content-Encoding", "gzip");
|
||||
headers.add("Content-Encoding", "gzip");
|
||||
}
|
||||
postSpans(endpoint, headers, body);
|
||||
}
|
||||
|
||||
abstract void postSpans(URI endpoint, HttpHeaders headers, byte[] body) throws IOException;
|
||||
abstract void postSpans(URI endpoint, MultiValueMap<String, String> headers, byte[] body) throws IOException;
|
||||
|
||||
HttpHeaders getDefaultHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("b3", "0");
|
||||
headers.set("Content-Type", this.encoding.mediaType());
|
||||
MultiValueMap<String, String> getDefaultHeaders() {
|
||||
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
|
||||
headers.add("b3", "0");
|
||||
headers.add("Content-Type", this.encoding.mediaType());
|
||||
return headers;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.time.Duration;
|
||||
import zipkin2.reporter.Encoding;
|
||||
import zipkin2.reporter.HttpEndpointSupplier.Factory;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* A {@link HttpSender} which uses the JDK {@link HttpClient} for HTTP communication.
|
||||
@@ -50,7 +50,7 @@ class ZipkinHttpClientSender extends HttpSender {
|
||||
}
|
||||
|
||||
@Override
|
||||
void postSpans(URI endpoint, HttpHeaders headers, byte[] body) throws IOException {
|
||||
void postSpans(URI endpoint, MultiValueMap<String, String> headers, byte[] body) throws IOException {
|
||||
Builder request = HttpRequest.newBuilder()
|
||||
.POST(BodyPublishers.ofByteArray(body))
|
||||
.uri(endpoint)
|
||||
|
||||
@@ -22,8 +22,8 @@ import zipkin2.reporter.Encoding;
|
||||
import zipkin2.reporter.HttpEndpointSupplier.Factory;
|
||||
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ class ZipkinRestTemplateSender extends HttpSender {
|
||||
}
|
||||
|
||||
@Override
|
||||
void postSpans(URI endpoint, HttpHeaders headers, byte[] body) {
|
||||
void postSpans(URI endpoint, MultiValueMap<String, String> headers, byte[] body) {
|
||||
HttpEntity<byte[]> request = new HttpEntity<>(body, headers);
|
||||
this.restTemplate.exchange(endpoint, HttpMethod.POST, request, Void.class);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.time.Duration;
|
||||
import zipkin2.reporter.Encoding;
|
||||
import zipkin2.reporter.HttpEndpointSupplier.Factory;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
@@ -47,7 +47,7 @@ class ZipkinWebClientSender extends HttpSender {
|
||||
}
|
||||
|
||||
@Override
|
||||
void postSpans(URI endpoint, HttpHeaders headers, byte[] body) {
|
||||
void postSpans(URI endpoint, MultiValueMap<String, String> headers, byte[] body) {
|
||||
this.webClient.post()
|
||||
.uri(endpoint)
|
||||
.headers((h) -> h.addAll(headers))
|
||||
|
||||
@@ -35,6 +35,8 @@ import zipkin2.reporter.Encoding;
|
||||
import zipkin2.reporter.HttpEndpointSupplier;
|
||||
import zipkin2.reporter.HttpEndpointSuppliers;
|
||||
|
||||
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||
@@ -44,6 +46,7 @@ import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
@ClassPathExclusions("spring-web-*.jar")
|
||||
class ZipkinHttpClientSenderTests extends ZipkinHttpSenderTests {
|
||||
|
||||
private MockWebServer mockBackEnd;
|
||||
|
||||
Reference in New Issue
Block a user