2 * Copyright © 2017-2019 AT&T, Bell Canada, Nordix Foundation
3 * Modifications Copyright © 2018-2019 IBM.
4 * Modifications Copyright © 2019 Huawei.
5 * Modifications Copyright © 2022 Deutsche Telekom AG.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 package org.onap.ccsdk.cds.blueprintsprocessor.rest.service
22 import org.apache.http.message.BasicHeader
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintRetryException
24 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintIOUtils
25 import java.nio.file.Path
27 interface BlueprintWebClientService {
28 fun defaultHeaders(): Map<String, String>
29 fun convertToBasicHeaders(
30 mergedDefaultAndSuppliedHeaders: Map<String, String>
37 headers: Map<String, String>
38 ): WebClientResponse<String>
44 ): WebClientResponse<String>
49 ): WebClientResponse<String>
51 suspend fun exchangeNB(methodType: String, path: String, request: Any): WebClientResponse<String>
53 suspend fun exchangeNB(methodType: String, path: String, request: Any, additionalHeaders: Map<String, String>?):
54 WebClientResponse<String>
56 suspend fun <T> exchangeNB(
60 additionalHeaders: Map<String, String>?,
61 responseType: Class<T>
62 ): WebClientResponse<T>
64 /** High performance non blocking Retry function, If execution block [block] throws BluePrintRetryException
65 * exception then this will perform wait and retrigger accoring to times [times] with delay [delay]
67 suspend fun <T> retry(
69 initialDelay: Long = 0,
71 block: suspend (Int) -> T
73 val exceptionBlock = { e: Exception ->
74 if (e !is BluePrintRetryException) {
78 return BluePrintIOUtils.retry(times, initialDelay, delay, block, exceptionBlock)
81 // TODO maybe there could be cases where we care about return headers?
82 data class WebClientResponse<T>(val status: Int, val body: T)