X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ms%2Fblueprintsprocessor%2Fmodules%2Fcommons%2Frest-lib%2Fsrc%2Fmain%2Fkotlin%2Forg%2Fonap%2Fccsdk%2Fcds%2Fblueprintsprocessor%2Frest%2Fservice%2FBaseBlueprintWebClientService.kt;h=ccc2f92a111e452ea384bc65768f0fcd7234e947;hb=refs%2Fchanges%2F73%2F130473%2F6;hp=bc1dc4e0972c01a4c95899506093e034761e9dcc;hpb=77891f46278488702aeed2fe970861a2f1b9a1a7;p=ccsdk%2Fcds.git 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 : Blu BlueprintWebClientService.WebClientResponse { 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 { return getNB(path, null, String::class.java)