Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Publish v5.3.2-SNAPSHOT #272

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<dependency>
<groupId>com.expediagroup</groupId>
<artifactId>rapid-sdk</artifactId>
<version>5.3.1</version>
<version>5.3.2-SNAPSHOT</version>
</dependency>
```

Expand Down
21 changes: 11 additions & 10 deletions code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.expediagroup</groupId>
<artifactId>rapid-sdk</artifactId>
<version>5.3.1</version>
<version>5.3.2-SNAPSHOT</version>
<name>EG rapid-sdk for Java</name>
<description>EG rapid-sdk v5.3.1</description>
<description>EG rapid-sdk v5.3.2-SNAPSHOT</description>
<url>https://github.com/ExpediaGroup/test-sdk</url>
<inceptionYear>2022</inceptionYear>
<packaging>jar</packaging>
Expand Down Expand Up @@ -74,15 +74,15 @@
<build-helper-maven-plugin.version>3.6.0</build-helper-maven-plugin.version>
<ktlint-plugin.version>3.4.0</ktlint-plugin.version>
<jacoco-plugin.version>0.8.12</jacoco-plugin.version>
<dokka-plugin.version>1.9.20</dokka-plugin.version>
<dokka-plugin.version>2.0.0</dokka-plugin.version>
<dokka-old-versions.location/> <!-- passed as a property when running dokka:dokka-->
<properties.maven.plugin.version>1.2.1</properties.maven.plugin.version>
<maven.licence.plugin.version>4.6</maven.licence.plugin.version>
<flatten.maven.plugin.version>1.6.0</flatten.maven.plugin.version>
<kotlin.version>2.0.21</kotlin.version>
<kotlinx.coroutines.version>1.9.0</kotlinx.coroutines.version>
<ktor.version>2.3.13</ktor.version>
<kotlin-atomic.version>0.26.1</kotlin-atomic.version>
<kotlin.version>2.1.0</kotlin.version>
<kotlinx.coroutines.version>1.10.1</kotlinx.coroutines.version>
<ktor.version>3.0.3</ktor.version>
<kotlin-atomic.version>0.27.0</kotlin-atomic.version>
<slf4j.version>2.0.16</slf4j.version>
<maven.nexus-staging.plugin.version>1.7.0</maven.nexus-staging.plugin.version>
<maven.gpg.plugin.version>3.2.7</maven.gpg.plugin.version>
Expand Down Expand Up @@ -138,7 +138,7 @@
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio-jvm</artifactId>
<version>3.9.1</version>
<version>3.10.2</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
Expand Down Expand Up @@ -449,6 +449,7 @@
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>${dokka-plugin.version}</version>
<configuration>
<sourceDirectories>
<dir>${project.basedir}/src/main/kotlin/com/expediagroup/sdk/rapid</dir>
Expand Down Expand Up @@ -732,13 +733,13 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
<version>3.17.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.12.0</version>
<version>1.13.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import okhttp3.Dispatcher
import okhttp3.OkHttpClient

// Create a Dispatcher with limits
val dispatcher =
val configuredDispatcher =
Dispatcher().apply {
maxRequests = 10000 // Maximum number of concurrent requests
maxRequestsPerHost = 1000
Expand All @@ -64,7 +64,7 @@ val DEFAULT_HTTP_CLIENT_ENGINE: HttpClientEngine =
OkHttp.create {
config {
eventListenerFactory(OkHttpEventListener.FACTORY)
dispatcher(dispatcher)
dispatcher(configuredDispatcher)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,20 @@ abstract class ExpediaGroupClient(
return self()
}
}

@Suppress("unused", "UnnecessaryAbstractClass") // This is used by the generated SDK clients.
abstract class BuilderWithHttpClient<SELF : Client.BuilderWithHttpClient<SELF>> : Client.BuilderWithHttpClient<SELF>() {
/** Sets the API auth endpoint to use for requests. */
protected var authEndpoint: String? = null

/** Sets the API auth endpoint to use for requests.
*
* @param authEndpoint The API auth endpoint to use for requests.
* @return The [Builder] instance.
*/
fun authEndpoint(authEndpoint: String): SELF {
this.authEndpoint = authEndpoint
return self()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
*/
package com.expediagroup.sdk.core.configuration.provider

import com.expediagroup.sdk.core.configuration.provider.RapidConfigurationProvider.connectionTimeout
import com.expediagroup.sdk.core.configuration.provider.RapidConfigurationProvider.endpoint
import com.expediagroup.sdk.core.configuration.provider.RapidConfigurationProvider.name
import com.expediagroup.sdk.core.configuration.provider.RapidConfigurationProvider.requestTimeout
import com.expediagroup.sdk.core.configuration.provider.RapidConfigurationProvider.socketTimeout
import com.expediagroup.sdk.core.constant.Constant

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package com.expediagroup.sdk.core.constant

import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.HttpTimeoutConfig

internal object Constant {
const val EMPTY_STRING = ""
const val TEN_SECONDS_IN_MILLIS = 10_000L
const val FIFTEEN_SECONDS_IN_MILLIS = 15_000L
const val INFINITE_TIMEOUT = HttpTimeout.INFINITE_TIMEOUT_MS
const val INFINITE_TIMEOUT = HttpTimeoutConfig.INFINITE_TIMEOUT_MS

private const val SUCCESSFUL_STATUS_CODES_RANGE_START = 200
private const val SUCCESSFUL_STATUS_CODES_RANGE_END = 299
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ internal object LoggingMessage {
const val TOKEN_EXPIRED = "Token expired or is about to expire. Request will wait until token is renewed"

const val OMITTED = "<-- omitted -->"

const val LOG_LIMIT = 4094

const val TRUNCATED = "<-- truncated -->"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import io.ktor.client.statement.HttpResponse
sealed class BasePaginator<R, T>(
private val client: Client,
firstResponse: Response<T>,
private val fallbackBody: T,
private val getBody: suspend (HttpResponse) -> T
) : Iterator<R> {
private var state: ResponseState<T> = DefaultResponseState(firstResponse)
Expand All @@ -41,7 +40,7 @@ sealed class BasePaginator<R, T>(

protected fun nextResponse(): Response<T> {
val response = state.getNextResponse()
state = ResponseStateFactory.getState(extractLink(response.headers), client, fallbackBody, getBody)
state = ResponseStateFactory.getState(extractLink(response.headers), client, getBody)
return response
}
}
Expand All @@ -56,9 +55,8 @@ sealed class BasePaginator<R, T>(
class Paginator<T>(
client: Client,
firstResponse: Response<T>,
fallbackBody: T,
getBody: suspend (HttpResponse) -> T
) : BasePaginator<T, T>(client, firstResponse, fallbackBody, getBody) {
) : BasePaginator<T, T>(client, firstResponse, getBody) {
/**
* Returns the body of the next response.
*
Expand All @@ -77,9 +75,8 @@ class Paginator<T>(
class ResponsePaginator<T>(
client: Client,
firstResponse: Response<T>,
fallbackBody: T,
getBody: suspend (HttpResponse) -> T
) : BasePaginator<Response<T>, T>(client, firstResponse, fallbackBody, getBody) {
) : BasePaginator<Response<T>, T>(client, firstResponse, getBody) {
/**
* Returns the next response.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,9 @@
package com.expediagroup.sdk.core.model.paging

import com.expediagroup.sdk.core.client.Client
import com.expediagroup.sdk.core.constant.HeaderValue
import com.expediagroup.sdk.core.model.Response
import com.expediagroup.sdk.core.plugin.logging.GZipEncoder.decode
import com.expediagroup.sdk.core.plugin.logging.contentEncoding
import io.ktor.client.statement.HttpResponse
import io.ktor.util.InternalAPI
import io.ktor.util.moveToByteArray
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.bits.Memory
import kotlinx.coroutines.runBlocking
import java.nio.ByteBuffer

internal interface ResponseState<T> {
fun getNextResponse(): Response<T>
Expand All @@ -51,7 +43,6 @@ internal class LastResponseState<T> : ResponseState<T> {
internal class FetchLinkState<T>(
private val link: String,
private val client: Client,
private val fallbackBody: T,
private val getBody: suspend (HttpResponse) -> T
) : ResponseState<T> {
override fun getNextResponse(): Response<T> =
Expand All @@ -63,32 +54,15 @@ internal class FetchLinkState<T>(

override fun hasNext(): Boolean = true

private suspend fun parseBody(response: HttpResponse): T = if (decodeBody(response).isEmpty()) fallbackBody else getBody(response)

private suspend fun decodeBody(response: HttpResponse): String {
val byteReadChannel = prepareByteReadChannel(response)
val decodedByteReadChannel = if (response.contentEncoding().equals(HeaderValue.GZIP)) client.httpClient.decode(byteReadChannel) else byteReadChannel
val bodyString: String = decodedByteReadChannel.readRemaining().readText()
return bodyString
}

@OptIn(InternalAPI::class)
private suspend fun prepareByteReadChannel(response: HttpResponse): ByteReadChannel {
val bufferSize = response.content.availableForRead
val buffer = ByteBuffer.allocate(bufferSize)
val numberOfBytesRead = response.content.peekTo(Memory(buffer), 0, 0, 0, bufferSize.toLong()).toInt()
val byteReadChannel = ByteReadChannel(buffer.moveToByteArray(), 0, numberOfBytesRead)
return byteReadChannel
}
private suspend fun parseBody(response: HttpResponse): T = getBody(response)
}

internal class ResponseStateFactory {
companion object {
fun <T> getState(
link: String?,
client: Client,
fallbackBody: T,
getBody: suspend (HttpResponse) -> T
): ResponseState<T> = link?.let { FetchLinkState(it, client, fallbackBody, getBody) } ?: LastResponseState()
): ResponseState<T> = link?.let { FetchLinkState(it, client, getBody) } ?: LastResponseState()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import com.expediagroup.sdk.core.plugin.authentication.AuthenticationConfigurati
import com.expediagroup.sdk.core.plugin.authentication.strategy.AuthenticationStrategy.AuthenticationType.BASIC
import com.expediagroup.sdk.core.plugin.authentication.strategy.AuthenticationStrategy.AuthenticationType.BEARER
import com.expediagroup.sdk.core.plugin.authentication.strategy.AuthenticationStrategy.AuthenticationType.SIGNATURE
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.AuthConfig
import io.ktor.client.request.HttpRequestBuilder

internal interface AuthenticationStrategy {
fun loadAuth(auth: Auth) {}
fun loadAuth(auth: AuthConfig) {}

fun isTokenAboutToExpire(): Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
package com.expediagroup.sdk.core.plugin.authentication.strategy

import com.expediagroup.sdk.core.plugin.authentication.AuthenticationConfiguration
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.AuthConfig
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
import io.ktor.client.plugins.auth.providers.basic
import io.ktor.client.request.HttpRequestBuilder

internal class BasicAuthenticationStrategy(
private val configs: AuthenticationConfiguration
) : AuthenticationStrategy {
override fun loadAuth(auth: Auth) {
auth.basic {
override fun loadAuth(authConfig: AuthConfig) {
authConfig.basic {
sendWithoutRequest { true }
credentials {
BasicAuthCredentials(username = configs.credentials.key, password = configs.credentials.secret)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import com.expediagroup.sdk.core.plugin.authentication.AuthenticationConfigurati
import com.expediagroup.sdk.core.plugin.logging.ExpediaGroupLoggerFactory
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.AuthConfig
import io.ktor.client.plugins.auth.authProviders
import io.ktor.client.plugins.auth.providers.BearerAuthProvider
import io.ktor.client.plugins.auth.providers.BearerTokens
import io.ktor.client.plugins.auth.providers.bearer
import io.ktor.client.plugins.plugin
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.basicAuth
import io.ktor.client.request.parameter
Expand All @@ -53,8 +53,8 @@ internal class ExpediaGroupAuthenticationStrategy(
private val log = ExpediaGroupLoggerFactory.getLogger(javaClass)
private var bearerTokenStorage = BearerTokensInfo.emptyBearerTokenInfo

override fun loadAuth(auth: Auth) {
auth.bearer {
override fun loadAuth(authConfig: AuthConfig) {
authConfig.bearer {
sendWithoutRequest { request ->
isIdentityRequest(request)
}
Expand Down Expand Up @@ -94,7 +94,7 @@ internal class ExpediaGroupAuthenticationStrategy(

private fun clearTokens(client: HttpClient) {
log.info(LoggingMessage.TOKEN_CLEARING_IN_PROGRESS)
client.plugin(Auth).providers.filterIsInstance<BearerAuthProvider>().first().clearToken()
client.authProviders.filterIsInstance<BearerAuthProvider>().first().clearToken()
bearerTokenStorage = BearerTokensInfo.emptyBearerTokenInfo
log.info(LoggingMessage.TOKEN_CLEARING_SUCCESSFUL)
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package com.expediagroup.sdk.core.plugin.logging
import com.expediagroup.sdk.core.client.Client
import com.expediagroup.sdk.core.constant.LogMaskingFields
import com.expediagroup.sdk.core.constant.LoggingMessage.LOGGING_PREFIX
import com.expediagroup.sdk.core.constant.LoggingMessage.LOG_LIMIT
import com.expediagroup.sdk.core.constant.LoggingMessage.TRUNCATED
import org.slf4j.Logger

internal class ExpediaGroupLogger(private val logger: Logger, private val client: Client? = null) : Logger by logger {
private val mask = LogMasker(getMaskedBodyFieldFilters())

override fun info(msg: String) {
if (logger.isInfoEnabled) {
logger.info(decorate(msg))
Expand All @@ -41,12 +41,9 @@ internal class ExpediaGroupLogger(private val logger: Logger, private val client
}
}

private fun decorate(msg: String): String = "$LOGGING_PREFIX ${mask(msg)}"
private fun decorate(msg: String): String = "$LOGGING_PREFIX ${mask(truncate(msg), getMaskedBodyFields())}"

private fun getMaskedBodyFields(): Set<String> = client?.getLoggingMaskedFieldsProvider()?.getMaskedBodyFields() ?: LogMaskingFields.DEFAULT_MASKED_BODY_FIELDS
private fun truncate(msg: String): String = if (msg.length > LOG_LIMIT) "${msg.substring(0, LOG_LIMIT)}$TRUNCATED" else msg

private fun getMaskedBodyFieldFilters(): Iterable<ExpediaGroupJsonFieldFilter> =
listOf(
ExpediaGroupJsonFieldFilter(getMaskedBodyFields().toTypedArray())
)
private fun getMaskedBodyFields(): Set<String> = client?.getLoggingMaskedFieldsProvider()?.getMaskedBodyFields() ?: LogMaskingFields.DEFAULT_MASKED_BODY_FIELDS
}
Loading
Loading