From 7f1ea2a557de7bf3a10f56003fc24d22f0ff6b9f Mon Sep 17 00:00:00 2001 From: Simon Schneider <10846939+raynigon@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:34:15 +0100 Subject: [PATCH] Remove OkHttp Module --- ecs-logging-okhttp3/build.gradle | 11 --- .../okhttp3/EcsTransactionIdInterceptor.java | 33 --------- .../EcsTransactionIdInterceptorSpec.groovy | 67 ------------------- settings.gradle | 1 - 4 files changed, 112 deletions(-) delete mode 100644 ecs-logging-okhttp3/build.gradle delete mode 100644 ecs-logging-okhttp3/src/main/java/com/raynigon/ecs/logging/okhttp3/EcsTransactionIdInterceptor.java delete mode 100644 ecs-logging-okhttp3/src/test/groovy/com/raynigon/ecs/logging/okhttp3/EcsTransactionIdInterceptorSpec.groovy diff --git a/ecs-logging-okhttp3/build.gradle b/ecs-logging-okhttp3/build.gradle deleted file mode 100644 index 53bc9f0..0000000 --- a/ecs-logging-okhttp3/build.gradle +++ /dev/null @@ -1,11 +0,0 @@ -dependencies { - api(project(':ecs-logging-base')) - api("org.slf4j:slf4j-api:2.0.16") - compileOnly("com.squareup.okhttp3:okhttp:4.12.0") - compileOnly("ch.qos.logback:logback-core") - - testImplementation("ch.qos.logback:logback-core") - testImplementation("ch.qos.logback:logback-classic") - testImplementation("com.squareup.okhttp3:okhttp:4.12.0") - testImplementation("org.springframework.boot:spring-boot-starter-test") -} diff --git a/ecs-logging-okhttp3/src/main/java/com/raynigon/ecs/logging/okhttp3/EcsTransactionIdInterceptor.java b/ecs-logging-okhttp3/src/main/java/com/raynigon/ecs/logging/okhttp3/EcsTransactionIdInterceptor.java deleted file mode 100644 index 06f3b5b..0000000 --- a/ecs-logging-okhttp3/src/main/java/com/raynigon/ecs/logging/okhttp3/EcsTransactionIdInterceptor.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.raynigon.ecs.logging.okhttp3; - -import okhttp3.Interceptor; -import okhttp3.Request; -import okhttp3.Response; -import org.jetbrains.annotations.NotNull; -import org.slf4j.MDC; - -import java.io.IOException; -import java.util.UUID; - -import static com.raynigon.ecs.logging.LoggingConstants.TRANSACTION_ID_HEADER; -import static com.raynigon.ecs.logging.LoggingConstants.TRANSACTION_ID_PROPERTY; - -public class EcsTransactionIdInterceptor implements Interceptor { - - @NotNull - @Override - public Response intercept(Interceptor.Chain chain) throws IOException { - Request original = chain.request(); - String transactionId = MDC.get(TRANSACTION_ID_PROPERTY); - // If no transaction id exists, generate custom transaction id - if (transactionId == null) { - transactionId = UUID.randomUUID().toString(); - MDC.put(TRANSACTION_ID_PROPERTY, transactionId); - } - // Update Request with transaction id header - Request updated = original.newBuilder() - .header(TRANSACTION_ID_HEADER, transactionId) - .build(); - return chain.proceed(updated); - } -} \ No newline at end of file diff --git a/ecs-logging-okhttp3/src/test/groovy/com/raynigon/ecs/logging/okhttp3/EcsTransactionIdInterceptorSpec.groovy b/ecs-logging-okhttp3/src/test/groovy/com/raynigon/ecs/logging/okhttp3/EcsTransactionIdInterceptorSpec.groovy deleted file mode 100644 index 085ae40..0000000 --- a/ecs-logging-okhttp3/src/test/groovy/com/raynigon/ecs/logging/okhttp3/EcsTransactionIdInterceptorSpec.groovy +++ /dev/null @@ -1,67 +0,0 @@ -package com.raynigon.ecs.logging.okhttp3 - -import static com.raynigon.ecs.logging.LoggingConstants.TRANSACTION_ID_HEADER -import static com.raynigon.ecs.logging.LoggingConstants.TRANSACTION_ID_PROPERTY - -import okhttp3.Protocol -import okhttp3.Request -import okhttp3.Response -import org.slf4j.MDC -import spock.lang.Specification -import spock.lang.Subject -import okhttp3.Interceptor - -class EcsTransactionIdInterceptorSpec extends Specification { - - @Subject - EcsTransactionIdInterceptor interceptor = new EcsTransactionIdInterceptor() - - def "transaction id header exists"() { - given: - Interceptor.Chain chain = Mock() - Request request = new Request.Builder().url("https://example.com").build() - Response response = new Response.Builder().request(request).code(200) - .protocol(Protocol.HTTP_1_1) - .message("dummy") - .build() - - when: - def result = interceptor.intercept(chain) - - then: - 1 * chain.request() >> request - 1 * chain.proceed({ Request r -> r.header(TRANSACTION_ID_HEADER) != null }) >> response - - and: - result == response - - cleanup: - MDC.clear() - } - - def "transaction id header is set from MDC Tag"() { - given: - Interceptor.Chain chain = Mock() - Request request = new Request.Builder().url("https://example.com").build() - Response response = new Response.Builder().request(request).code(200) - .protocol(Protocol.HTTP_1_1) - .message("dummy") - .build() - - and: - MDC.put(TRANSACTION_ID_PROPERTY, "my-value") - - when: - def result = interceptor.intercept(chain) - - then: - 1 * chain.request() >> request - 1 * chain.proceed({ Request r -> r.header(TRANSACTION_ID_HEADER) == "my-value" }) >> response - - and: - result == response - - cleanup: - MDC.clear() - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 299611d..67ed8f5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,5 +6,4 @@ include 'ecs-logging-access' include 'ecs-logging-async' include 'ecs-logging-audit' include 'ecs-logging-kafka' -include 'ecs-logging-okhttp3' include 'gzip-request-filter-starter' \ No newline at end of file