From 385874a6fd067cb17323a27ecd1af62b4176aecc Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Fri, 26 Jun 2020 15:56:48 -0400 Subject: Add RFC 8040 compliant error handler Add a new error handler that formats error responses consistent with RFC 8040 (RESTCONF) standards. Change-Id: I67a6ab626d943115570f2e74d0a8132933726bc8 Issue-ID: CCSDK-2482 Signed-off-by: Dan Timoney --- .../src/main/java/org/onap/ccsdk/apps/ms/sliboot/App.java | 3 +-- .../main/java/org/onap/ccsdk/apps/ms/sliboot/WebConfig.java | 3 +-- .../apps/ms/sliboot/controllers/RestconfApiController.java | 12 ++++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'ms/sliboot/src/main/java') diff --git a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/App.java b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/App.java index d2ef5e77..b93c2f9f 100644 --- a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/App.java +++ b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/App.java @@ -35,8 +35,7 @@ import org.onap.aaf.cadi.shiro.AAFRealm; @SpringBootApplication @EnableSwagger2 -@ComponentScan(basePackages = { "org.onap.ccsdk.apps.ms.sliboot.*" }) - +@ComponentScan(basePackages = { "org.onap.ccsdk.apps.ms.sliboot.*", "org.onap.ccsdk.apps.services" }) public class App { private static final Logger log = LoggerFactory.getLogger(App.class); diff --git a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/WebConfig.java b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/WebConfig.java index 3b0b2a20..1cef3161 100644 --- a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/WebConfig.java +++ b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/WebConfig.java @@ -28,10 +28,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -@EnableWebMvc @Configuration @EnableJpaRepositories("org.onap.ccsdk.apps.ms.sliboot.*") -@ComponentScan(basePackages = {"org.onap.ccsdk.apps.ms.sliboot.*"}) +@ComponentScan(basePackages = {"org.onap.ccsdk.apps.ms.sliboot.*", "org.onap.ccsdk.apps.services"}) @EntityScan("org.onap.ccsdk.apps.ms.sliboot.*") @EnableTransactionManagement public class WebConfig implements WebMvcConfigurer { diff --git a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/controllers/RestconfApiController.java b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/controllers/RestconfApiController.java index 4b78b2d1..f37fe137 100644 --- a/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/controllers/RestconfApiController.java +++ b/ms/sliboot/src/main/java/org/onap/ccsdk/apps/ms/sliboot/controllers/RestconfApiController.java @@ -29,6 +29,9 @@ import org.onap.ccsdk.apps.ms.sliboot.swagger.OperationalApi; import org.onap.ccsdk.apps.ms.sliboot.swagger.OperationsApi; import org.onap.ccsdk.apps.ms.sliboot.data.TestResultsOperationalRepository; import org.onap.ccsdk.apps.ms.sliboot.swagger.model.*; +import org.onap.ccsdk.apps.services.RestApplicationException; +import org.onap.ccsdk.apps.services.RestException; +import org.onap.ccsdk.apps.services.RestProtocolException; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceBase; @@ -42,6 +45,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; @@ -49,7 +53,7 @@ import java.util.*; @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2020-02-20T12:50:11.207-05:00") -@Controller +@RestController @ComponentScan(basePackages = {"org.onap.ccsdk.apps.ms.sliboot.*", "org.onap.ccsdk.apps.services"}) @EntityScan("org.onap.ccsdk.apps.ms.sliboot.*") public class RestconfApiController implements ConfigApi, OperationalApi, OperationsApi { @@ -273,7 +277,7 @@ public class RestconfApiController implements ConfigApi, OperationalApi, Operati } @Override - public ResponseEntity configSLIAPItestResultsGet() { + public ResponseEntity configSLIAPItestResultsGet() throws RestException { if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { } else { @@ -282,6 +286,10 @@ public class RestconfApiController implements ConfigApi, OperationalApi, Operati SliApiTestResults results = new SliApiTestResults(); + if (testResultsConfigRepository.count() == 0) { + throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", 404); + } + testResultsConfigRepository.findAll().forEach(testResult -> { SliApiTestresultsTestResult item = null; try { -- cgit 1.2.3-korg