Skip to content

Commit

Permalink
Remove spring-web dependency from ZipkinHttpClientSender
Browse files Browse the repository at this point in the history
Closes gh-42161
  • Loading branch information
mhalbritter committed Sep 6, 2024
1 parent 92ed9ef commit 1679a72
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
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;

/**
Expand Down Expand Up @@ -60,20 +61,20 @@ protected byte[] newBody(List<byte[]> list) {

@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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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.
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
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;

/**
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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;

/**
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
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;
Expand All @@ -44,6 +46,7 @@
*
* @author Moritz Halbritter
*/
@ClassPathExclusions("spring-web-*.jar")
class ZipkinHttpClientSenderTests extends ZipkinHttpSenderTests {

private MockWebServer mockBackEnd;
Expand Down

0 comments on commit 1679a72

Please sign in to comment.