diff options
author | Steve Smokowski <ss835w@att.com> | 2020-10-07 13:58:57 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-10-07 13:58:57 +0000 |
commit | 4c7a4b6c8a137ce3799d8ac00d4d2b4a0031fe1d (patch) | |
tree | 8994a6cf4e2efd382cf7f9f5a4f7b2122de77fc6 | |
parent | bcf518fda267cbb20e3bc26853642d8863acfcac (diff) | |
parent | 1a26730bb6e5cae1972ba40a2bed83a171c3ff03 (diff) |
Merge "Restored methods to pre-java11 state"
-rw-r--r-- | mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index 17b22ec216..9b42eacfc2 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -29,6 +29,7 @@ import javax.annotation.PostConstruct; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; import org.apache.http.HttpStatus; +import org.onap.logging.filter.spring.SpringClientPayloadFilter; import org.onap.so.db.request.beans.ArchivedInfraRequests; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.OperationStatus; @@ -42,6 +43,7 @@ import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus; import org.onap.so.db.request.beans.WatchdogDistributionStatus; import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup; import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; +import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Primary; @@ -297,17 +299,55 @@ public class RequestsDbClient { restTemplate.exchange(uri, HttpMethod.PATCH, entity, String.class); } + /** + * Required for groovy usage. Cannot use Spring Autowired variables + * + * @param requestId + * @param basicAuth + * @param host + * @return + */ public InfraActiveRequests getInfraActiveRequests(String requestId, String basicAuth, String host) { + RestTemplate template = new RestTemplate(); + HttpHeaders headers = new HttpHeaders(); + headers.set(HttpHeaders.AUTHORIZATION, basicAuth); + headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); URI uri = getUri(host + "/infraActiveRequests/" + requestId); - - return getSingleResponse(uri, InfraActiveRequests.class); + try { + InfraActiveRequests infraActiveRequests = template + .exchange(uri, HttpMethod.GET, new HttpEntity<>(headers), InfraActiveRequests.class).getBody(); + if (infraActiveRequests != null) { + infraActiveRequests.setRequestId(requestId); + } + return infraActiveRequests; + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + return null; + } + throw e; + } } + /** + * Required for groovy usage. Cannot use Spring Autowired variables + * + * @param request + * @param basicAuth + * @param host + */ public void updateInfraActiveRequests(InfraActiveRequests request, String basicAuth, String host) { + RestTemplate template = new RestTemplate(); + template.getInterceptors().add(new SOSpringClientFilter()); + template.getInterceptors().add(new SpringClientPayloadFilter()); + HttpHeaders headers = new HttpHeaders(); + headers.set(HttpHeaders.AUTHORIZATION, basicAuth); + headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); URI uri = getUri(host + "/infraActiveRequests/" + request.getRequestId()); - HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(request, getHttpHeaders()); - restTemplate.put(uri, entity); + HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(request, headers); + template.put(uri, entity); } protected URI getUri(String uri) { |