diff options
author | 2022-08-29 13:28:01 +0200 | |
---|---|---|
committer | 2022-09-01 14:20:03 +0000 | |
commit | e679d838562ef6762852e8073844ad578d700a84 (patch) | |
tree | 402bf717892bccddf1be7759446aa5464f69ee4d /ms/blueprintsprocessor/modules/commons/rest-lib/src/main | |
parent | 77891f46278488702aeed2fe970861a2f1b9a1a7 (diff) |
Http 204 response results with exception in rest resolution
Issue-ID: CCSDK-3746
Signed-off-by: Frank Kimmlingen <frank.kimmlingen@telekom.de>
Change-Id: I740c970de631e58902e6f92b9069aee8d3ae075b
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/rest-lib/src/main')
-rw-r--r-- | ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BaseBlueprintWebClientService.kt | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BaseBlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BaseBlueprintWebClientService.kt index bc1dc4e09..ccc2f92a1 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BaseBlueprintWebClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BaseBlueprintWebClientService.kt @@ -23,6 +23,9 @@ import com.fasterxml.jackson.databind.JsonNode import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.apache.commons.io.IOUtils +import org.apache.http.HttpEntity +import org.apache.http.HttpResponse +import org.apache.http.HttpStatus import org.apache.http.client.ClientProtocolException import org.apache.http.client.config.RequestConfig import org.apache.http.client.methods.HttpDelete @@ -164,11 +167,25 @@ abstract class BaseBlueprintWebClientService<out E : RestClientProperties> : Blu BlueprintWebClientService.WebClientResponse<T> { val httpResponse = httpClient().execute(httpUriRequest) val statusCode = httpResponse.statusLine.statusCode - httpResponse.entity.content.use { - val body = getResponse(it, responseType) + val entity: HttpEntity? = httpResponse.entity + if (canResponseHaveBody(httpResponse)) { + entity!!.content.use { + val body = getResponse(it, responseType) + return BlueprintWebClientService.WebClientResponse(statusCode, body) + } + } else { + val constructor = responseType.getConstructor() + val body = constructor.newInstance() return BlueprintWebClientService.WebClientResponse(statusCode, body) } } + fun canResponseHaveBody(response: HttpResponse): Boolean { + val status = response.statusLine.statusCode + return response.entity !== null && + status != HttpStatus.SC_NO_CONTENT && + status != HttpStatus.SC_NOT_MODIFIED && + status != HttpStatus.SC_RESET_CONTENT + } open suspend fun getNB(path: String): BlueprintWebClientService.WebClientResponse<String> { return getNB(path, null, String::class.java) |