Skip to content

Commit 1b9b757

Browse files
authored
feat: update code to v4.1.0 (#67)
1 parent 44bf03c commit 1b9b757

File tree

296 files changed

+6151
-4099
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

296 files changed

+6151
-4099
lines changed

code/src/main/kotlin/com/expediagroup/sdk/core/client/BaseRapidClient.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Expedia, Inc.
2+
* Copyright (C) 2022 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,15 +32,14 @@ import io.ktor.client.engine.HttpClientEngine
3232
abstract class BaseRapidClient(
3333
namespace: String,
3434
clientConfiguration: RapidClientConfiguration,
35-
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE,
35+
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE
3636
) : Client(namespace) {
3737
private val _configurationProvider: ConfigurationProvider =
3838
ConfigurationCollector.create(
3939
clientConfiguration.toProvider(),
40-
RapidConfigurationProvider,
40+
RapidConfigurationProvider
4141
)
42-
private val _httpClient: HttpClient =
43-
buildHttpClient(_configurationProvider, AuthenticationStrategy.AuthenticationType.SIGNATURE, httpClientEngine)
42+
private val _httpClient: HttpClient = buildHttpClient(_configurationProvider, AuthenticationStrategy.AuthenticationType.SIGNATURE, httpClientEngine)
4443

4544
init {
4645
finalize()

code/src/main/kotlin/com/expediagroup/sdk/core/client/Client.kt

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Expedia, Inc.
2+
* Copyright (C) 2022 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,7 +63,7 @@ val DEFAULT_HTTP_CLIENT_ENGINE: HttpClientEngine =
6363
*/
6464
abstract class Client(
6565
namespace: String,
66-
environmentProvider: EnvironmentProvider = DefaultEnvironmentProvider(namespace),
66+
environmentProvider: EnvironmentProvider = DefaultEnvironmentProvider(namespace)
6767
) : EnvironmentProvider by environmentProvider {
6868
private val httpHandler = DefaultHttpHandler(environmentProvider)
6969

@@ -80,7 +80,7 @@ abstract class Client(
8080
internal fun buildHttpClient(
8181
configurationProvider: ConfigurationProvider,
8282
authenticationType: AuthenticationStrategy.AuthenticationType,
83-
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE,
83+
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE
8484
): HttpClient =
8585
HttpClient(httpClientEngine) {
8686
val httpClientConfig = this
@@ -89,18 +89,9 @@ abstract class Client(
8989
val secret: String = configurationProvider.secret ?: fireMissingConfigurationIssue(ConfigurationName.SECRET)
9090
val endpoint: String = configurationProvider.endpoint ?: fireMissingConfigurationIssue(ConfigurationName.ENDPOINT)
9191
val authEndpoint: String = configurationProvider.authEndpoint ?: fireMissingConfigurationIssue(ConfigurationName.AUTH_ENDPOINT)
92-
val requestTimeout: Long =
93-
configurationProvider.requestTimeout ?: fireMissingConfigurationIssue(
94-
ConfigurationName.REQUEST_TIMEOUT_MILLIS,
95-
)
96-
val connectionTimeout: Long =
97-
configurationProvider.connectionTimeout ?: fireMissingConfigurationIssue(
98-
ConfigurationName.CONNECTION_TIMEOUT_MILLIS,
99-
)
100-
val socketTimeout: Long =
101-
configurationProvider.socketTimeout ?: fireMissingConfigurationIssue(
102-
ConfigurationName.SOCKET_TIMEOUT_MILLIS,
103-
)
92+
val requestTimeout: Long = configurationProvider.requestTimeout ?: fireMissingConfigurationIssue(ConfigurationName.REQUEST_TIMEOUT_MILLIS)
93+
val connectionTimeout: Long = configurationProvider.connectionTimeout ?: fireMissingConfigurationIssue(ConfigurationName.CONNECTION_TIMEOUT_MILLIS)
94+
val socketTimeout: Long = configurationProvider.socketTimeout ?: fireMissingConfigurationIssue(ConfigurationName.SOCKET_TIMEOUT_MILLIS)
10495
val maskedLoggingHeaders: Set<String> = configurationProvider.maskedLoggingHeaders ?: setOf()
10596
val maskedLoggingBodyFields: Set<String> = configurationProvider.maskedLoggingBodyFields ?: setOf()
10697

@@ -109,7 +100,7 @@ abstract class Client(
109100
httpClientConfig,
110101
Credentials.from(key, secret),
111102
authEndpoint,
112-
authenticationType,
103+
authenticationType
113104
)
114105

115106
plugins {
@@ -118,9 +109,7 @@ abstract class Client(
118109
use(AuthenticationPlugin).with(authenticationConfiguration)
119110
use(DefaultRequestPlugin).with(DefaultRequestConfiguration.from(httpClientConfig, endpoint))
120111
use(EncodingPlugin).with(EncodingConfiguration.from(httpClientConfig))
121-
use(
122-
HttpTimeoutPlugin,
123-
).with(HttpTimeoutConfiguration.from(httpClientConfig, requestTimeout, connectionTimeout, socketTimeout))
112+
use(HttpTimeoutPlugin).with(HttpTimeoutConfiguration.from(httpClientConfig, requestTimeout, connectionTimeout, socketTimeout))
124113
use(ExceptionHandlingPlugin).with(ExceptionHandlingConfiguration.from(httpClientConfig))
125114
}
126115

@@ -130,8 +119,7 @@ abstract class Client(
130119
}
131120

132121
/** Throw an exception if the configuration is missing. */
133-
private fun fireMissingConfigurationIssue(configurationKey: String): Nothing =
134-
throw ExpediaGroupConfigurationException(getMissingRequiredConfigurationMessage(configurationKey))
122+
private fun fireMissingConfigurationIssue(configurationKey: String): Nothing = throw ExpediaGroupConfigurationException(getMissingRequiredConfigurationMessage(configurationKey))
135123

136124
private fun isNotSuccessfulResponse(response: HttpResponse) = response.status.value !in Constant.SUCCESSFUL_STATUS_CODES_RANGE
137125

@@ -145,7 +133,7 @@ abstract class Client(
145133

146134
abstract suspend fun throwServiceException(
147135
response: HttpResponse,
148-
operationId: String,
136+
operationId: String
149137
)
150138

151139
suspend fun performGet(url: String): HttpResponse = httpHandler.performGet(httpClient, url)
@@ -237,12 +225,7 @@ abstract class Client(
237225
*/
238226
fun requestTimeout(milliseconds: Long): SELF {
239227
this.requestTimeout = milliseconds
240-
log.info(
241-
LoggingMessageProvider.getRuntimeConfigurationProviderMessage(
242-
ConfigurationName.REQUEST_TIMEOUT_MILLIS,
243-
milliseconds.toString(),
244-
),
245-
)
228+
log.info(LoggingMessageProvider.getRuntimeConfigurationProviderMessage(ConfigurationName.REQUEST_TIMEOUT_MILLIS, milliseconds.toString()))
246229
return self()
247230
}
248231

@@ -256,12 +239,7 @@ abstract class Client(
256239
*/
257240
fun connectionTimeout(milliseconds: Long): SELF {
258241
this.connectionTimeout = milliseconds
259-
log.info(
260-
LoggingMessageProvider.getRuntimeConfigurationProviderMessage(
261-
ConfigurationName.CONNECTION_TIMEOUT_MILLIS,
262-
milliseconds.toString(),
263-
),
264-
)
242+
log.info(LoggingMessageProvider.getRuntimeConfigurationProviderMessage(ConfigurationName.CONNECTION_TIMEOUT_MILLIS, milliseconds.toString()))
265243
return self()
266244
}
267245

@@ -275,12 +253,7 @@ abstract class Client(
275253
*/
276254
fun socketTimeout(milliseconds: Long): SELF {
277255
this.socketTimeout = milliseconds
278-
log.info(
279-
LoggingMessageProvider.getRuntimeConfigurationProviderMessage(
280-
ConfigurationName.SOCKET_TIMEOUT_MILLIS,
281-
milliseconds.toString(),
282-
),
283-
)
256+
log.info(LoggingMessageProvider.getRuntimeConfigurationProviderMessage(ConfigurationName.SOCKET_TIMEOUT_MILLIS, milliseconds.toString()))
284257
return self()
285258
}
286259

@@ -292,12 +265,7 @@ abstract class Client(
292265
*/
293266
fun maskedLoggingHeaders(vararg headers: String): SELF {
294267
this.maskedLoggingHeaders = headers.toSet()
295-
log.info(
296-
LoggingMessageProvider.getRuntimeConfigurationProviderMessage(
297-
ConfigurationName.MASKED_LOGGING_HEADERS,
298-
headers.joinToString(),
299-
),
300-
)
268+
log.info(LoggingMessageProvider.getRuntimeConfigurationProviderMessage(ConfigurationName.MASKED_LOGGING_HEADERS, headers.joinToString()))
301269
return self()
302270
}
303271

@@ -309,12 +277,7 @@ abstract class Client(
309277
*/
310278
fun maskedLoggingBodyFields(vararg fields: String): SELF {
311279
this.maskedLoggingBodyFields = fields.toSet()
312-
log.info(
313-
LoggingMessageProvider.getRuntimeConfigurationProviderMessage(
314-
ConfigurationName.MASKED_LOGGING_BODY_FIELDS,
315-
fields.joinToString(),
316-
),
317-
)
280+
log.info(LoggingMessageProvider.getRuntimeConfigurationProviderMessage(ConfigurationName.MASKED_LOGGING_BODY_FIELDS, fields.joinToString()))
318281
return self()
319282
}
320283

code/src/main/kotlin/com/expediagroup/sdk/core/client/ClientHelpers.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Expedia, Inc.
2+
* Copyright (C) 2022 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,5 +17,5 @@ package com.expediagroup.sdk.core.client
1717

1818
/** Handy utils and helpers for a client. */
1919
abstract class ClientHelpers(
20-
val client: Client,
20+
val client: Client
2121
)

code/src/main/kotlin/com/expediagroup/sdk/core/client/Environment.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Expedia, Inc.
2+
* Copyright (C) 2022 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,16 +17,16 @@ package com.expediagroup.sdk.core.client
1717

1818
import com.expediagroup.sdk.core.constant.HeaderKey
1919
import com.expediagroup.sdk.core.model.Properties
20+
import com.expediagroup.sdk.core.model.TransactionId
2021
import io.ktor.client.request.HttpRequestBuilder
2122
import io.ktor.http.HttpHeaders
22-
import java.util.UUID
2323

2424
interface EnvironmentProvider {
25-
fun HttpRequestBuilder.appendHeaders()
25+
fun HttpRequestBuilder.appendHeaders(transactionId: TransactionId = TransactionId())
2626
}
2727

2828
class DefaultEnvironmentProvider(
29-
namespace: String,
29+
namespace: String
3030
) : EnvironmentProvider {
3131
private val properties = Properties.from(javaClass.classLoader.getResource("sdk.properties")!!)
3232
private val javaVersion = System.getProperty("java.version")
@@ -35,11 +35,11 @@ class DefaultEnvironmentProvider(
3535
private val userAgent = "expediagroup-sdk-java-$namespace/${properties["sdk-version"]!!} (Java $javaVersion; $operatingSystemName $operatingSystemVersion)"
3636

3737
@Suppress("MemberVisibilityCanBePrivate")
38-
override fun HttpRequestBuilder.appendHeaders() {
38+
override fun HttpRequestBuilder.appendHeaders(transactionId: TransactionId) {
3939
with(headers) {
4040
append(HttpHeaders.UserAgent, userAgent)
4141
append(HeaderKey.X_SDK_TITLE, properties["sdk-title"]!!)
42-
append(HeaderKey.TRANSACTION_ID, UUID.randomUUID().toString())
42+
append(HeaderKey.TRANSACTION_ID, transactionId.dequeue().toString())
4343
}
4444
}
4545
}

code/src/main/kotlin/com/expediagroup/sdk/core/client/ExpediaGroupClient.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Expedia, Inc.
2+
* Copyright (C) 2022 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,15 +32,14 @@ import io.ktor.client.engine.HttpClientEngine
3232
abstract class ExpediaGroupClient(
3333
namespace: String,
3434
clientConfiguration: ExpediaGroupClientConfiguration,
35-
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE,
35+
httpClientEngine: HttpClientEngine = DEFAULT_HTTP_CLIENT_ENGINE
3636
) : Client(namespace) {
3737
private val _configurationProvider: ConfigurationProvider =
3838
ConfigurationCollector.create(
3939
clientConfiguration.toProvider(),
40-
ExpediaGroupConfigurationProvider,
40+
ExpediaGroupConfigurationProvider
4141
)
42-
private val _httpClient: HttpClient =
43-
buildHttpClient(_configurationProvider, AuthenticationStrategy.AuthenticationType.BEARER, httpClientEngine)
42+
private val _httpClient: HttpClient = buildHttpClient(_configurationProvider, AuthenticationStrategy.AuthenticationType.BEARER, httpClientEngine)
4443

4544
init {
4645
finalize()

code/src/main/kotlin/com/expediagroup/sdk/core/client/HttpHandler.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 Expedia, Inc.
2+
* Copyright (C) 2022 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,16 +24,16 @@ import io.ktor.http.HttpMethod
2424
internal interface HttpHandler {
2525
suspend fun performGet(
2626
httpClient: HttpClient,
27-
link: String,
27+
link: String
2828
): HttpResponse
2929
}
3030

3131
internal class DefaultHttpHandler(
32-
private val environmentProvider: EnvironmentProvider,
32+
private val environmentProvider: EnvironmentProvider
3333
) : HttpHandler, EnvironmentProvider by environmentProvider {
3434
override suspend fun performGet(
3535
httpClient: HttpClient,
36-
link: String,
36+
link: String
3737
): HttpResponse {
3838
return httpClient.request {
3939
method = HttpMethod.Get

0 commit comments

Comments
 (0)