From 1a26730bb6e5cae1972ba40a2bed83a171c3ff03 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Thu, 1 Oct 2020 14:56:58 -0400 Subject: Restored methods to pre-java11 state Methods reverted Required for usage in groovy scripts Issue-ID: SO-3261 Signed-off-by: Benjamin, Max (mb388a) Change-Id: Id980f83cc444997e24971f2146b40f98ee6ed668 --- .../so/db/request/client/RequestsDbClient.java | 48 ++++++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'mso-api-handlers/mso-requests-db/src') 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 entity = new HttpEntity<>(request, getHttpHeaders()); - restTemplate.put(uri, entity); + HttpEntity entity = new HttpEntity<>(request, headers); + template.put(uri, entity); } protected URI getUri(String uri) { -- cgit 1.2.3-korg