diff options
author | 2020-06-26 15:56:48 -0400 | |
---|---|---|
committer | 2020-06-29 09:01:18 -0400 | |
commit | 385874a6fd067cb17323a27ecd1af62b4176aecc (patch) | |
tree | b6f02d6dca3f496aacff8ae29b1c0cca71b7b866 /ms/sliboot/src/main/java | |
parent | f3430368211a5eb435a56a70006831255dcdba2e (diff) |
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 <dtimoney@att.com>
Diffstat (limited to 'ms/sliboot/src/main/java')
3 files changed, 12 insertions, 6 deletions
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<SliApiTestResults> configSLIAPItestResultsGet() { + public ResponseEntity<SliApiTestResults> 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 { |