mirror of https://github.com/dapr/java-sdk.git
Removing OkHttp3 dependencies (#1313)
Signed-off-by: Artur Ciocanu <ciocanu@adobe.com> Co-authored-by: Artur Ciocanu <ciocanu@adobe.com>
This commit is contained in:
parent
ef1fc2242a
commit
128cfdeb4b
|
@ -111,12 +111,6 @@
|
|||
<version>${springboot.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.gmazzo.okhttp.mock</groupId>
|
||||
<artifactId>mock-client</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -88,18 +88,6 @@ dependencies {
|
|||
|
||||
{{< /tabs >}}
|
||||
|
||||
If you are also using Spring Boot, you may run into a common issue where the `OkHttp` version that the Dapr SDK uses conflicts with the one specified in the Spring Boot _Bill of Materials_.
|
||||
|
||||
You can fix this by specifying a compatible `OkHttp` version in your project to match the version that the Dapr SDK uses:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>1.14.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
## Try it out
|
||||
|
||||
Put the Dapr Java SDK to the test. Walk through the Java quickstarts and tutorials to see Dapr in action:
|
||||
|
|
|
@ -133,11 +133,6 @@
|
|||
<artifactId>protobuf-java</artifactId>
|
||||
<version>${protobuf.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.12.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -19,11 +19,11 @@ import com.evanlennick.retry4j.config.RetryConfig;
|
|||
import com.evanlennick.retry4j.config.RetryConfigBuilder;
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -34,7 +34,11 @@ import static java.time.temporal.ChronoUnit.SECONDS;
|
|||
*/
|
||||
final class Validation {
|
||||
|
||||
private static final OkHttpClient HTTP_CLIENT = new OkHttpClient();
|
||||
private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
.build();
|
||||
|
||||
private static final String TRACES_URL = "http://localhost:9411/api/v2/traces";
|
||||
|
||||
private static final RetryConfig RETRY_CONFIG = new RetryConfigBuilder()
|
||||
.withMaxNumberOfTries(5)
|
||||
|
@ -56,27 +60,16 @@ final class Validation {
|
|||
|
||||
static void validate() {
|
||||
Status<Void> result = new CallExecutorBuilder().config(RETRY_CONFIG).build().execute(() -> doValidate());
|
||||
|
||||
if (!result.wasSuccessful()) {
|
||||
throw new RuntimeException(result.getLastExceptionThatCausedRetry());
|
||||
}
|
||||
}
|
||||
|
||||
private static Void doValidate() throws Exception {
|
||||
System.out.println("Performing validation of tracing events ...");
|
||||
|
||||
HttpUrl.Builder urlBuilder = new HttpUrl.Builder();
|
||||
urlBuilder.scheme("http")
|
||||
.host("localhost")
|
||||
.port(9411);
|
||||
urlBuilder.addPathSegments("api/v2/traces");
|
||||
Request.Builder requestBuilder = new Request.Builder()
|
||||
.url(urlBuilder.build());
|
||||
requestBuilder.method("GET", null);
|
||||
|
||||
Request request = requestBuilder.build();
|
||||
|
||||
Response response = HTTP_CLIENT.newCall(request).execute();
|
||||
DocumentContext documentContext = JsonPath.parse(response.body().string());
|
||||
HttpRequest request = HttpRequest.newBuilder().GET().uri(URI.create(TRACES_URL)).build();
|
||||
HttpResponse<String> response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
DocumentContext documentContext = JsonPath.parse(response.body());
|
||||
String mainSpanId = readOne(documentContext, "$..[?(@.name == \"example's main\")]['id']").toString();
|
||||
|
||||
// Validate echo
|
||||
|
@ -104,13 +97,14 @@ final class Validation {
|
|||
.toString();
|
||||
readOne(documentContext,
|
||||
String.format(JSONPATH_SLEEP_SPAN_ID, proxySleepSpanId2));
|
||||
System.out.println("Validation of tracing events has succeeded.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Object readOne(DocumentContext documentContext, String path) {
|
||||
List<Map<String, Object>> arr = documentContext.read(path);
|
||||
if (arr.size() == 0) {
|
||||
|
||||
if (arr.isEmpty()) {
|
||||
throw new RuntimeException("No record found for " + path);
|
||||
}
|
||||
|
||||
|
@ -119,6 +113,7 @@ final class Validation {
|
|||
|
||||
private static void assertCount(DocumentContext documentContext, String path, int expectedCount) {
|
||||
List<Map<String, Object>> arr = documentContext.read(path);
|
||||
|
||||
if (arr.size() != expectedCount) {
|
||||
throw new RuntimeException(
|
||||
String.format("Unexpected count %d vs expected %d for %s", arr.size(), expectedCount, path));
|
||||
|
|
|
@ -31,12 +31,6 @@
|
|||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.gmazzo.okhttp.mock</groupId>
|
||||
<artifactId>mock-client</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
|
|
|
@ -71,12 +71,6 @@
|
|||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.gmazzo.okhttp.mock</groupId>
|
||||
<artifactId>mock-client</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -142,7 +142,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.zipkin.reporter2</groupId>
|
||||
<artifactId>zipkin-sender-okhttp3</artifactId>
|
||||
<artifactId>zipkin-sender-urlconnection</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -24,17 +24,18 @@ import io.dapr.config.Property;
|
|||
import io.dapr.v1.AppCallbackHealthCheckGrpc;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -231,23 +232,21 @@ public class DaprRun implements Stoppable {
|
|||
channel.shutdown();
|
||||
}
|
||||
} else {
|
||||
// Create an OkHttpClient instance with a custom timeout
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
.connectTimeout(maxWaitMilliseconds, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(maxWaitMilliseconds, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
Duration waitDuration = Duration.ofMillis(maxWaitMilliseconds);
|
||||
HttpClient client = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
.connectTimeout(waitDuration)
|
||||
.build();
|
||||
String url = "http://127.0.0.1:" + this.getAppPort() + "/health";
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(URI.create(url))
|
||||
.build();
|
||||
|
||||
// Define the URL to probe
|
||||
String url = "http://127.0.0.1:" + this.getAppPort() + "/health"; // Change to your specific URL
|
||||
try {
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
// Create a request to the URL
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.build();
|
||||
|
||||
// Execute the request
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
if (response.statusCode() != 200) {
|
||||
throw new RuntimeException("error: HTTP service is not healthy.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -21,9 +21,6 @@ import io.dapr.client.domain.State;
|
|||
|
||||
import io.dapr.config.Properties;
|
||||
import io.dapr.testcontainers.DaprContainer;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -34,6 +31,10 @@ import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
|
|||
import org.testcontainers.shaded.org.awaitility.core.ConditionTimeoutException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -51,7 +52,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.verify;
|
|||
import static io.dapr.it.testcontainers.ContainerConstants.DAPR_IMAGE_TAG;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
|
||||
|
@ -155,20 +155,21 @@ public class DaprContainerIT {
|
|||
|
||||
}
|
||||
|
||||
private String checkSidecarMetadata() throws IOException {
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||||
.build();
|
||||
Request request = new Request.Builder()
|
||||
.url(DAPR_CONTAINER.getHttpEndpoint() + "/v1.0/metadata")
|
||||
private String checkSidecarMetadata() throws IOException, InterruptedException {
|
||||
String url = DAPR_CONTAINER.getHttpEndpoint() + "/v1.0/metadata";
|
||||
HttpClient client = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
.build();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(url))
|
||||
.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
try (Response response = okHttpClient.newCall(request).execute()) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
return response.body().string();
|
||||
} else {
|
||||
throw new IOException("Unexpected response: " + response.code());
|
||||
}
|
||||
if (response.statusCode() != 200) {
|
||||
throw new IOException("Unexpected response: " + response.statusCode());
|
||||
}
|
||||
|
||||
return response.body();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,13 +16,14 @@ package io.dapr.it.tracing;
|
|||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import net.minidev.json.JSONArray;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Class used to verify that traces are present as expected.
|
||||
|
@ -31,7 +32,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
*/
|
||||
public final class Validation {
|
||||
|
||||
private static final OkHttpClient HTTP_CLIENT = new OkHttpClient();
|
||||
private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_1_1)
|
||||
.build();
|
||||
|
||||
private static final String TRACES_URL = "http://localhost:9411/api/v2/traces?limit=100";
|
||||
|
||||
/**
|
||||
* JSON Path for main span Id.
|
||||
|
@ -47,31 +52,28 @@ public final class Validation {
|
|||
public static void validate(String spanName, String sleepSpanName) throws Exception {
|
||||
// Must wait for some time to make sure Zipkin receives all spans.
|
||||
Thread.sleep(10000);
|
||||
HttpUrl.Builder urlBuilder = new HttpUrl.Builder();
|
||||
urlBuilder.scheme("http")
|
||||
.host("localhost")
|
||||
.port(9411)
|
||||
.addPathSegments("api/v2/traces")
|
||||
.addQueryParameter("limit", "100");
|
||||
Request.Builder requestBuilder = new Request.Builder()
|
||||
.url(urlBuilder.build());
|
||||
requestBuilder.method("GET", null);
|
||||
|
||||
Request request = requestBuilder.build();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(URI.create(TRACES_URL))
|
||||
.build();
|
||||
|
||||
Response response = HTTP_CLIENT.newCall(request).execute();
|
||||
DocumentContext documentContext = JsonPath.parse(response.body().string());
|
||||
HttpResponse<String> response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
DocumentContext documentContext = JsonPath.parse(response.body());
|
||||
String mainSpanId = readOne(documentContext, String.format(JSONPATH_MAIN_SPAN_ID, spanName)).toString();
|
||||
|
||||
assertNotNull(mainSpanId);
|
||||
|
||||
String sleepSpanId = readOne(documentContext, String.format(JSONPATH_SLEEP_SPAN_ID, mainSpanId, sleepSpanName))
|
||||
.toString();
|
||||
|
||||
assertNotNull(sleepSpanId);
|
||||
}
|
||||
|
||||
private static Object readOne(DocumentContext documentContext, String path) {
|
||||
JSONArray arr = documentContext.read(path);
|
||||
assertTrue(arr.size() > 0);
|
||||
|
||||
assertFalse(arr.isEmpty());
|
||||
|
||||
return arr.get(0);
|
||||
}
|
||||
|
|
|
@ -61,12 +61,6 @@
|
|||
<version>1.9.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.gmazzo.okhttp.mock</groupId>
|
||||
<artifactId>mock-client</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.stefanbirkner</groupId>
|
||||
<artifactId>system-rules</artifactId>
|
||||
|
|
Loading…
Reference in New Issue