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
26 interface BlueprintWebClientService {
27 fun defaultHeaders(): Map<String, String>
28 fun convertToBasicHeaders(
29 mergedDefaultAndSuppliedHeaders: Map<String, String>
36 headers: Map<String, String>
37 ): WebClientResponse<String>
43 ): WebClientResponse<String>
45 suspend fun exchangeNB(methodType: String, path: String, request: Any): WebClientResponse<String>
47 suspend fun exchangeNB(methodType: String, path: String, request: Any, additionalHeaders: Map<String, String>?):
48 WebClientResponse<String>
50 suspend fun <T> exchangeNB(
54 additionalHeaders: Map<String, String>?,
55 responseType: Class<T>
56 ): WebClientResponse<T>
58 /** High performance non blocking Retry function, If execution block [block] throws BluePrintRetryException
59 * exception then this will perform wait and retrigger accoring to times [times] with delay [delay]
61 suspend fun <T> retry(
63 initialDelay: Long = 0,
65 block: suspend (Int) -> T
67 val exceptionBlock = { e: Exception ->
68 if (e !is BluePrintRetryException) {
72 return BluePrintIOUtils.retry(times, initialDelay, delay, block, exceptionBlock)
75 // TODO maybe there could be cases where we care about return headers?
76 data class WebClientResponse<T>(val status: Int, val body: T)