summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-acm/src/main')
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java5
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java3
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java27
3 files changed, 14 insertions, 21 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java
index f03cc4ecd..1854fc24d 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java
@@ -47,11 +47,10 @@ public class CommissioningControllerStub extends AbstractRestController
private static final Logger log = LoggerFactory.getLogger(CommissioningControllerStub.class);
- @Autowired
- private HttpServletRequest request;
+ private StubUtils stubUtils = new StubUtils();
@Autowired
- private StubUtils stubUtils;
+ private HttpServletRequest request;
@Value("${stub.deleteCompositionDefinitionResponse}")
private String pathToResponseFile;
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java
index 40152683d..cdd3ad80f 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java
@@ -47,8 +47,7 @@ public class InstantiationControllerStub extends AbstractRestController implemen
private static final Logger log = LoggerFactory.getLogger(InstantiationControllerStub.class);
- @Autowired
- private StubUtils stubUtils;
+ private StubUtils stubUtils = new StubUtils();
@Autowired
private HttpServletRequest request;
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java
index 285365d9b..650426681 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java
@@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javax.servlet.http.HttpServletRequest;
+import lombok.RequiredArgsConstructor;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.slf4j.Logger;
@@ -34,6 +35,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
+@RequiredArgsConstructor
@Service
@Profile("stub")
public class StubUtils {
@@ -46,26 +48,19 @@ public class StubUtils {
<T> ResponseEntity<T> getResponse(String path, Class<T> clazz,
HttpServletRequest request, Logger log) {
String accept = request.getHeader(ACCEPT);
- if (accept.contains(YAML)) {
- path = path.replace("json", "yaml");
- final ClassPathResource resourceY = new ClassPathResource(path);
- try (InputStream inputStreamY = resourceY.getInputStream()) {
- var targetObj = YAML_TRANSLATOR.decode(inputStreamY, clazz);
- return new ResponseEntity<>(targetObj, HttpStatus.OK);
- } catch (IOException | CoderException e) {
- log.error("Error reading the file.", e);
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
- }
- } else {
- final ClassPathResource resource = new ClassPathResource(path);
- try (InputStream inputStream = resource.getInputStream()) {
+ final ClassPathResource resource = new ClassPathResource(path);
+ try (InputStream inputStream = resource.getInputStream()) {
+ if (accept.contains(YAML)) {
+ var targetObject = YAML_TRANSLATOR.decode(inputStream, clazz);
+ return new ResponseEntity<>(targetObject, HttpStatus.OK);
+ } else {
final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
var targetObject = JSON_TRANSLATOR.fromJson(string, clazz);
return new ResponseEntity<>(targetObject, HttpStatus.OK);
- } catch (final IOException exception) {
- log.error("Error reading the file.", exception);
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
+ } catch (IOException | CoderException exception) {
+ log.error("Error reading the file.", exception);
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
}