Skip to content

Commit

Permalink
fix: remove transaction-id parameter from client methods (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
osama-salman99 authored Feb 20, 2024
1 parent e48132f commit 73d2a2b
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import io.ktor.http.HttpHeaders
import java.util.UUID

interface EnvironmentProvider {
fun HttpRequestBuilder.appendHeaders(transactionId: UUID)
fun HttpRequestBuilder.appendHeaders()
}

class DefaultEnvironmentProvider(
Expand All @@ -35,11 +35,11 @@ class DefaultEnvironmentProvider(
private val userAgent = "expediagroup-sdk-java-$namespace/${properties["sdk-version"]!!} (Java $javaVersion; $operatingSystemName $operatingSystemVersion)"

@Suppress("MemberVisibilityCanBePrivate")
override fun HttpRequestBuilder.appendHeaders(transactionId: UUID) {
override fun HttpRequestBuilder.appendHeaders() {
with(headers) {
append(HttpHeaders.UserAgent, userAgent)
append(HeaderKey.X_SDK_TITLE, properties["sdk-title"]!!)
append(HeaderKey.TRANSACTION_ID, transactionId.toString())
append(HeaderKey.TRANSACTION_ID, UUID.randomUUID().toString())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import io.ktor.client.request.request
import io.ktor.client.request.url
import io.ktor.client.statement.HttpResponse
import io.ktor.http.HttpMethod
import java.util.UUID

internal interface HttpHandler {
suspend fun performGet(
Expand All @@ -39,7 +38,7 @@ internal class DefaultHttpHandler(
return httpClient.request {
method = HttpMethod.Get
url(link)
appendHeaders(UUID.randomUUID())
appendHeaders()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import io.ktor.http.clone
import io.ktor.http.contentType
import kotlinx.coroutines.runBlocking
import java.time.LocalDateTime
import java.util.UUID

internal class ExpediaGroupAuthenticationStrategy(
private val client: Client,
Expand Down Expand Up @@ -75,7 +74,7 @@ internal class ExpediaGroupAuthenticationStrategy(
contentType(ContentType.Application.FormUrlEncoded)
url(configs.authUrl)
basicAuth(configs.credentials)
with(client) { appendHeaders(UUID.randomUUID()) }
with(client) { appendHeaders() }
}
}
if (renewTokenResponse.status.value !in Constant.SUCCESSFUL_STATUS_CODES_RANGE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package com.expediagroup.sdk.core.client

import com.expediagroup.sdk.core.constant.HeaderKey.TRANSACTION_ID
import io.ktor.client.request.HttpRequestBuilder
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test

Expand All @@ -35,11 +37,10 @@ class DefaultEnvironmentProviderTest {
@Test
fun `Verify headers are appended`() {
environmentProvider.apply {
val transactionId = java.util.UUID.randomUUID()
httpRequestBuilder.appendHeaders(transactionId)
httpRequestBuilder.appendHeaders()

assertEquals("dummy-title", httpRequestBuilder.headers["x-sdk-title"])
assertEquals(transactionId.toString(), httpRequestBuilder.headers["transaction-id"])
assertTrue(httpRequestBuilder.headers.contains(TRANSACTION_ID))
assertEquals("expediagroup-sdk-java-dummy/dummy-version (Java $javaVersion; $operatingSystemName $operatingSystemVersion)", httpRequestBuilder.headers["User-agent"])
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#allParams}}{{>client/apiParam}}, {{/allParams}}transactionId: UUID = UUID.randomUUID()
{{#allParams}}{{>client/apiParam}}{{^-last}}, {{/-last}}{{/allParams}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#allParams}}{{{paramName}}}, {{/allParams}}transactionId
{{#allParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/allParams}}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {{import}}
val response = httpClient.request {
method = HttpMethod.parse("{{httpMethod}}")
url("{{#removeLeadingSlash}}{{path}}{{/removeLeadingSlash}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", {{#isContainer}}{{paramName}}.joinToString(","){{/isContainer}}{{^isContainer}}"${{{paramName}}}"{{/isContainer}}){{/pathParams}})
appendHeaders(transactionId)
appendHeaders()
{{#headerParams}}
{{paramName}}{{^required}}?{{/required}}.also{ headers.append("{{baseName}}", it) }
{{/headerParams}}
Expand Down Expand Up @@ -81,7 +81,6 @@ import {{import}}
* {{{notes}}}
{{#allParams}} * @param {{{paramName}}} {{{description}}}{{^required}} (optional{{#defaultValue}}, defaults to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (defaults to {{{.}}}){{/defaultValue}}{{/required}}
{{/allParams}}
* @param transactionId The transaction id for the request (optional, defaults to a new UUID)
{{#throwsExceptions}}{{/throwsExceptions}}
* @return {{{returnType}}}{{^returnType}}Nothing{{/returnType}}
*/
Expand All @@ -98,7 +97,6 @@ import {{import}}
* {{{notes}}}
{{#allParams}} * @param {{{paramName}}} {{{description}}}{{^required}} (optional{{#defaultValue}}, defaults to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (defaults to {{{.}}}){{/defaultValue}}{{/required}}
{{/allParams}}
* @param transactionId The transaction id for the request (optional, defaults to a new UUID)
{{#throwsExceptions}}{{/throwsExceptions}}
* @return a [Response] object with a body of type {{{returnType}}}{{^returnType}}Nothing{{/returnType}}
*/
Expand Down

0 comments on commit 73d2a2b

Please sign in to comment.