Skip to content

Commit 85eacc1

Browse files
committed
1 parent 7d95ffb commit 85eacc1

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ContainerApi.kt

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import kotlinx.coroutines.launch
4848
import kotlinx.coroutines.runBlocking
4949
import kotlinx.coroutines.withTimeout
5050
import okhttp3.RequestBody
51+
import okhttp3.WebSocket
52+
import okhttp3.WebSocketListener
5153
import okio.Source
5254
import okio.source
5355
import java.io.InputStream
@@ -332,33 +334,17 @@ class ContainerApi(dockerClientConfig: DockerClientConfig = defaultClientConfig,
332334
*/
333335
@Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class)
334336
fun containerAttachWebsocket(
335-
id: String,
336-
detachKeys: String?,
337-
logs: Boolean?,
338-
stream: Boolean?,
339-
stdin: Boolean?,
340-
stdout: Boolean?,
341-
stderr: Boolean?
342-
) {
337+
id: String, detachKeys: String?,
338+
logs: Boolean?, stream: Boolean?, stdin: Boolean?, stdout: Boolean?, stderr: Boolean?,
339+
wsListener: WebSocketListener
340+
): WebSocket {
343341
val localVariableConfig = containerAttachWebsocketRequestConfig(id = id, detachKeys = detachKeys, logs = logs, stream = stream, stdin = stdin, stdout = stdout, stderr = stderr)
344342

345-
val localVarResponse = request<Any?>(
346-
localVariableConfig
343+
val localVarResponse = requestWebSocket(
344+
localVariableConfig,
345+
wsListener
347346
)
348-
349-
return when (localVarResponse.responseType) {
350-
ResponseType.Success -> Unit
351-
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
352-
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
353-
ResponseType.ClientError -> {
354-
val localVarError = localVarResponse as ClientError<*>
355-
throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
356-
}
357-
ResponseType.ServerError -> {
358-
val localVarError = localVarResponse as ServerError<*>
359-
throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse)
360-
}
361-
}
347+
return localVarResponse
362348
}
363349

364350
/**

api-client/src/main/kotlin/de/gesellix/docker/remote/api/core/ApiClient.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import okhttp3.RequestBody
2323
import okhttp3.RequestBody.Companion.asRequestBody
2424
import okhttp3.RequestBody.Companion.toRequestBody
2525
import okhttp3.ResponseBody
26+
import okhttp3.WebSocket
27+
import okhttp3.WebSocketListener
2628
import okio.Source
2729
import java.io.File
2830
import java.io.InputStream
@@ -133,6 +135,17 @@ open class ApiClient(
133135
return request<T>(request, client, requestConfig.elementType)
134136
}
135137

138+
protected fun requestWebSocket(requestConfig: RequestConfig, wsListener: WebSocketListener): WebSocket {
139+
val engineRequest = EngineRequest(requestConfig.method, requestConfig.path).also {
140+
it.headers = requestConfig.headers
141+
it.query = requestConfig.query
142+
it.body = requestConfig.body
143+
}
144+
val request = prepareRequest(engineRequest, JsonMediaType)
145+
val client = prepareClient(engineRequest)
146+
return client.newWebSocket(request, wsListener)
147+
}
148+
136149
protected inline fun <reified T : Any?> requestStream(requestConfig: RequestConfig): ApiInfrastructureResponse<T?> {
137150
val engineRequest = EngineRequest(requestConfig.method, requestConfig.path).also {
138151
it.headers = requestConfig.headers

0 commit comments

Comments
 (0)