diff options
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt')
-rw-r--r-- | ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.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/BlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt index 945d29850..d37612fe6 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt @@ -22,6 +22,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.methods.HttpDelete import org.apache.http.client.methods.HttpGet @@ -165,11 +168,25 @@ interface 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 WebClientResponse(statusCode, body) + } + } else { + val constructor = responseType.getConstructor() + val body = constructor.newInstance() return 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 + } suspend fun getNB(path: String): WebClientResponse<String> { return getNB(path, null, String::class.java) |