summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main
diff options
context:
space:
mode:
authorottero <rodrigo.ottero@est.tech>2019-05-16 09:00:07 +0000
committerottero <rodrigo.ottero@est.tech>2019-05-16 09:00:07 +0000
commit5801ed7abaa58f7ef728ad68c496a3780d438194 (patch)
tree21e94f4d3c548fdfd24b2c7c9bf08d5807caa041 /ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main
parent250b5b2a4ad4020df9c0dd053743d28616e28485 (diff)
Bugfix: Blueprints Processor always return 200 OK
Currently the Blueprints Processor mS replies with a 200 OK HTTP status code even if an exception occurs in the server side while executing the request. Thus, the only way for a REST client to determine if the request was successful or not is by analysing the response and evaluate the content of the element status.code This bugfix modifies the HTTP status code of the response to match the one inside the response. Issue-ID: CCSDK-1327 Change-Id: I05a58cb3ab9359319172f2d8f1a665fdcdc1230b Signed-off-by: ottero <rodrigo.ottero@est.tech>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt8
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt13
2 files changed, 19 insertions, 2 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
index 7cbc89583..eff977348 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
@@ -22,9 +22,12 @@ import kotlinx.coroutines.runBlocking
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
+import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.determineHttpStatusCode
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
+import org.springframework.http.ResponseEntity
import org.springframework.http.codec.multipart.FilePart
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.*
@@ -63,10 +66,11 @@ open class ExecutionServiceController {
notes = "Takes the blueprint information and process as per the payload")
@ResponseBody
@PreAuthorize("hasRole('USER')")
- fun process(@RequestBody executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput = runBlocking {
+ fun process(@RequestBody executionServiceInput: ExecutionServiceInput): ResponseEntity<ExecutionServiceOutput> = runBlocking {
if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) {
throw IllegalStateException("Can't process async request through the REST endpoint. Use gRPC for async processing.")
}
- executionServiceHandler.doProcess(executionServiceInput)
+ val processResult = executionServiceHandler.doProcess(executionServiceInput)
+ ResponseEntity(processResult, determineHttpStatusCode(processResult.status.code))
}
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt
index 32be3e0a0..2cf1c1dd0 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/utils/Utils.kt
@@ -16,6 +16,7 @@
package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.springframework.http.HttpStatus
import org.springframework.http.codec.multipart.FilePart
import org.springframework.util.StringUtils
import java.io.File
@@ -26,6 +27,7 @@ import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.*
+const val INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE = 500
fun currentTimestamp(): String {
val now = LocalDateTime.now(ZoneId.systemDefault())
@@ -56,4 +58,15 @@ fun saveCBAFile(filePart: FilePart, targetDirectory: Path): Path {
filePart.transferTo(file)
return targetLocation
+}
+
+fun determineHttpStatusCode(statusCode: Int): HttpStatus {
+
+ try {
+ return HttpStatus.valueOf(statusCode)
+ } catch (exception: Exception) {
+ //if statusCode cannot be converted to a proper HttpStatus, the resource still needs to assign a HTTP status
+ // code to the response. In this case, a 500 Internal Server Error will be returned as default.
+ return HttpStatus.valueOf(INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE)
+ }
} \ No newline at end of file